evolve: touch command
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Thu, 23 Aug 2012 12:51:34 +0200
changeset 481 4e0f1aae8d24
parent 480 cd1d5b7308be
child 482 d2531a747ff5
evolve: touch command command to easily revive a changeset.
hgext/evolve.py
tests/test-evolve.t
--- a/hgext/evolve.py	Thu Aug 23 03:14:03 2012 +0200
+++ b/hgext/evolve.py	Thu Aug 23 12:51:34 2012 +0200
@@ -9,6 +9,8 @@
 
 '''a set of commands to handle changeset mutation'''
 
+import random
+
 from mercurial import cmdutil
 from mercurial import scmutil
 from mercurial import node
@@ -797,6 +799,51 @@
     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', [])
--- a/tests/test-evolve.t	Thu Aug 23 03:14:03 2012 +0200
+++ b/tests/test-evolve.t	Thu Aug 23 12:51:34 2012 +0200
@@ -509,5 +509,47 @@
   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
+  
+