Mercurial > hg
comparison mercurial/localrepo.py @ 16371:4417eb761ba8
tags: defer tag validation until repo.tags() is called
Before, we were validating all tags for any tag operation, which meant
building a (nearly) full node->tag lookup tree for most operations.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 06 Apr 2012 15:16:30 -0500 |
parents | 6097ede2be4d |
children | c463f46fe050 |
comparison
equal
deleted
inserted
replaced
16370:28bb4daf070c | 16371:4417eb761ba8 |
---|---|
396 | 396 |
397 return cache | 397 return cache |
398 | 398 |
399 def tags(self): | 399 def tags(self): |
400 '''return a mapping of tag to node''' | 400 '''return a mapping of tag to node''' |
401 return self._tagscache.tags | 401 t = {} |
402 for k, v in self._tagscache.tags.iteritems(): | |
403 try: | |
404 # ignore tags to unknown nodes | |
405 self.changelog.rev(v) | |
406 t[k] = v | |
407 except error.LookupError: | |
408 pass | |
409 return t | |
402 | 410 |
403 def _findtags(self): | 411 def _findtags(self): |
404 '''Do the hard work of finding tags. Return a pair of dicts | 412 '''Do the hard work of finding tags. Return a pair of dicts |
405 (tags, tagtypes) where tags maps tag name to node, and tagtypes | 413 (tags, tagtypes) where tags maps tag name to node, and tagtypes |
406 maps tag name to a string like \'global\' or \'local\'. | 414 maps tag name to a string like \'global\' or \'local\'. |
425 # writing to the cache), but the rest of Mercurial wants them in | 433 # writing to the cache), but the rest of Mercurial wants them in |
426 # local encoding. | 434 # local encoding. |
427 tags = {} | 435 tags = {} |
428 for (name, (node, hist)) in alltags.iteritems(): | 436 for (name, (node, hist)) in alltags.iteritems(): |
429 if node != nullid: | 437 if node != nullid: |
430 try: | 438 tags[encoding.tolocal(name)] = node |
431 # ignore tags to unknown nodes | |
432 self.changelog.lookup(node) | |
433 tags[encoding.tolocal(name)] = node | |
434 except error.LookupError: | |
435 pass | |
436 tags['tip'] = self.changelog.tip() | 439 tags['tip'] = self.changelog.tip() |
437 tagtypes = dict([(encoding.tolocal(name), value) | 440 tagtypes = dict([(encoding.tolocal(name), value) |
438 for (name, value) in tagtypes.iteritems()]) | 441 for (name, value) in tagtypes.iteritems()]) |
439 return (tags, tagtypes) | 442 return (tags, tagtypes) |
440 | 443 |
462 | 465 |
463 def nodetags(self, node): | 466 def nodetags(self, node): |
464 '''return the tags associated with a node''' | 467 '''return the tags associated with a node''' |
465 if not self._tagscache.nodetagscache: | 468 if not self._tagscache.nodetagscache: |
466 nodetagscache = {} | 469 nodetagscache = {} |
467 for t, n in self.tags().iteritems(): | 470 for t, n in self._tagscache.tags.iteritems(): |
468 nodetagscache.setdefault(n, []).append(t) | 471 nodetagscache.setdefault(n, []).append(t) |
469 for tags in nodetagscache.itervalues(): | 472 for tags in nodetagscache.itervalues(): |
470 tags.sort() | 473 tags.sort() |
471 self._tagscache.nodetagscache = nodetagscache | 474 self._tagscache.nodetagscache = nodetagscache |
472 return self._tagscache.nodetagscache.get(node, []) | 475 return self._tagscache.nodetagscache.get(node, []) |