site

(Pierre-Yves David)
2011-12-28: Add a -o option to commit

Add a -o option to commit

diff --git a/hgext/evolution.py b/hgext/evolution.py
--- a/hgext/evolution.py
+++ b/hgext/evolution.py
@@ -18,6 +18,7 @@ from mercurial import commands
 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 @@ def amend(ui, repo, *pats, **opts):
 
     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")))
+
diff --git a/tests/test-evolution.t b/tests/test-evolution.t
--- a/tests/test-evolution.t
+++ b/tests/test-evolution.t
@@ -216,3 +216,14 @@ changeset plus the updating changeset ar
   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