comparison mercurial/copies.py @ 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 4327687ca757
children 3db9e798e004
comparison
equal deleted inserted replaced
20293:2f6b3900be64 20294:243ea5ffdf31
96 if k in src and v in dst: 96 if k in src and v in dst:
97 del t[k] 97 del t[k]
98 98
99 return t 99 return t
100 100
101 def _tracefile(fctx, actx): 101 def _tracefile(fctx, am, limit=-1):
102 '''return file context that is the ancestor of fctx present in actx''' 102 '''return file context that is the ancestor of fctx present in ancestor
103 stop = actx.rev() 103 manifest am, stopping after the first ancestor lower than limit'''
104 am = actx.manifest()
105 104
106 for f in fctx.ancestors(): 105 for f in fctx.ancestors():
107 if am.get(f.path(), None) == f.filenode(): 106 if am.get(f.path(), None) == f.filenode():
108 return f 107 return f
109 if f.rev() < stop: 108 if f.rev() < limit:
110 return None 109 return None
111 110
112 def _dirstatecopies(d): 111 def _dirstatecopies(d):
113 ds = d._repo.dirstate 112 ds = d._repo.dirstate
114 c = ds.copies().copy() 113 c = ds.copies().copy()
127 b = w.p1() 126 b = w.p1()
128 if a == b: 127 if a == b:
129 # short-circuit to avoid issues with merge states 128 # short-circuit to avoid issues with merge states
130 return _dirstatecopies(w) 129 return _dirstatecopies(w)
131 130
131 # files might have to be traced back to the fctx parent of the last
132 # one-side-only changeset, but not further back than that
133 limit = _findlimit(a._repo, a.rev(), b.rev())
134 if limit is None:
135 limit = -1
136 am = a.manifest()
137
132 # find where new files came from 138 # find where new files came from
133 # we currently don't try to find where old files went, too expensive 139 # we currently don't try to find where old files went, too expensive
134 # this means we can miss a case like 'hg rm b; hg cp a b' 140 # this means we can miss a case like 'hg rm b; hg cp a b'
135 cm = {} 141 cm = {}
136 missing = set(b.manifest().iterkeys()) 142 missing = set(b.manifest().iterkeys())
137 missing.difference_update(a.manifest().iterkeys()) 143 missing.difference_update(a.manifest().iterkeys())
138 144
139 for f in missing: 145 for f in missing:
140 ofctx = _tracefile(b[f], a) 146 ofctx = _tracefile(b[f], am, limit)
141 if ofctx: 147 if ofctx:
142 cm[f] = ofctx.path() 148 cm[f] = ofctx.path()
143 149
144 # combine copies from dirstate if necessary 150 # combine copies from dirstate if necessary
145 if w is not None: 151 if w is not None: