comparison mercurial/localrepo.py @ 3577:7f7425306925

Correct optimization from 3464f5e77f34; add a test. If there are two (or more) heads that point to the same .hgtags node, we can safely skip parsing the file in all but the last head. (In 3464f5e77f34, we were parsing the file in the first head and skipping all the others.)
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Sat, 28 Oct 2006 23:37:59 -0300
parents 23f7d9621783
children 3b4e00cba57a
comparison
equal deleted inserted replaced
3576:00427c4b533b 3577:7f7425306925
242 self.tagscache[key] = bin_n 242 self.tagscache[key] = bin_n
243 243
244 # read the tags file from each head, ending with the tip, 244 # read the tags file from each head, ending with the tip,
245 # and add each tag found to the map, with "newer" ones 245 # and add each tag found to the map, with "newer" ones
246 # taking precedence 246 # taking precedence
247 heads = self.heads() 247 f = None
248 heads.reverse() 248 for rev, node, fnode in self._hgtagsnodes():
249 seen = {} 249 f = (f and f.filectx(fnode) or
250 for node in heads: 250 self.filectx('.hgtags', fileid=fnode))
251 f = self.filectx('.hgtags', node)
252 if not f or f.filerev() in seen: continue
253 seen[f.filerev()] = 1
254 count = 0 251 count = 0
255 for l in f.data().splitlines(): 252 for l in f.data().splitlines():
256 count += 1 253 count += 1
257 parsetag(l, _("%s, line %d") % (str(f), count)) 254 parsetag(l, _("%s, line %d") % (str(f), count))
258 255
266 pass 263 pass
267 264
268 self.tagscache['tip'] = self.changelog.tip() 265 self.tagscache['tip'] = self.changelog.tip()
269 266
270 return self.tagscache 267 return self.tagscache
268
269 def _hgtagsnodes(self):
270 heads = self.heads()
271 heads.reverse()
272 last = {}
273 ret = []
274 for node in heads:
275 c = self.changectx(node)
276 rev = c.rev()
277 try:
278 fnode = c.filenode('.hgtags')
279 except repo.LookupError:
280 continue
281 ret.append((rev, node, fnode))
282 if fnode in last:
283 ret[last[fnode]] = None
284 last[fnode] = len(ret) - 1
285 return [item for item in ret if item]
271 286
272 def tagslist(self): 287 def tagslist(self):
273 '''return a list of tags ordered by revision''' 288 '''return a list of tags ordered by revision'''
274 l = [] 289 l = []
275 for t, n in self.tags().items(): 290 for t, n in self.tags().items():