# HG changeset patch # User Greg Ward # Date 2009-07-16 14:39:41 # Node ID 6b03f93b8ff3007022ae3d3eff6ed2dcc10204fd # Parent ad72e3b08bc09e894b13b1a31f83b755c4fcaacf localrepo: factor _findtags() out of tags() (issue548). This makes in-memory caching the sole responsibility of localrepo, eliminating some localrepo code that was duplicated in mq and bookmarks. diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py --- a/hgext/bookmarks.py +++ b/hgext/bookmarks.py @@ -293,14 +293,11 @@ def reposetup(ui, repo): write(self, marks) return result - def tags(self): + def _findtags(self): """Merge bookmarks with normal tags""" - if self.tagscache: - return self.tagscache - - tagscache = super(bookmark_repo, self).tags() - tagscache.update(parse(self)) - return tagscache + (tags, tagtypes) = super(bookmark_repo, self)._findtags() + tags.update(parse(self)) + return (tags, tagtypes) repo.__class__ = bookmark_repo diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -2415,34 +2415,33 @@ def reposetup(ui, repo): raise util.Abort(_('source has mq patches applied')) return super(mqrepo, self).push(remote, force, revs) - def tags(self): - if self.tagscache: - return self.tagscache - - tagscache = super(mqrepo, self).tags() + def _findtags(self): + '''augment tags from base class with patch tags''' + result = super(mqrepo, self)._findtags() q = self.mq if not q.applied: - return tagscache + return result mqtags = [(bin(patch.rev), patch.name) for patch in q.applied] if mqtags[-1][0] not in self.changelog.nodemap: self.ui.warn(_('mq status file refers to unknown node %s\n') % short(mqtags[-1][0])) - return tagscache + return result mqtags.append((mqtags[-1][0], 'qtip')) mqtags.append((mqtags[0][0], 'qbase')) mqtags.append((self.changelog.parents(mqtags[0][0])[0], 'qparent')) + tags = result[0] for patch in mqtags: - if patch[1] in tagscache: + if patch[1] in tags: self.ui.warn(_('Tag %s overrides mq patch of the same name\n') % patch[1]) else: - tagscache[patch[1]] = patch[0] + tags[patch[1]] = patch[0] - return tagscache + return result def _branchtags(self, partial, lrev): q = self.mq diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -233,8 +233,24 @@ class localrepository(repo.repository): def tags(self): '''return a mapping of tag to node''' - if self.tagscache: - return self.tagscache + if self.tagscache is None: + (self.tagscache, self._tagstypecache) = self._findtags() + + return self.tagscache + + def _findtags(self): + '''Do the hard work of finding tags. Return a pair of dicts + (tags, tagtypes) where tags maps tag name to node, and tagtypes + maps tag name to a string like \'global\' or \'local\'. + Subclasses or extensions are free to add their own tags, but + should be aware that the returned dicts will be retained for the + duration of the localrepo object.''' + + # XXX what tagtype should subclasses/extensions use? Currently + # mq and bookmarks add tags, but do not set the tagtype at all. + # Should each extension invent its own tag type? Should there + # be one tagtype for all such "virtual" tags? Or is the status + # quo fine? globaltags = {} tagtypes = {} @@ -318,15 +334,13 @@ class localrepository(repo.repository): except IOError: pass - self.tagscache = {} - self._tagstypecache = {} + tags = {} for k, nh in globaltags.iteritems(): n = nh[0] if n != nullid: - self.tagscache[k] = n - self._tagstypecache[k] = tagtypes[k] - self.tagscache['tip'] = self.changelog.tip() - return self.tagscache + tags[k] = n + tags['tip'] = self.changelog.tip() + return (tags, tagtypes) def tagtype(self, tagname): '''