Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 9145:6b03f93b8ff3
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.
author | Greg Ward <greg-hg@gerg.ca> |
---|---|
date | Thu, 16 Jul 2009 10:39:41 -0400 |
parents | a5c060b80082 |
children | 5614a628d173 |
comparison
equal
deleted
inserted
replaced
9144:ad72e3b08bc0 | 9145:6b03f93b8ff3 |
---|---|
231 self.tags() # instantiate the cache | 231 self.tags() # instantiate the cache |
232 self._tag(names, node, message, local, user, date) | 232 self._tag(names, node, message, local, user, date) |
233 | 233 |
234 def tags(self): | 234 def tags(self): |
235 '''return a mapping of tag to node''' | 235 '''return a mapping of tag to node''' |
236 if self.tagscache: | 236 if self.tagscache is None: |
237 return self.tagscache | 237 (self.tagscache, self._tagstypecache) = self._findtags() |
238 | |
239 return self.tagscache | |
240 | |
241 def _findtags(self): | |
242 '''Do the hard work of finding tags. Return a pair of dicts | |
243 (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
244 maps tag name to a string like \'global\' or \'local\'. | |
245 Subclasses or extensions are free to add their own tags, but | |
246 should be aware that the returned dicts will be retained for the | |
247 duration of the localrepo object.''' | |
248 | |
249 # XXX what tagtype should subclasses/extensions use? Currently | |
250 # mq and bookmarks add tags, but do not set the tagtype at all. | |
251 # Should each extension invent its own tag type? Should there | |
252 # be one tagtype for all such "virtual" tags? Or is the status | |
253 # quo fine? | |
238 | 254 |
239 globaltags = {} | 255 globaltags = {} |
240 tagtypes = {} | 256 tagtypes = {} |
241 | 257 |
242 def readtags(lines, fn, tagtype): | 258 def readtags(lines, fn, tagtype): |
316 # while the internal tag table is stored in UTF-8 | 332 # while the internal tag table is stored in UTF-8 |
317 readtags(data.splitlines(), "localtags", "local") | 333 readtags(data.splitlines(), "localtags", "local") |
318 except IOError: | 334 except IOError: |
319 pass | 335 pass |
320 | 336 |
321 self.tagscache = {} | 337 tags = {} |
322 self._tagstypecache = {} | |
323 for k, nh in globaltags.iteritems(): | 338 for k, nh in globaltags.iteritems(): |
324 n = nh[0] | 339 n = nh[0] |
325 if n != nullid: | 340 if n != nullid: |
326 self.tagscache[k] = n | 341 tags[k] = n |
327 self._tagstypecache[k] = tagtypes[k] | 342 tags['tip'] = self.changelog.tip() |
328 self.tagscache['tip'] = self.changelog.tip() | 343 return (tags, tagtypes) |
329 return self.tagscache | |
330 | 344 |
331 def tagtype(self, tagname): | 345 def tagtype(self, tagname): |
332 ''' | 346 ''' |
333 return the type of the given tag. result can be: | 347 return the type of the given tag. result can be: |
334 | 348 |