changeset 4724:77bf84025dd5

metaedit: allow operations on merge commits with some conditions As with fold (see the previous patch), it's allowed to metaedit a merge commit or a set of commits including merge commits (with --fold) as long as there are less than 2 parents of the set not included in the said set.
author Anton Shestakov <av6@dwimlabs.net>
date Sat, 13 Jul 2019 18:22:34 +0800
parents 41885988921e
children f162cafc5000
files CHANGELOG hgext3rd/evolve/cmdrewrite.py tests/test-metaedit.t
diffstat 3 files changed, 59 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG	Thu Jul 11 18:07:03 2019 +0800
+++ b/CHANGELOG	Sat Jul 13 18:22:34 2019 +0800
@@ -11,6 +11,7 @@
   * touch: now works on merge commit too
   * rewind: fix behavior for merge commit
   * fold: allow fold with merge commit
+  * metaedit: now also operates on merge commit
 
 9.0.1 - in progress
 -------------------
--- a/hgext3rd/evolve/cmdrewrite.py	Thu Jul 11 18:07:03 2019 +0800
+++ b/hgext3rd/evolve/cmdrewrite.py	Sat Jul 13 18:22:34 2019 +0800
@@ -889,6 +889,7 @@
                 hint %= repo[newunstable.first()]
                 raise error.Abort(msg, hint=hint)
             root = head = repo[revs.first()]
+            p2 = root.p2()
 
         wctx = repo[None]
         p1 = wctx.p1()
@@ -911,12 +912,15 @@
                 commitopts['message'] = "\n".join(msgs)
                 commitopts['edit'] = True
 
+            updates = allctx[:]
+            if p2 is not None and (root.p2() != p2 or not opts['fold']):
+                updates.append(p2)
             # TODO: if the author and message are the same, don't create a new
             # hash. Right now we create a new hash because the date can be
             # different.
-            newid, created = rewriteutil.rewrite(repo, root, allctx, head,
+            newid, created = rewriteutil.rewrite(repo, root, updates, head,
                                                  [root.p1().node(),
-                                                  root.p2().node()],
+                                                  p2.node()],
                                                  commitopts=commitopts)
             if created:
                 if p1.rev() in revs:
--- a/tests/test-metaedit.t	Thu Jul 11 18:07:03 2019 +0800
+++ b/tests/test-metaedit.t	Sat Jul 13 18:22:34 2019 +0800
@@ -10,6 +10,7 @@
   > publish = False
   > [alias]
   > qlog = log --template='{rev} - {node|short} {desc} ({phase})\n'
+  > gluf = log -GT "{rev}: {desc|firstline} - {author|user} ({files})"
   > [diff]
   > git = 1
   > unified = 0
@@ -229,3 +230,54 @@
   1 changesets folded
   $ hg log -r "tip" --template '{rev}: {author}\n'
   12: foobar3
+
+working on merge commits too
+
+  $ hg up -q 11
+  $ hg merge -q 12
+  $ hg ci -m 'merge commit'
+  $ hg st --change .
+  A D
+  $ hg metaedit --user someone-else
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg st --change .
+  A D
+  $ hg gluf
+  @    14: merge commit - someone-else ()
+  |\
+  | o  12: D2 - foobar3 (D)
+  | |
+  o |  11: E - foobar2 (E F)
+  |/
+  o  3: C - test (C)
+  |
+  | o  2: B - test (B)
+  |/
+  o  1: A - test (A)
+  |
+  o  0: ROOT - test (ROOT)
+  
+  $ hg metaedit --user mr-squasher -r 3:14 --fold --message squashed
+  4 changesets folded
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg st --change .
+  A C
+  A D
+  A E
+  A F
+  $ hg gluf
+  @  15: squashed - mr-squasher (C D E F)
+  |
+  | o  2: B - test (B)
+  |/
+  o  1: A - test (A)
+  |
+  o  0: ROOT - test (ROOT)
+  
+  $ hg files
+  A
+  C
+  D
+  E
+  F
+  ROOT