Mercurial > hg
changeset 20294:243ea5ffdf31
diff: search beyond ancestor when detecting renames
This removes an optimization that was introduced in 91eb4512edd0 but was too
aggressive - as indicated by how it changed test-mq-merge.t .
We are walking filelogs to find copy sources and we can thus not be sure to hit
the base revision and find the renamed file there - it could also be in the
first ancestor of the base ... in the filelog.
We are walking the filelog and can thus not easily know when we hit the first
ancestor of the base revision and which filename to look for there. Instead, we
use _findlimit like mergecopies do: The lower bound for how far we have to go
is found from the lowest changelog revision that is an ancestor of only one of
the compared revisions. Any filelog ancestor with a revision number lower than
that revision will be the ancestor of both compared revisions, and there is
thus no reason to go further back than that.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Sat, 16 Nov 2013 15:46:29 -0500 |
parents | 2f6b3900be64 |
children | 36333ff8c54d |
files | mercurial/copies.py tests/test-mq-merge.t tests/test-mv-cp-st-diff.t |
diffstat | 3 files changed, 56 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/copies.py Tue Jan 14 13:38:16 2014 -0800 +++ b/mercurial/copies.py Sat Nov 16 15:46:29 2013 -0500 @@ -98,15 +98,14 @@ return t -def _tracefile(fctx, actx): - '''return file context that is the ancestor of fctx present in actx''' - stop = actx.rev() - am = actx.manifest() +def _tracefile(fctx, am, limit=-1): + '''return file context that is the ancestor of fctx present in ancestor + manifest am, stopping after the first ancestor lower than limit''' for f in fctx.ancestors(): if am.get(f.path(), None) == f.filenode(): return f - if f.rev() < stop: + if f.rev() < limit: return None def _dirstatecopies(d): @@ -129,6 +128,13 @@ # short-circuit to avoid issues with merge states return _dirstatecopies(w) + # files might have to be traced back to the fctx parent of the last + # one-side-only changeset, but not further back than that + limit = _findlimit(a._repo, a.rev(), b.rev()) + if limit is None: + limit = -1 + am = a.manifest() + # find where new files came from # we currently don't try to find where old files went, too expensive # this means we can miss a case like 'hg rm b; hg cp a b' @@ -137,7 +143,7 @@ missing.difference_update(a.manifest().iterkeys()) for f in missing: - ofctx = _tracefile(b[f], a) + ofctx = _tracefile(b[f], am, limit) if ofctx: cm[f] = ofctx.path()
--- a/tests/test-mq-merge.t Tue Jan 14 13:38:16 2014 -0800 +++ b/tests/test-mq-merge.t Sat Nov 16 15:46:29 2013 -0500 @@ -147,11 +147,13 @@ -b +a +c - diff --git a/aa b/aa - new file mode 100644 - --- /dev/null + diff --git a/a b/aa + copy from a + copy to aa + --- a/a +++ b/aa - @@ -0,0 +1,1 @@ + @@ -1,1 +1,1 @@ + -b +a Check patcha2 is still a regular patch:
--- a/tests/test-mv-cp-st-diff.t Tue Jan 14 13:38:16 2014 -0800 +++ b/tests/test-mv-cp-st-diff.t Sat Nov 16 15:46:29 2013 -0500 @@ -1567,3 +1567,41 @@ @@ -0,0 +1,1 @@ +a $ cd .. + + +test for case where we didn't look sufficiently far back to find rename ancestor + + $ hg init diffstop + $ cd diffstop + $ echo > f + $ hg ci -qAmf + $ hg mv f g + $ hg ci -m'f->g' + $ hg up -qr0 + $ touch x + $ hg ci -qAmx + $ echo f > f + $ hg ci -qmf=f + $ hg merge -q + $ hg ci -mmerge + $ hg log -G --template '{rev} {desc}' + @ 4 merge + |\ + | o 3 f=f + | | + | o 2 x + | | + o | 1 f->g + |/ + o 0 f + + $ hg diff --git -r 2 + diff --git a/f b/g + rename from f + rename to g + --- a/f + +++ b/g + @@ -1,1 +1,1 @@ + - + +f + $ cd ..