comparison mercurial/hg.py @ 343:d7df759d0e97

rework all code using tags -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 rework all code using tags Add three utility functions: tags(): get (and possibly load) the tags mapping tagslist(): sort tag,node by revision (aka topologically) nodetags(): return a list of tags associated with a node (also cached) Update all the code using tags to use these. Simplify identify code make unknown always visible if printed don't ignore tip pseudo-tag manifest hash: e6deb4d545ad465be7735f9ec43227bcb5e238c7 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCr+HjywK+sNU5EO8RAh4/AJ90cI0WxmvQAj6Lq2ZiG8LmqZan/QCfR8B5 ltu8tOIEHDa8LhfS9wtBu0k= =pv3t -----END PGP SIGNATURE-----
author mpm@selenic.com
date Wed, 15 Jun 2005 00:08:03 -0800
parents c3d873ef4b31
children db419f14df4b
comparison
equal deleted inserted replaced
342:f7c51058cbb7 343:d7df759d0e97
332 self.opener = opener(self.path) 332 self.opener = opener(self.path)
333 self.wopener = opener(self.root) 333 self.wopener = opener(self.root)
334 self.manifest = manifest(self.opener) 334 self.manifest = manifest(self.opener)
335 self.changelog = changelog(self.opener) 335 self.changelog = changelog(self.opener)
336 self.ignorelist = None 336 self.ignorelist = None
337 self.tags = None 337 self.tagscache = None
338 self.nodetagscache = None
338 339
339 if not self.remote: 340 if not self.remote:
340 self.dirstate = dirstate(self.opener, ui, self.root) 341 self.dirstate = dirstate(self.opener, ui, self.root)
341 try: 342 try:
342 self.ui.readconfig(self.opener("hgrc")) 343 self.ui.readconfig(self.opener("hgrc"))
353 except IOError: pass 354 except IOError: pass
354 for pat in self.ignorelist: 355 for pat in self.ignorelist:
355 if pat.search(f): return True 356 if pat.search(f): return True
356 return False 357 return False
357 358
358 def lookup(self, key): 359 def tags(self):
359 if self.tags is None: 360 '''return a mapping of tag to node'''
360 self.tags = {} 361 if not self.tagscache:
362 self.tagscache = {}
361 try: 363 try:
362 # read each head of the tags file, ending with the tip 364 # read each head of the tags file, ending with the tip
363 # and add each tag found to the map, with "newer" ones 365 # and add each tag found to the map, with "newer" ones
364 # taking precedence 366 # taking precedence
365 fl = self.file(".hgtags") 367 fl = self.file(".hgtags")
367 h.reverse() 369 h.reverse()
368 for r in h: 370 for r in h:
369 for l in fl.revision(r).splitlines(): 371 for l in fl.revision(r).splitlines():
370 if l: 372 if l:
371 n, k = l.split(" ") 373 n, k = l.split(" ")
372 self.tags[k] = bin(n) 374 self.tagscache[k] = bin(n)
373 except KeyError: pass 375 except KeyError: pass
374 self.tags['tip'] = self.changelog.tip() 376 self.tagscache['tip'] = self.changelog.tip()
377
378 return self.tagscache
379
380 def tagslist(self):
381 '''return a list of tags ordered by revision'''
382 l = []
383 for t,n in self.tags().items():
384 try:
385 r = self.changelog.rev(n)
386 except:
387 r = -2 # sort to the beginning of the list if unknown
388 l.append((r,t,n))
389 l.sort()
390 return [(t,n) for r,t,n in l]
391
392 def nodetags(self, node):
393 '''return the tags associated with a node'''
394 if not self.nodetagscache:
395 self.nodetagscache = {}
396 for t,n in self.tags().items():
397 self.nodetagscache.setdefault(n,[]).append(t)
398 return self.nodetagscache.get(node, [])
399
400 def lookup(self, key):
375 try: 401 try:
376 return self.tags[key] 402 return self.tags()[key]
377 except KeyError: 403 except KeyError:
378 return self.changelog.lookup(key) 404 return self.changelog.lookup(key)
379 405
380 def join(self, f): 406 def join(self, f):
381 return os.path.join(self.path, f) 407 return os.path.join(self.path, f)