# HG changeset patch # User Patrick Mezard # Date 1330113479 -3600 # Node ID 60101427d618a0d774d2d1fd29838ec81f3bba7c # Parent 18743c4d198966309450e14ec0ac52177a9c280f 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 -r 18743c4d1989 -r 60101427d618 mercurial/cmdutil.py --- 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(): diff -r 18743c4d1989 -r 60101427d618 tests/test-convert-hg-startrev.t --- 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 diff -r 18743c4d1989 -r 60101427d618 tests/test-log.t --- 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'