diff: search beyond ancestor when detecting renames

This removes an optimization that was introduced in 5a644704d5eb 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.
This commit is contained in:
Mads Kiilerich 2013-11-16 15:46:29 -05:00
parent 8db38e4850
commit 3ee1a27c56
3 changed files with 56 additions and 10 deletions

View File

@ -98,15 +98,14 @@ def _chain(src, dst, a, b):
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 @@ def _forwardcopies(a, b):
# 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 @@ def _forwardcopies(a, b):
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()

View File

@ -147,11 +147,13 @@ Check patcha is still a git patch:
-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:

View File

@ -1567,3 +1567,41 @@ unrelated branch diff
@@ -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 ..