changeset 30016:2963fba2d18a

log: copy the way of ancestor traversal to --follow matcher (issue5376) We can't use fctx.linkrev() because follow() revset tries hard to simulate the traversal of changelog DAG, not filelog DAG. This patch fixes _makefollowlogfilematcher() to walk file ancestors in the same way as revset._follow(). I'll factor out a common function in future patches.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 24 Sep 2016 19:58:23 +0900
parents 96b2dd3b184d
children 973cf6c3de30
files mercurial/cmdutil.py tests/test-log.t
diffstat 2 files changed, 75 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Sat Sep 24 19:52:02 2016 +0900
+++ b/mercurial/cmdutil.py	Sat Sep 24 19:58:23 2016 +0900
@@ -1941,7 +1941,7 @@
     # --follow, we want the names of the ancestors of FILE in the
     # revision, stored in "fcache". "fcache" is populated by
     # reproducing the graph traversal already done by --follow revset
-    # and relating linkrevs to file names (which is not "correct" but
+    # and relating revs to file names (which is not "correct" but
     # good enough).
     fcache = {}
     fcacheready = [False]
@@ -1950,9 +1950,9 @@
     def populate():
         for fn in files:
             fctx = pctx[fn]
-            fcache.setdefault(fctx.linkrev(), set()).add(fctx.path())
+            fcache.setdefault(fctx.introrev(), set()).add(fctx.path())
             for c in fctx.ancestors(followfirst=followfirst):
-                fcache.setdefault(c.linkrev(), set()).add(c.path())
+                fcache.setdefault(c.rev(), set()).add(c.path())
 
     def filematcher(rev):
         if not fcacheready[0]:
--- a/tests/test-log.t	Sat Sep 24 19:52:02 2016 +0900
+++ b/tests/test-log.t	Sat Sep 24 19:58:23 2016 +0900
@@ -933,6 +933,78 @@
 
   $ cd ..
 
+log --follow --patch FILE in repository where linkrev isn't trustworthy
+(issue5376)
+
+  $ hg init follow-dup
+  $ cd follow-dup
+  $ cat <<EOF >> .hg/hgrc
+  > [ui]
+  > logtemplate = '=== {rev}: {desc}\n'
+  > [diff]
+  > nodates = True
+  > EOF
+  $ echo 0 >> a
+  $ hg ci -qAm 'a0'
+  $ echo 1 >> a
+  $ hg ci -m 'a1'
+  $ hg up -q 0
+  $ echo 1 >> a
+  $ touch b
+  $ hg ci -qAm 'a1 with b'
+  $ echo 3 >> a
+  $ hg ci -m 'a3'
+
+ fctx.rev() == 2, but fctx.linkrev() == 1
+
+  $ hg log -pf a
+  === 3: a3
+  diff -r 4ea02ba94d66 -r e7a6331a34f0 a
+  --- a/a
+  +++ b/a
+  @@ -1,2 +1,3 @@
+   0
+   1
+  +3
+  
+  === 2: a1 with b
+  diff -r 49b5e81287e2 -r 4ea02ba94d66 a
+  --- a/a
+  +++ b/a
+  @@ -1,1 +1,2 @@
+   0
+  +1
+  
+  === 0: a0
+  diff -r 000000000000 -r 49b5e81287e2 a
+  --- /dev/null
+  +++ b/a
+  @@ -0,0 +1,1 @@
+  +0
+  
+
+ fctx.introrev() == 2, but fctx.linkrev() == 1
+
+  $ hg up -q 2
+  $ hg log -pf a
+  === 2: a1 with b
+  diff -r 49b5e81287e2 -r 4ea02ba94d66 a
+  --- a/a
+  +++ b/a
+  @@ -1,1 +1,2 @@
+   0
+  +1
+  
+  === 0: a0
+  diff -r 000000000000 -r 49b5e81287e2 a
+  --- /dev/null
+  +++ b/a
+  @@ -0,0 +1,1 @@
+  +0
+  
+
+  $ cd ..
+
 Test that log should respect the order of -rREV even if multiple OR conditions
 are specified (issue5100):