changeset 116:64ca29eef349

Add a -o option to commit
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Wed, 28 Dec 2011 12:38:01 +0100
parents d60eddda9546
children 438fe133b068
files hgext/evolution.py tests/test-evolution.t
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/evolution.py	Thu Dec 22 15:26:42 2011 +0100
+++ b/hgext/evolution.py	Wed Dec 28 12:38:01 2011 +0100
@@ -18,6 +18,7 @@
 from mercurial import bookmarks
 from mercurial import phases
 from mercurial import context
+from mercurial import commands
 from mercurial import util
 from mercurial.i18n import _
 from mercurial.commands import walkopts, commitopts, commitopts2, logopts
@@ -300,3 +301,19 @@
 
     finally:
         wlock.release()
+
+def commitwrapper(orig, ui, repo, *arg, **kwargs):
+    obsoleted = kwargs.get('obsolete', [])
+    if obsoleted:
+        obsoleted = repo.set('%lr', obsoleted)
+    result = orig(ui, repo, *arg, **kwargs)
+    if not result: # commit successed
+        new = repo['-1']
+        for old in obsoleted:
+            repo.addobsolete(new.node(), old.node())
+    return result
+
+def extsetup(ui):
+    entry = extensions.wrapcommand(commands.table, 'commit', commitwrapper)
+    entry[1].append(('o', 'obsolete', [], _("this commit obsolet this revision")))
+
--- a/tests/test-evolution.t	Thu Dec 22 15:26:42 2011 +0100
+++ b/tests/test-evolution.t	Wed Dec 28 12:38:01 2011 +0100
@@ -216,3 +216,14 @@
   7	feature-B: another feature - test
   6	feature-A: a nifty feature - test
   0	: base - test
+
+Test commit -o options
+
+  $ hg up 6
+  $ hg revert -r 7 --all
+  $ sed -i'' -e s/Zwei/deux/ main-file-1
+  $ hg commit -m 'Feature B' -o 7
+  $ hg log
+  8	feature-B: another feature - test
+  6	feature-A: a nifty feature - test
+  0	: base - test