changeset 320:63f267bd2176

obsolete: basic commit --amend support commit --amend still strip. but lay obsolete marker down anyway
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Wed, 27 Jun 2012 12:30:16 +0200
parents e7431cf7fca9
children 41ba89f0caa5
files hgext/obsolete.py tests/test-obsolete.t
diffstat 2 files changed, 85 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/obsolete.py	Wed Jun 27 03:53:44 2012 +0200
+++ b/hgext/obsolete.py	Wed Jun 27 12:30:16 2012 +0200
@@ -622,9 +622,31 @@
     repo._turn_extinct_secret()
     return orig(repo)
 
+def wrapcmdutilamend(orig, ui, repo, commitfunc, old, *args, **kwargs):
+    oldnode = old.node()
+    new = orig(ui, repo, commitfunc, old, *args, **kwargs)
+    if new != oldnode:
+        lock = repo.lock()
+        try:
+            newmarker = {
+                'subjects':  [new],
+                'object': oldnode,
+                'date':  util.makedate(),
+                'user': ui.username(),
+                'reason': 'commit --amend',
+                }
+            repo.obsoletestore.new(newmarker)
+            repo._clearobsoletecache()
+            repo._turn_extinct_secret()
+        finally:
+            lock.release()
+    return new
+
 def uisetup(ui):
     extensions.wrapcommand(commands.table, "update", wrapmayobsoletewc)
     extensions.wrapcommand(commands.table, "pull", wrapmayobsoletewc)
+    if util.safehasattr(cmdutil, 'amend'):
+        extensions.wrapfunction(cmdutil, 'amend', wrapcmdutilamend)
     extensions.wrapfunction(discovery, 'findcommonoutgoing', wrapfindcommonoutgoing)
     extensions.wrapfunction(discovery, 'checkheads', wrapcheckheads)
     extensions.wrapfunction(phases, 'visibleheads', noextinctsvisibleheads)
--- a/tests/test-obsolete.t	Wed Jun 27 03:53:44 2012 +0200
+++ b/tests/test-obsolete.t	Wed Jun 27 12:30:16 2012 +0200
@@ -515,3 +515,66 @@
   abort: Trying to push latecomer changeset: 6db5e282cb91!
   (use 'hg stabilize' to get a stable history (or --force to proceed))
   [255]
+
+Check hg commit --amend compat
+
+  $ hg up 'desc(obsol_c)'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ mkcommit f
+  created new head
+  $ echo 42 >> f
+  $ hg commit --amend --traceback
+  saved backup bundle to $TESTTMP/local/.hg/strip-backup/0b1b6dd009c0-amend-backup.hg
+  $ hg glog
+  @  changeset:   13:3734a65252e6
+  |  tag:         tip
+  |  parent:      10:2033b4e49474
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add f
+  |
+  | o  changeset:   12:6db5e282cb91
+  |/   parent:      10:2033b4e49474
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     add obsol_d'''
+  |
+  | o  changeset:   11:9468a5f5d8b2
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     add obsol_d''
+  |
+  o  changeset:   10:2033b4e49474
+  |  parent:      4:725c380fe99b
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add obsol_c
+  |
+  o  changeset:   4:725c380fe99b
+  |  parent:      1:7c3bad9141dc
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add obsol_c'
+  |
+  o  changeset:   1:7c3bad9141dc
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add b
+  |
+  o  changeset:   0:1f0dee641bb7
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     add a
+  
+  $ hg debugsuccessors
+  0b1b6dd009c0 3734a65252e6
+  0d3f46688ccc 2033b4e49474
+  0d3f46688ccc 725c380fe99b
+  159dfc9fa5d3 9468a5f5d8b2
+  1f0dee641bb7 83b5778897ad
+  4538525df7e2 0d3f46688ccc
+  83b5778897ad 000000000000
+  909a0fb57e5d 159dfc9fa5d3
+  9468a5f5d8b2 6db5e282cb91
+  95de7fc6918d 909a0fb57e5d
+  a7a6f2b5d8a5 95de7fc6918d