[PATCH 2 of 3] histedit: make finishfold not depend on parentctx

Mateusz Kwapich mitrandir at fb.com
Thu Feb 5 15:59:15 CST 2015


# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1423170607 28800
#      Thu Feb 05 13:10:07 2015 -0800
# Node ID 9ea70194adf7d075f31044c082f70f7c436a392a
# Parent  d68972b5e29e920571d976fee41a385d4f6baa95
histedit: make finishfold not depend on parentctx

To make histedit more robust to changes between actions, let's make finishfold
not depend on having access to the original parentctx. This has the slight side
effect of not merging the commit dates or phases anymore. Instead we just keep
the date and phase of the original commit, which arguably the right choice in
the beginning since the user is choosing to get rid of the second commit.

Future patches will remove this dependency from other areas as well.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -397,9 +397,11 @@
     if n is None:
         ui.warn(_('%s: empty changeset') % ha[:12])
         return ctx, []
-    return finishfold(ui, repo, ctx, oldctx, n, opts, [])
+    return finishfold(ui, repo, ctx, oldctx.node(), oldctx.description(),
+                      n, opts, [])
 
-def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges):
+def finishfold(ui, repo, ctx, oldctxnode, oldctxdescription, newnode,
+               opts, internalchanges):
     parent = ctx.parents()[0].node()
     hg.update(repo, parent)
     ### prepare new commit data
@@ -412,19 +414,19 @@
         newmessage = '\n***\n'.join(
             [ctx.description()] +
             [repo[r].description() for r in internalchanges] +
-            [oldctx.description()]) + '\n'
+            [oldctxdescription]) + '\n'
     commitopts['message'] = newmessage
     # date
-    commitopts['date'] = max(ctx.date(), oldctx.date())
+    commitopts['date'] = ctx.date()
     extra = ctx.extra().copy()
     # histedit_source
     # note: ctx is likely a temporary commit but that the best we can do here
     #       This is sufficient to solve issue3681 anyway
-    extra['histedit_source'] = '%s,%s' % (ctx.hex(), oldctx.hex())
+    extra['histedit_source'] = '%s,%s' % (ctx.hex(), node.hex(oldctxnode))
     commitopts['extra'] = extra
     phasebackup = repo.ui.backupconfig('phases', 'new-commit')
     try:
-        phasemin = max(ctx.phase(), oldctx.phase())
+        phasemin = ctx.phase()
         repo.ui.setconfig('phases', 'new-commit', phasemin, 'histedit')
         n = collapse(repo, ctx, repo[newnode], commitopts)
     finally:
@@ -432,7 +434,7 @@
     if n is None:
         return ctx, []
     hg.update(repo, n)
-    replacements = [(oldctx.node(), (newnode,)),
+    replacements = [(oldctxnode, (newnode,)),
                     (ctx.node(), (n,)),
                     (newnode, (n,)),
                    ]
@@ -779,8 +781,9 @@
             if action in ('r', 'roll'):
                 foldopts = foldopts.copy()
                 foldopts['rollup'] = True
-            parentctx, repl = finishfold(ui, repo, parentctx, ctx, new,
-                                         foldopts, newchildren)
+            parentctx, repl = finishfold(ui, repo, parentctx, ctx.node(),
+                                         ctx.description(), new, foldopts,
+                                         newchildren)
             replacements.extend(repl)
         else:
             # newchildren is empty if the fold did not result in any commit
diff --git a/tests/test-histedit-obsolete.t b/tests/test-histedit-obsolete.t
--- a/tests/test-histedit-obsolete.t
+++ b/tests/test-histedit-obsolete.t
@@ -433,7 +433,7 @@
   $ hg log -G
   @  19:f9daec13fb98 (secret) i
   |
-  o  18:49807617f46a (secret) g
+  o  18:49807617f46a (draft) g
   |
   o  17:050280826e04 (draft) h
   |


More information about the Mercurial-devel mailing list