Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 4211:e29f2db5ab18
Make the tags algorithm smarter
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 14 Mar 2007 18:47:29 -0500 |
parents | caff92047e87 |
children | 6c0be67c2b27 |
comparison
equal
deleted
inserted
replaced
4210:caff92047e87 | 4211:e29f2db5ab18 |
---|---|
258 def tags(self): | 258 def tags(self): |
259 '''return a mapping of tag to node''' | 259 '''return a mapping of tag to node''' |
260 if self.tagscache: | 260 if self.tagscache: |
261 return self.tagscache | 261 return self.tagscache |
262 | 262 |
263 self.tagscache = {} | 263 globaltags = {} |
264 globalover = {} | |
264 | 265 |
265 def readtags(lines, fn): | 266 def readtags(lines, fn): |
266 filetags = {} | 267 filetags = {} |
268 fileover = {} | |
267 count = 0 | 269 count = 0 |
268 | 270 |
269 def warn(msg): | 271 def warn(msg): |
270 self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg)) | 272 self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg)) |
271 | 273 |
285 warn(_("node '%s' is not well formed") % node) | 287 warn(_("node '%s' is not well formed") % node) |
286 continue | 288 continue |
287 if bin_n not in self.changelog.nodemap: | 289 if bin_n not in self.changelog.nodemap: |
288 warn(_("tag '%s' refers to unknown node") % key) | 290 warn(_("tag '%s' refers to unknown node") % key) |
289 continue | 291 continue |
290 self.tagscache[key] = bin_n | 292 |
291 | 293 h = {} |
292 # read the tags file from each head, ending with the tip, | 294 if key in filetags: |
293 # and add each tag found to the map, with "newer" ones | 295 n, h = filetags[key] |
294 # taking precedence | 296 h[n] = True |
297 filetags[key] = (bin_n, h) | |
298 | |
299 for k,nh in filetags.items(): | |
300 if k not in globaltags: | |
301 globaltags[k] = nh | |
302 continue | |
303 # we prefer the global tag if: | |
304 # it supercedes us OR | |
305 # mutual supercedes and it has a higher rank | |
306 # otherwise we win because we're tip-most | |
307 an, ah = nh | |
308 bn, bh = globaltags[k] | |
309 if bn != an and an in bh and \ | |
310 (bn not in ah or len(bh) > len(ah)): | |
311 an = bn | |
312 ah.update(bh) | |
313 globaltags[k] = an, ah | |
314 | |
315 # read the tags file from each head, ending with the tip | |
295 f = None | 316 f = None |
296 for rev, node, fnode in self._hgtagsnodes(): | 317 for rev, node, fnode in self._hgtagsnodes(): |
297 f = (f and f.filectx(fnode) or | 318 f = (f and f.filectx(fnode) or |
298 self.filectx('.hgtags', fileid=fnode)) | 319 self.filectx('.hgtags', fileid=fnode)) |
299 readtags(f.data().splitlines(), f) | 320 readtags(f.data().splitlines(), f) |
304 # while the internal tag table is stored in UTF-8 | 325 # while the internal tag table is stored in UTF-8 |
305 readtags(data.splitlines(), "localtags") | 326 readtags(data.splitlines(), "localtags") |
306 except IOError: | 327 except IOError: |
307 pass | 328 pass |
308 | 329 |
330 self.tagscache = {} | |
331 for k,nh in globaltags.items(): | |
332 n = nh[0] | |
333 self.tagscache[k] = n | |
309 self.tagscache['tip'] = self.changelog.tip() | 334 self.tagscache['tip'] = self.changelog.tip() |
310 | 335 |
311 return self.tagscache | 336 return self.tagscache |
312 | 337 |
313 def _hgtagsnodes(self): | 338 def _hgtagsnodes(self): |