[PATCH STABLE] graft: do not try to skip rev derived from ancestor more than once (issue6024)

Yuya Nishihara yuya at tcha.org
Thu Nov 15 14:08:46 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1542290378 -32400
#      Thu Nov 15 22:59:38 2018 +0900
# Branch stable
# Node ID b395d9aa849c5776a1a129e5282902b03ab31ab7
# Parent  4790732559ade2c1ab13608ba8d9e0c22d335b9b
graft: do not try to skip rev derived from ancestor more than once (issue6024)

We check 'x in revs' in other cases, so let's do the same.

The test case credits to Tom Prince.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2478,10 +2478,11 @@ def _dograft(ui, repo, *revs, **opts):
                     revs.remove(ids[n])
             elif ctx.hex() in ids:
                 r = ids[ctx.hex()]
-                ui.warn(_('skipping already grafted revision %d:%s '
-                          '(was grafted from %d:%s)\n') %
-                        (r, repo[r], rev, ctx))
-                revs.remove(r)
+                if r in revs:
+                    ui.warn(_('skipping already grafted revision %d:%s '
+                              '(was grafted from %d:%s)\n') %
+                            (r, repo[r], rev, ctx))
+                    revs.remove(r)
         if not revs:
             return -1
 
diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -1390,6 +1390,52 @@ also detecting that both 3 and 5 should 
 
   $ cd ..
 
+Grafted revision should be warned and skipped only once. (issue6024)
+
+  $ mkdir issue6024
+  $ cd issue6024
+
+  $ hg init base
+  $ cd base
+  $ touch x
+  $ hg commit -qAminit
+  $ echo a > x
+  $ hg commit -mchange
+  $ hg update -q 0
+  $ hg graft -r 1
+  grafting 1:a0b923c546aa "change" (tip)
+  $ cd ..
+
+  $ hg clone -qr 2 base clone
+  $ cd clone
+  $ hg pull -q
+  $ hg merge -q 2
+  $ hg commit -mmerge
+  $ hg update -q 0
+  $ hg graft -r 1
+  grafting 1:04fc6d444368 "change"
+  $ hg update -q 3
+  $ hg log -G -T '{rev}:{node|shortest} <- {extras.source|shortest}\n'
+  o  4:4e16 <- a0b9
+  |
+  | @    3:f0ac <-
+  | |\
+  +---o  2:a0b9 <-
+  | |
+  | o  1:04fc <- a0b9
+  |/
+  o  0:7848 <-
+  
+
+ the source of rev 4 is an ancestor of the working parent, and was also
+ grafted as rev 1. it should be stripped from the target revisions only once.
+
+  $ hg graft -r 4
+  skipping already grafted revision 4:4e16bab40c9c (1:04fc6d444368 also has origin 2:a0b923c546aa)
+  [255]
+
+  $ cd ../..
+
 Testing the reading of old format graftstate file with newer mercurial
 
   $ hg init oldgraft


More information about the Mercurial-devel mailing list