D7859: graftcopies: use _filter() for filtering out invalid copies

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Tue Jan 14 12:07:51 EST 2020


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  `graftcopies()` (formerly called `duplicatecopies()`) checked that the
  copy destination existed in the working copy, but it didn't check that
  copy source existed in the parent of the working copy. In
  `test-graft.t` we can see that as warnings about not finding ancestors
  of the copied files, and also empty commits getting created.
  
  This patch uses the existing `_filter()` function for filtering out
  invalid copies. In addition to the aforementioned types, that also
  includes copies where source and destination is the same.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7859

AFFECTED FILES
  mercurial/copies.py
  tests/test-graft-rename.t
  tests/test-graft.t
  tests/test-issue1175.t

CHANGE DETAILS

diff --git a/tests/test-issue1175.t b/tests/test-issue1175.t
--- a/tests/test-issue1175.t
+++ b/tests/test-issue1175.t
@@ -82,7 +82,6 @@
   continue: hg graft --continue
   $ hg graft --continue
   grafting 1:5974126fad84 "b1"
-  warning: can't find ancestor for 'b' copied from 'a'!
   $ hg log -f b -T 'changeset:   {rev}:{node|short}\nsummary:     {desc}\n\n'
   changeset:   3:376d30ccffc0
   summary:     b1
diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -493,7 +493,6 @@
   $ hg up -Cq 1
   $ hg graft 3 --log -u foo
   grafting 3:4c60f11aa304 "3"
-  warning: can't find ancestor for 'c' copied from 'b'!
   $ hg log --template '{rev}:{node|short} {parents} {desc}\n' -r tip
   14:0c921c65ef1e 1:5d205f8b35b6  3
   (grafted from 4c60f11aa304a54ae1c199feb94e7fc771e51ed8)
@@ -753,12 +752,7 @@
    branchmerge: True, force: True, partial: False
    ancestor: b592ea63bb0c, local: 7e61b508e709+, remote: 7a4785234d87
   starting 4 threads for background file closing (?)
-  committing files:
-  b
-  warning: can't find ancestor for 'b' copied from 'a'!
-  reusing manifest from p1 (listed files actually unchanged)
-  committing changelog
-  updating the branch cache
+  note: graft of 13:7a4785234d87 created no changes to commit
   $ hg log -r 'destination(13)'
 All copies of a cset
   $ hg log -r 'origin(13) or destination(origin(13))'
@@ -785,12 +779,6 @@
   
   changeset:   21:7e61b508e709
   branch:      dev
-  user:        foo
-  date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     2
-  
-  changeset:   22:3a4e92d81b97
-  branch:      dev
   tag:         tip
   user:        foo
   date:        Thu Jan 01 00:00:00 1970 +0000
@@ -809,27 +797,28 @@
   $ hg graft 19 0 6
   skipping ungraftable merge revision 6
   skipping ancestor revision 0:68795b066622
-  skipping already grafted revision 19:9627f653b421 (22:3a4e92d81b97 also has origin 2:5c095ad7e90f)
-  [255]
+  grafting 19:9627f653b421 "2"
+  merging b
+  note: graft of 19:9627f653b421 created no changes to commit
   $ hg graft 19 0 6 --force
   skipping ungraftable merge revision 6
   grafting 19:9627f653b421 "2"
   merging b
-  warning: can't find ancestor for 'b' copied from 'a'!
+  note: graft of 19:9627f653b421 created no changes to commit
   grafting 0:68795b066622 "0"
 
 graft --force after backout
 
   $ echo abc > a
-  $ hg ci -m 26
-  $ hg backout 26
+  $ hg ci -m 24
+  $ hg backout 24
   reverting a
-  changeset 27:e25e17192dc4 backs out changeset 26:44f862488a35
-  $ hg graft 26
-  skipping ancestor revision 26:44f862488a35
+  changeset 25:71c4e63d4f98 backs out changeset 24:2e7ea477be26
+  $ hg graft 24
+  skipping ancestor revision 24:2e7ea477be26
   [255]
-  $ hg graft 26 --force
-  grafting 26:44f862488a35 "26"
+  $ hg graft 24 --force
+  grafting 24:2e7ea477be26 "24"
   merging a
   $ cat a
   abc
@@ -837,9 +826,9 @@
 graft --continue after --force
 
   $ echo def > a
