[PATCH 2 of 2] histedit: retain hashes when obsolecense markers are enabled

David Soria Parra davidsp at fb.com
Mon Sep 8 11:35:55 CDT 2014


# HG changeset patch
# User David Soria Parra <davidsp at fb.com>
# Date 1409942389 -7200
#      Fri Sep 05 20:39:49 2014 +0200
# Node ID 9d351511590b26ab6fa07fa5bd5f11e2a6b1883a
# Parent  e79544cdfb81f88d782e923d96e8ad63303aec94
histedit: retain hashes when obsolecense markers are enabled

In case obsolecense markers are enabled we savely allow modifying
nodes that do have children. This allows us to retain hashes in
cases where the content doesn't change after a stop.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -408,20 +408,25 @@
 def stop(ui, repo, ctx, ha, opts):
     oldctx = repo[ha]
 
-    hg.update(repo, ctx.node())
-    stats = applychanges(ui, repo, oldctx, opts)
-    if stats and stats[3] > 0:
-        raise error.InterventionRequired(
-            _('Fix up the change and run hg histedit --continue'))
+    if obsolete._enabled and oldctx.parents()[0] == ctx:
+        hg.update(repo, oldctx.node())
+        newctx = oldctx
+    else:
+        hg.update(repo, ctx.node())
+        stats = applychanges(ui, repo, oldctx, opts)
+        if stats and stats[3] > 0:
+            raise error.InterventionRequired(
+                _('Fix up the change and run hg histedit --continue'))
 
-    commit = commitfuncfor(repo, oldctx)
-    new = commit(text=oldctx.description(), user=oldctx.user(),
-            date=oldctx.date(), extra=oldctx.extra())
+        commit = commitfuncfor(repo, oldctx)
+        new = commit(text=oldctx.description(), user=oldctx.user(),
+                date=oldctx.date(), extra=oldctx.extra())
+        newctx = repo[new]
 
     raise error.InterventionRequired(
         _('Changes commited as %s. You may amend the commit now.\n'
           'When you are finished, run hg histedit --continue to resume.') %
-        repo[new])
+        newctx)
 
 def message(ui, repo, ctx, ha, opts):
     oldctx = repo[ha]
diff --git a/tests/test-histedit-stop.t b/tests/test-histedit-stop.t
--- a/tests/test-histedit-stop.t
+++ b/tests/test-histedit-stop.t
@@ -161,4 +161,77 @@
   e
   
   
+Enable obsolete
 
+  $ cat > ${TESTTMP}/obs.py << EOF
+  > import mercurial.obsolete
+  > mercurial.obsolete._enabled = True
+  > EOF
+
+  $ cat >> $HGRCPATH << EOF
+  > [extensions]
+  > histedit=
+  > rebase=
+  > 
+  > obs=${TESTTMP}/obs.py
+  > EOF
+
+ With obsolete enabled a stop should retain the hashes
+
+  $ hg histedit 177f92b77385 --commands - 2>&1 << EOF| fixbundle
+  > pick 177f92b77385 c
+  > pick 055a42cdd887 d
+  > stop d51720eb7a13 e
+  > pick 099559071076 f
+  > EOF
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  Changes commited as d51720eb7a13. You may amend the commit now.
+  When you are finished, run hg histedit --continue to resume.
+
+  $ hg histedit --continue
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ hg log --graph --template '{node|short} {desc} {files}\n'
+  @  099559071076 f f
+  |
+  o  d51720eb7a13 e added e
+  |
+  o  055a42cdd887 d d
+  |
+  o  177f92b77385 c c
+  |
+  o  d2ae7f538514 b b
+  |
+  o  cb9a9f314b8b a a
+  
+  $ hg histedit 177f92b77385 --commands - 2>&1 << EOF| fixbundle
+  > pick 177f92b77385 c
+  > pick 055a42cdd887 d
+  > stop d51720eb7a13 e
+  > pick 099559071076 f
+  > EOF
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  Changes commited as d51720eb7a13. You may amend the commit now.
+  When you are finished, run hg histedit --continue to resume.
+
+  $ echo other > other
+  $ hg add other
+  $ hg commit --amend
+  $ hg histedit --continue
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ hg log --graph --template '{node|short} {desc} {files}\n'
+  @  c5e71295d8f1 f f
+  |
+  o  37537b78d2b6 e added e other
+  |
+  o  055a42cdd887 d d
+  |
+  o  177f92b77385 c c
+  |
+  o  d2ae7f538514 b b
+  |
+  o  cb9a9f314b8b a a
+  
+


More information about the Mercurial-devel mailing list