comparison mercurial/copies.py @ 43255:b8d60845fa5d

copies: extract data extraction into a `revinfo` function The function is build once at the beginning of the algorithm and used fetch appropriate information for each revision. This abstracts some implementation details from the main algorithm and will help us to access the data more efficiently in future changesets. Differential Revision: https://phab.mercurial-scm.org/D7070
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 02 Oct 2019 17:42:01 -0400
parents 181d28ba05da
children 00de32aa834e
comparison
equal deleted inserted replaced
43254:181d28ba05da 43255:b8d60845fa5d
176 % (util.timer() - start) 176 % (util.timer() - start)
177 ) 177 )
178 return cm 178 return cm
179 179
180 180
181 def _revinfogetter(repo):
182 """return a function that return multiple data given a <rev>"i
183
184 * p1: revision number of first parent
185 * p2: revision number of first parent
186 * p1copies: mapping of copies from p1
187 * p2copies: mapping of copies from p2
188 * removed: a list of removed files
189 """
190 cl = repo.changelog
191 parents = cl.parentrevs
192
193 def revinfo(rev):
194 p1, p2 = parents(rev)
195 ctx = repo[rev]
196 p1copies, p2copies = ctx._copies
197 removed = ctx.filesremoved()
198 return p1, p2, p1copies, p2copies, removed
199
200 return revinfo
201
202
181 def _changesetforwardcopies(a, b, match): 203 def _changesetforwardcopies(a, b, match):
182 if a.rev() in (node.nullrev, b.rev()): 204 if a.rev() in (node.nullrev, b.rev()):
183 return {} 205 return {}
184 206
185 repo = a.repo() 207 repo = a.repo()
186 children = {} 208 children = {}
209 revinfo = _revinfogetter(repo)
210
187 cl = repo.changelog 211 cl = repo.changelog
188 missingrevs = cl.findmissingrevs(common=[a.rev()], heads=[b.rev()]) 212 missingrevs = cl.findmissingrevs(common=[a.rev()], heads=[b.rev()])
189 for r in missingrevs: 213 for r in missingrevs:
190 for p in cl.parentrevs(r): 214 for p in cl.parentrevs(r):
191 if p == node.nullrev: 215 if p == node.nullrev:
204 r = heapq.heappop(work) 228 r = heapq.heappop(work)
205 copies = all_copies.pop(r) 229 copies = all_copies.pop(r)
206 if r == b.rev(): 230 if r == b.rev():
207 return copies 231 return copies
208 for i, c in enumerate(children[r]): 232 for i, c in enumerate(children[r]):
209 childctx = repo[c] 233 p1, p2, p1copies, p2copies, removed = revinfo(c)
210 p1, p2 = cl.parentrevs(c)
211 p1copies, p2copies = childctx._copies
212 if r == p1: 234 if r == p1:
213 parent = 1 235 parent = 1
214 childcopies = p1copies 236 childcopies = p1copies
215 else: 237 else:
216 assert r == p2 238 assert r == p2
225 newcopies = copies.copy() 247 newcopies = copies.copy()
226 else: 248 else:
227 newcopies = copies 249 newcopies = copies
228 if childcopies: 250 if childcopies:
229 newcopies = _chain(newcopies, childcopies) 251 newcopies = _chain(newcopies, childcopies)
230 for f in childctx.filesremoved(): 252 for f in removed:
231 if f in newcopies: 253 if f in newcopies:
232 del newcopies[f] 254 del newcopies[f]
233 othercopies = all_copies.get(c) 255 othercopies = all_copies.get(c)
234 if othercopies is None: 256 if othercopies is None:
235 heapq.heappush(work, c) 257 heapq.heappush(work, c)