[PATCH 2 of 2 STABLE] log: fix --follow FILE ancestry calculation

Patrick Mezard patrick at mezard.eu
Fri Feb 24 14:12:53 CST 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1330113479 -3600
# Branch stable
# Node ID 3d2a2f074162f30880f36efeb1b85c15f09ce9aa
# Parent  3aac56cd94be3652dee1a3eabdbb971c83e04562
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.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -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():
diff --git a/tests/test-convert-hg-startrev.t b/tests/test-convert-hg-startrev.t
--- a/tests/test-convert-hg-startrev.t
+++ b/tests/test-convert-hg-startrev.t
@@ -115,6 +115,7 @@
   o  0 "1: add c" files: a b c
   
   $ cd conv1
+  $ hg up -q
 
 Check copy preservation
 
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -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'


More information about the Mercurial-devel mailing list