Commits

Pierre-Yves David committed 4e0f1aa

evolve: touch command

command to easily revive a changeset.

Comments (0)

Files changed (2)

 
 '''a set of commands to handle changeset mutation'''
 
+import random
+
 from mercurial import cmdutil
 from mercurial import scmutil
 from mercurial import node
     finally:
         lock.release()
 
+@command('^touch',
+    [('r', 'rev', [], 'revision to update'),],
+    # allow to choose the seed ?
+    _('[-r] revs'))
+def touch(ui, repo, *revs, **opts):
+    """Create successors with exact same property but hash
+    
+    This is used to "resurect" changeset"""
+    revs = list(revs)
+    revs.extend(opts['rev'])
+    if not revs:
+        revs = ['.']
+    revs = scmutil.revrange(repo, revs)
+    if not revs:
+        ui.write_err('no revision to touch\n')
+        return 1
+    if repo.revs('public() and %ld', revs):
+        raise util.Abort("can't touch public revision")
+    obsolete = extensions.find('obsolete')
+    wlock = repo.wlock()
+    try:
+        lock = repo.lock()
+        try:
+            tr = repo.transaction('touch')
+            try:
+                for r in revs:
+                    ctx = repo[r]
+                    extra = ctx.extra().copy()
+                    extra['__touch-noise__'] = random.randint(0, 0xffffffff)
+                    new, _ = rewrite(repo, ctx, [], ctx,
+                                     [ctx.p1().node(), ctx.p2().node()],
+                                     commitopts={'extra': extra})
+                    obsolete.createmarkers(repo, [(ctx, (repo[new],))])
+                    phases.retractboundary(repo, ctx.phase(), [new])
+                    if ctx in repo[None].parents():
+                        repo.dirstate.setparents(new, node.nullid)
+                tr.close()
+            finally:
+                tr.release()
+        finally:
+            lock.release()
+    finally:
+        wlock.release()
+
+
 def graftwrapper(orig, ui, repo, *revs, **kwargs):
     kwargs = dict(kwargs)
     revs = list(revs) + kwargs.get('rev', [])

tests/test-evolve.t

   db038628b9e56f51a454c0da0c508df247b41748 acb28cd497b7f8767e01ef70f68697a959573c2d 0 {'date': '* *', 'user': 'test'} (glob)
   a5bfd90a2f29c7ccb8f917ff4e5013a9053d0a04 920e58bb443b73eea9d6d65570b4241051ea3229 0 {'date': '* *', 'user': 'test'} (glob)
 
-  $ cd ..
+Test touch
 
+  $ glog
+  @  8:920e58bb443b@default(draft) conflict
+  |
+  o  6:acb28cd497b7@default(draft) add 1
+  |
+  o  5:0b9e50c35132@default(draft) add 3
+  |
+  o  4:ce341209337f@default(draft) add 4
+  |
+  | o  1:73d38bb17fd7@default(draft) add 1
+  |/
+  o  0:8685c6d34325@default(draft) add 0
+  
+  $ hg touch
+  $ glog
+  @  9:7a2f49fdcf11@default(draft) conflict
+  |
+  o  6:acb28cd497b7@default(draft) add 1
+  |
+  o  5:0b9e50c35132@default(draft) add 3
+  |
+  o  4:ce341209337f@default(draft) add 4
+  |
+  | o  1:73d38bb17fd7@default(draft) add 1
+  |/
+  o  0:8685c6d34325@default(draft) add 0
+  
+  $ hg touch .
+  $ glog
+  @  10:ce7e3d9b3afe@default(draft) conflict
+  |
+  o  6:acb28cd497b7@default(draft) add 1
+  |
+  o  5:0b9e50c35132@default(draft) add 3
+  |
+  o  4:ce341209337f@default(draft) add 4
+  |
+  | o  1:73d38bb17fd7@default(draft) add 1
+  |/
+  o  0:8685c6d34325@default(draft) add 0
+  
+ 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.