-  $ hg ci -m 29
-  $ hg graft 26 --force --tool internal:fail
-  grafting 26:44f862488a35 "26"
+  $ hg ci -m 27
+  $ hg graft 24 --force --tool internal:fail
+  grafting 24:2e7ea477be26 "24"
   abort: unresolved conflicts, can't continue
   (use 'hg resolve' and 'hg graft --continue')
   [255]
@@ -852,7 +841,7 @@
   (no more unresolved files)
   continue: hg graft --continue
   $ hg graft -c
-  grafting 26:44f862488a35 "26"
+  grafting 24:2e7ea477be26 "24"
   $ cat a
   abc
 
@@ -869,12 +858,12 @@
 
 Empty graft
 
-  $ hg up -qr 24
+  $ hg up -qr 22
   $ hg tag -f something
-  $ hg graft -qr 25
-  $ hg graft -f 25
-  grafting 25:bd0c98709948 "26"
-  note: graft of 25:bd0c98709948 created no changes to commit
+  $ hg graft -qr 23
+  $ hg graft -f 23
+  grafting 23:72d9c7c75bcc "24"
+  note: graft of 23:72d9c7c75bcc created no changes to commit
 
   $ cd ..
 
diff --git a/tests/test-graft-rename.t b/tests/test-graft-rename.t
--- a/tests/test-graft-rename.t
+++ b/tests/test-graft-rename.t
@@ -118,7 +118,6 @@
   grafting 2:f58c7e2b28fa "C0"
   merging f1a and f1b to f1a
   merging f5a
-  warning: can't find ancestor for 'f5a' copied from 'f5b'!
   $ hg status --change .
   M f1a
   M f5a
@@ -137,7 +136,6 @@
   note: possible conflict - f3b was renamed multiple times to:
    f3a
    f3d
-  warning: can't find ancestor for 'f3d' copied from 'f3b'!
 
 Set up the repository for some further tests
 
@@ -224,7 +222,6 @@
    f3d
    f3e
   merging f4e and f4a to f4e
-  warning: can't find ancestor for 'f3d' copied from 'f3b'!
 
   $ hg cat f2c
   c2e
@@ -232,7 +229,6 @@
 Test the case A.5 (move case, f1x).
 
   $ hg up -q "desc("C0")"
-BROKEN: Shouldn't get the warning about missing ancestor
   $ HGEDITOR="echo E1 >" hg graft -r 'desc("E0")' --edit
   grafting 6:6bd1736cab86 "E0"
   note: possible conflict - f1a was renamed multiple times to:
@@ -243,18 +239,14 @@
    f3e
   merging f2c and f2a to f2c
   merging f5a and f5b to f5b
-  warning: can't find ancestor for 'f1e' copied from 'f1a'!
-  warning: can't find ancestor for 'f3e' copied from 'f3a'!
   $ cat f1e
   c1a
 
 Test the case A.5 (copy case, f1x).
 
   $ hg up -q "desc("C0")"
-BROKEN: Shouldn't get the warning about missing ancestor
   $ HGEDITOR="echo F1 >" hg graft -r 'desc("F0")' --edit
   grafting 7:d376ab0d7fda "F0"
-  warning: can't find ancestor for 'f1f' copied from 'f1a'!
 BROKEN: f1f should be marked a copy from f1b
   $ hg st --copies --change .
   A f1f
@@ -270,7 +262,6 @@
 "c1a")
   $ HGEDITOR="echo G1 >" hg graft -r 'desc("G0")' --edit
   grafting 8:ba67f08fb15a "G0"
-  warning: can't find ancestor for 'f1g' copied from 'f1a'!
 
 Check the results of the grafts tested
 
diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -875,11 +875,12 @@
         # of the function is much faster (and is required for carrying copy
         # metadata across the rebase anyway).
         exclude = pathcopies(base, skip)
-    for dst, src in pycompat.iteritems(pathcopies(base, ctx)):
+    new_copies = pathcopies(base, ctx)
+    _filter(wctx.p1(), wctx, new_copies)
+    for dst, src in pycompat.iteritems(new_copies):
         if dst in exclude:
             continue
-        if dst in wctx:
-            wctx[dst].markcopied(src)
+        wctx[dst].markcopied(src)
 
 
 def computechangesetfilesadded(ctx):



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list