changeset 16165:60101427d618 stable

log: fix --follow FILE ancestry calculation Currently, --follow FILE looks for a FILE filelog, scans it and collects linkrevs and renames, then filters them. The problem is the filelog scan does not start at FILE filenode in parent revision but at the last filelog revision. So: - Files not in the parent revision can be followed, the starting node is unexpected - Files in the parent revision can be followed from an incorrect starting node. This patch makes log --follow FILE fail if FILE is not in parent revision, and computes ancestors of the parent revision FILE filenode.
author Patrick Mezard <patrick@mezard.eu>
date Fri, 24 Feb 2012 20:57:59 +0100
parents 18743c4d1989
children 5b0a4383cd5e 280e834c9d15 87d37aceb5e3
files mercurial/cmdutil.py tests/test-convert-hg-startrev.t tests/test-log.t
diffstat 3 files changed, 27 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Fri Feb 24 20:56:18 2012 +0100
+++ b/mercurial/cmdutil.py	Fri Feb 24 20:57:59 2012 +0100
@@ -1024,8 +1024,15 @@
 
             return reversed(revs)
         def iterfiles():
+            pctx = repo['.']
             for filename in match.files():
-                yield filename, None
+                if follow:
+                    if filename not in pctx:
+                        raise util.Abort(_('cannot follow file not in parent '
+                                           'revision: "%s"') % filename)
+                    yield filename, pctx[filename].filenode()
+                else:
+                    yield filename, None
             for filename_node in copies:
                 yield filename_node
         for file_, node in iterfiles():
--- a/tests/test-convert-hg-startrev.t	Fri Feb 24 20:56:18 2012 +0100
+++ b/tests/test-convert-hg-startrev.t	Fri Feb 24 20:57:59 2012 +0100
@@ -115,6 +115,7 @@
   o  0 "1: add c" files: a b c
   
   $ cd conv1
+  $ hg up -q
 
 Check copy preservation
 
--- a/tests/test-log.t	Fri Feb 24 20:56:18 2012 +0100
+++ b/tests/test-log.t	Fri Feb 24 20:57:59 2012 +0100
@@ -40,7 +40,7 @@
 -f, directory
 
   $ hg log -f dir
-  abort: cannot follow nonexistent file: "dir"
+  abort: cannot follow file not in parent revision: "dir"
   [255]
 
 -f, but no args
@@ -75,6 +75,7 @@
 
 one rename
 
+  $ hg up -q 2
   $ hg log -vf a
   changeset:   0:9161b9aeaf16
   user:        test
@@ -87,6 +88,7 @@
 
 many renames
 
+  $ hg up -q tip
   $ hg log -vf e
   changeset:   4:7e4639b4691b
   tag:         tip
@@ -125,6 +127,7 @@
 
 log -pf dir/b
 
+  $ hg up -q 3
   $ hg log -pf dir/b
   changeset:   2:f8954cd4dc1f
   user:        test
@@ -189,6 +192,20 @@
   
 
 
+-f and multiple filelog heads
+
+  $ hg up -q 2
+  $ hg log -f g --template '{rev}\n'
+  2
+  1
+  0
+  $ hg up -q tip
+  $ hg log -f g --template '{rev}\n'
+  3
+  2
+  0
+
+
 log copies with --copies
 
   $ hg log -vC --template '{rev} {file_copies}\n'