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-----
--- a/mercurial/commands.py Wed Jun 15 00:03:25 2005 -0800
+++ b/mercurial/commands.py Wed Jun 15 00:08:03 2005 -0800
@@ -126,18 +126,6 @@
ui.status("summary: %s\n" % description[0])
ui.status("\n")
-def tags_load(repo):
- repo.lookup(0) # prime the cache
- i = repo.tags.items()
- n = []
- for e in i:
- try:
- l = repo.changelog.rev(e[1])
- except KeyError:
- l = -2
- n.append((l, e))
- return n
-
def help(ui, cmd=None):
'''show help for a given command or all commands'''
if cmd:
@@ -328,17 +316,15 @@
"""print information about the working copy"""
(c, a, d, u) = repo.diffdir(repo.root)
mflag = (c or a or d or u) and "+" or ""
- parents = [parent for parent in repo.dirstate.parents()
- if parent != hg.nullid]
+ parents = [p for p in repo.dirstate.parents() if p != hg.nullid]
if not parents:
- ui.note("unknown\n")
+ ui.write("unknown\n")
return
tstring = ''
if not ui.quiet:
- taglist = [e[1] for e in tags_load(repo)]
- tstring = " %s" % ' + '.join([e[0] for e in taglist
- if e[0] != 'tip' and e[1] in parents])
+ tags = sum(map(repo.nodetags, parents), [])
+ tstring = " " + ' + '.join(tags)
hexfunc = ui.verbose and hg.hex or hg.short
pstring = '+'.join([hexfunc(parent) for parent in parents])
@@ -544,17 +530,15 @@
def tags(ui, repo):
"""list repository tags"""
- n = tags_load(repo)
-
- n.sort()
- n.reverse()
- i = [ e[1] for e in n ]
- for k, n in i:
+
+ l = repo.tagslist()
+ l.reverse()
+ for t,n in l:
try:
r = repo.changelog.rev(n)
except KeyError:
r = "?"
- print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n))
+ print "%-30s %5d:%s" % (t, repo.changelog.rev(n), hg.hex(n))
def tip(ui, repo):
"""show the tip revision"""
--- a/mercurial/hg.py Wed Jun 15 00:03:25 2005 -0800
+++ b/mercurial/hg.py Wed Jun 15 00:08:03 2005 -0800
@@ -334,7 +334,8 @@
self.manifest = manifest(self.opener)
self.changelog = changelog(self.opener)
self.ignorelist = None
- self.tags = None
+ self.tagscache = None
+ self.nodetagscache = None
if not self.remote:
self.dirstate = dirstate(self.opener, ui, self.root)
@@ -355,9 +356,10 @@
if pat.search(f): return True
return False
- def lookup(self, key):
- if self.tags is None:
- self.tags = {}
+ def tags(self):
+ '''return a mapping of tag to node'''
+ if not self.tagscache:
+ self.tagscache = {}
try:
# read each head of the tags file, ending with the tip
# and add each tag found to the map, with "newer" ones
@@ -369,11 +371,35 @@
for l in fl.revision(r).splitlines():
if l:
n, k = l.split(" ")
- self.tags[k] = bin(n)
+ self.tagscache[k] = bin(n)
except KeyError: pass
- self.tags['tip'] = self.changelog.tip()
+ self.tagscache['tip'] = self.changelog.tip()
+
+ return self.tagscache
+
+ def tagslist(self):
+ '''return a list of tags ordered by revision'''
+ l = []
+ for t,n in self.tags().items():
+ try:
+ r = self.changelog.rev(n)
+ except:
+ r = -2 # sort to the beginning of the list if unknown
+ l.append((r,t,n))
+ l.sort()
+ return [(t,n) for r,t,n in l]
+
+ def nodetags(self, node):
+ '''return the tags associated with a node'''
+ if not self.nodetagscache:
+ self.nodetagscache = {}
+ for t,n in self.tags().items():
+ self.nodetagscache.setdefault(n,[]).append(t)
+ return self.nodetagscache.get(node, [])
+
+ def lookup(self, key):
try:
- return self.tags[key]
+ return self.tags()[key]
except KeyError:
return self.changelog.lookup(key)
--- a/mercurial/hgweb.py Wed Jun 15 00:03:25 2005 -0800
+++ b/mercurial/hgweb.py Wed Jun 15 00:08:03 2005 -0800
@@ -523,12 +523,8 @@
cl = self.repo.changelog
mf = cl.read(cl.tip())[0]
- self.repo.lookup(0) # prime the cache
- i = self.repo.tags.items()
- n = [ (cl.rev(e[1]), e) for e in i ] # sort by revision
- n.sort()
- n.reverse()
- i = [ e[1] for e in n ]
+ i = self.repo.tagslist()
+ i.reverse()
def entries():
parity = 0