Mercurial > hg
comparison mercurial/copies.py @ 24782:4906dc0e038c
copies: add matcher parameter to copy logic
This allows passing a matcher down the pathcopies() stack to _forwardcopies().
This will let us add logic in a later patch to avoid tracing copies when not
necessary (like when doing hg diff -r 1 -r 2 foo.txt).
author | Durham Goode <durham@fb.com> |
---|---|
date | Thu, 16 Apr 2015 11:29:30 -0700 |
parents | 2cebf17c0fcc |
children | 708b19c18adf 0f28815ef066 |
comparison
equal
deleted
inserted
replaced
24781:055b3cbe6c57 | 24782:4906dc0e038c |
---|---|
138 for k in c.keys(): | 138 for k in c.keys(): |
139 if ds[k] not in 'anm': | 139 if ds[k] not in 'anm': |
140 del c[k] | 140 del c[k] |
141 return c | 141 return c |
142 | 142 |
143 def _computeforwardmissing(a, b): | 143 def _computeforwardmissing(a, b, match=None): |
144 """Computes which files are in b but not a. | 144 """Computes which files are in b but not a. |
145 This is its own function so extensions can easily wrap this call to see what | 145 This is its own function so extensions can easily wrap this call to see what |
146 files _forwardcopies is about to process. | 146 files _forwardcopies is about to process. |
147 """ | 147 """ |
148 return b.manifest().filesnotin(a.manifest()) | 148 ma = a.manifest() |
149 | 149 mb = b.manifest() |
150 def _forwardcopies(a, b): | 150 if match: |
151 ma = ma.matches(match) | |
152 mb = mb.matches(match) | |
153 return mb.filesnotin(ma) | |
154 | |
155 def _forwardcopies(a, b, match=None): | |
151 '''find {dst@b: src@a} copy mapping where a is an ancestor of b''' | 156 '''find {dst@b: src@a} copy mapping where a is an ancestor of b''' |
152 | 157 |
153 # check for working copy | 158 # check for working copy |
154 w = None | 159 w = None |
155 if b.rev() is None: | 160 if b.rev() is None: |
168 | 173 |
169 # find where new files came from | 174 # find where new files came from |
170 # we currently don't try to find where old files went, too expensive | 175 # we currently don't try to find where old files went, too expensive |
171 # this means we can miss a case like 'hg rm b; hg cp a b' | 176 # this means we can miss a case like 'hg rm b; hg cp a b' |
172 cm = {} | 177 cm = {} |
173 missing = _computeforwardmissing(a, b) | 178 missing = _computeforwardmissing(a, b, match=match) |
174 ancestrycontext = a._repo.changelog.ancestors([b.rev()], inclusive=True) | 179 ancestrycontext = a._repo.changelog.ancestors([b.rev()], inclusive=True) |
175 for f in missing: | 180 for f in missing: |
176 fctx = b[f] | 181 fctx = b[f] |
177 fctx._ancestrycontext = ancestrycontext | 182 fctx._ancestrycontext = ancestrycontext |
178 ofctx = _tracefile(fctx, am, limit) | 183 ofctx = _tracefile(fctx, am, limit) |
196 if v in a: | 201 if v in a: |
197 continue | 202 continue |
198 r[v] = k | 203 r[v] = k |
199 return r | 204 return r |
200 | 205 |
201 def pathcopies(x, y): | 206 def pathcopies(x, y, match=None): |
202 '''find {dst@y: src@x} copy mapping for directed compare''' | 207 '''find {dst@y: src@x} copy mapping for directed compare''' |
203 if x == y or not x or not y: | 208 if x == y or not x or not y: |
204 return {} | 209 return {} |
205 a = y.ancestor(x) | 210 a = y.ancestor(x) |
206 if a == x: | 211 if a == x: |
207 return _forwardcopies(x, y) | 212 return _forwardcopies(x, y, match=match) |
208 if a == y: | 213 if a == y: |
209 return _backwardrenames(x, y) | 214 return _backwardrenames(x, y) |
210 return _chain(x, y, _backwardrenames(x, a), _forwardcopies(a, y)) | 215 return _chain(x, y, _backwardrenames(x, a), |
216 _forwardcopies(a, y, match=match)) | |
211 | 217 |
212 def _computenonoverlap(repo, c1, c2, addedinm1, addedinm2): | 218 def _computenonoverlap(repo, c1, c2, addedinm1, addedinm2): |
213 """Computes, based on addedinm1 and addedinm2, the files exclusive to c1 | 219 """Computes, based on addedinm1 and addedinm2, the files exclusive to c1 |
214 and c2. This is its own function so extensions can easily wrap this call | 220 and c2. This is its own function so extensions can easily wrap this call |
215 to see what files mergecopies is about to process. | 221 to see what files mergecopies is about to process. |