Patchwork [01,of,12,v2] checkcopies: add a sanity check against false-positive copies

login
register
mail settings
Submitter Gábor Stefanik
Date Oct. 16, 2016, 3:15 p.m.
Message ID <e8e15a687df328f37b2d.1476630938@GSTEFANIK.NavnGo.local>
Download mbox | patch
Permalink /patch/17130/
State Accepted
Headers show

Comments

Gábor Stefanik - Oct. 16, 2016, 3:15 p.m.
# HG changeset patch
# User Gábor Stefanik <gabor.stefanik@nng.com>
# Date 1476300825 -7200
#      Wed Oct 12 21:33:45 2016 +0200
# Node ID e8e15a687df328f37b2d5e97e67f1a2071b35134
# Parent  bfb99ef3749757161bf439cc0ec678de46e24672
checkcopies: add a sanity check against false-positive copies

When grafting a copy backwards through a rename, a copy is wrongly detected,
which causes the graft to be applied inappropriately, in a destructive way.
Make sure that the old file name really exists in the common ancestor,
and bail out if it doesn't.

This fixes the aggravated case of bug 5343, although the basic issue
(failure to duplicate the copy information) still occurs.

Patch

diff -r bfb99ef37497 -r e8e15a687df3 mercurial/copies.py
--- a/mercurial/copies.py	Thu Oct 13 01:30:14 2016 +0200
+++ b/mercurial/copies.py	Wed Oct 12 21:33:45 2016 +0200
@@ -543,7 +543,8 @@ 
         # unrelated to the droids we are looking for.
         cr = _related(oc, c2, base.rev())
         if cr and (of == f or of == c2.path()): # non-divergent
-            data['copy'][f] = of
+            if of in mb:
+                data['copy'][f] = of
             return
 
     if of in mb:
diff -r bfb99ef37497 -r e8e15a687df3 tests/test-graft.t
--- a/tests/test-graft.t	Thu Oct 13 01:30:14 2016 +0200
+++ b/tests/test-graft.t	Wed Oct 12 21:33:45 2016 +0200
@@ -427,8 +427,8 @@ 
   $ hg graft 3 --log -u foo
   grafting 3:4c60f11aa304 "3"
   warning: can't find ancestor for 'c' copied from 'b'!
-  $ hg log --template '{rev} {parents} {desc}\n' -r tip
-  14 1:5d205f8b35b6  3
+  $ hg log --template '{rev}:{node|short} {parents} {desc}\n' -r tip
+  14:0c921c65ef1e 1:5d205f8b35b6  3
   (grafted from 4c60f11aa304a54ae1c199feb94e7fc771e51ed8)
 
 Resolve conflicted graft
@@ -620,7 +620,7 @@ 
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     2
   
-  changeset:   14:f64defefacee
+  changeset:   14:0c921c65ef1e
   parent:      1:5d205f8b35b6
   user:        foo
   date:        Thu Jan 01 00:00:00 1970 +0000