##// END OF EJS Templates
localrepo: unify tag related info into a tagscache class
Idan Kamara -
r14936:9dca7653 default
parent child Browse files
Show More
@@ -97,17 +97,9 b' class localrepository(repo.repository):'
97 97 if create:
98 98 self._writerequirements()
99 99
100 # These two define the set of tags for this repository. _tags
101 # maps tag name to node; _tagtypes maps tag name to 'global' or
102 # 'local'. (Global tags are defined by .hgtags across all
103 # heads, and local tags are defined in .hg/localtags.) They
104 # constitute the in-memory cache of tags.
105 self._tags = None
106 self._tagtypes = None
107 100
108 101 self._branchcache = None
109 102 self._branchcachetip = None
110 self.nodetagscache = None
111 103 self.filterpats = {}
112 104 self._datafilters = {}
113 105 self._transref = self._lockref = self._wlockref = None
@@ -268,8 +260,8 b' class localrepository(repo.repository):'
268 260 fp.write('\n')
269 261 for name in names:
270 262 m = munge and munge(name) or name
271 if self._tagtypes and name in self._tagtypes:
272 old = self._tags.get(name, nullid)
263 if self._tagscache.tagtypes and name in self._tagscache.tagtypes:
264 old = self.tags().get(name, nullid)
273 265 fp.write('%s %s\n' % (hex(old), m))
274 266 fp.write('%s %s\n' % (hex(node), m))
275 267 fp.close()
@@ -344,12 +336,31 b' class localrepository(repo.repository):'
344 336 self.tags() # instantiate the cache
345 337 self._tag(names, node, message, local, user, date)
346 338
339 @propertycache
340 def _tagscache(self):
341 '''Returns a tagscache object that contains various tags related caches.'''
342
343 # This simplifies its cache management by having one decorated
344 # function (this one) and the rest simply fetch things from it.
345 class tagscache(object):
346 def __init__(self):
347 # These two define the set of tags for this repository. tags
348 # maps tag name to node; tagtypes maps tag name to 'global' or
349 # 'local'. (Global tags are defined by .hgtags across all
350 # heads, and local tags are defined in .hg/localtags.)
351 # They constitute the in-memory cache of tags.
352 self.tags = self.tagtypes = None
353
354 self.nodetagscache = self.tagslist = None
355
356 cache = tagscache()
357 cache.tags, cache.tagtypes = self._findtags()
358
359 return cache
360
347 361 def tags(self):
348 362 '''return a mapping of tag to node'''
349 if self._tags is None:
350 (self._tags, self._tagtypes) = self._findtags()
351
352 return self._tags
363 return self._tagscache.tags
353 364
354 365 def _findtags(self):
355 366 '''Do the hard work of finding tags. Return a pair of dicts
@@ -398,27 +409,29 b' class localrepository(repo.repository):'
398 409 None : tag does not exist
399 410 '''
400 411
401 self.tags()
402
403 return self._tagtypes.get(tagname)
412 return self._tagscache.tagtypes.get(tagname)
404 413
405 414 def tagslist(self):
406 415 '''return a list of tags ordered by revision'''
407 l = []
408 for t, n in self.tags().iteritems():
409 r = self.changelog.rev(n)
410 l.append((r, t, n))
411 return [(t, n) for r, t, n in sorted(l)]
416 if not self._tagscache.tagslist:
417 l = []
418 for t, n in self.tags().iteritems():
419 r = self.changelog.rev(n)
420 l.append((r, t, n))
421 self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)]
422
423 return self._tagscache.tagslist
412 424
413 425 def nodetags(self, node):
414 426 '''return the tags associated with a node'''
415 if not self.nodetagscache:
416 self.nodetagscache = {}
427 if not self._tagscache.nodetagscache:
428 nodetagscache = {}
417 429 for t, n in self.tags().iteritems():
418 self.nodetagscache.setdefault(n, []).append(t)
419 for tags in self.nodetagscache.itervalues():
430 nodetagscache.setdefault(n, []).append(t)
431 for tags in nodetagscache.itervalues():
420 432 tags.sort()
421 return self.nodetagscache.get(node, [])
433 self._tagscache.nodetagscache = nodetagscache
434 return self._tagscache.nodetagscache.get(node, [])
422 435
423 436 def nodebookmarks(self, node):
424 437 marks = []
@@ -792,9 +805,11 b' class localrepository(repo.repository):'
792 805 release(lock, wlock)
793 806
794 807 def invalidatecaches(self):
795 self._tags = None
796 self._tagtypes = None
797 self.nodetagscache = None
808 try:
809 delattr(self, '_tagscache')
810 except AttributeError:
811 pass
812
798 813 self._branchcache = None # in UTF-8
799 814 self._branchcachetip = None
800 815
General Comments 0
You need to be logged in to leave comments. Login now