Patchwork [3,of,4,V2] histedit: make finishfold not depend on parentctx

login
register
mail settings
Submitter Mateusz Kwapich
Date Feb. 3, 2015, 12:32 a.m.
Message ID <0850d3f920a11370d564.1422923548@dev1429.prn1.facebook.com>
Download mbox | patch
Permalink /patch/7617/
State Changes Requested
Headers show

Comments

Mateusz Kwapich - Feb. 3, 2015, 12:32 a.m.
# HG changeset patch
# User Mateusz Kwapich <mitrandir@fb.com>
# Date 1422315450 28800
#      Mon Jan 26 15:37:30 2015 -0800
# Node ID 0850d3f920a11370d564d5fe9a67c35fc8c347ba
# Parent  5868827d6d1a2a75d9628d502281d0d7fad2b115
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.

Patch

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,)),
                    ]
@@ -775,8 +777,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
   |