changeset 67:a182f2561c8e

Add tag support
author mpm@selenic.com
date Fri, 13 May 2005 13:12:32 -0800
parents 5ec8b2ed858f
children 6fa994fe90fc db5eb6a86179
files README hg mercurial/hg.py mercurial/revlog.py setup.py
diffstat 5 files changed, 37 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/README
+++ b/README
@@ -37,6 +37,7 @@ Mercurial commands:
  $ hg add foo          # add a new file for the next commit
  $ hg remove bar       # mark a file as removed
  $ hg verify           # check repo integrity
+ $ hg tags             # show current tags
 
 Branching and merging:
 
@@ -93,7 +94,6 @@ Network support:
  # merge changes from a remote machine
  bar$ hg merge hg://foo/~user/hg-linux
 
-
  Another approach which does perform well right now is to use rsync.
  Simply rsync the remote repo to a read-only local copy and then do a
  local pull.
--- a/hg
+++ b/hg
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #
 # mercurial - a minimal scalable distributed SCM
-# v0.4e "sabina"
+# v0.4f "jane dark"
 #
 # Copyright 2005 Matt Mackall <mpm@selenic.com>
 #
@@ -37,6 +37,7 @@ def help():
  dump <file> [rev]     dump the latest or given revision of a file
  dumpmanifest [rev]    dump the latest or given revision of the manifest
  diff [files...]       diff working directory (or selected files)
+ tags                  show current changeset tags
 """
 
 def filterfiles(list, files):
@@ -118,7 +119,7 @@ else:
 if cmd == "checkout" or cmd == "co":
     node = repo.changelog.tip()
     if args:
-        node = repo.changelog.lookup(args[0])
+        node = repo.lookup(args[0])
     repo.checkout(node)
 
 elif cmd == "add":
@@ -177,7 +178,7 @@ elif cmd == "diff":
         opts = [('r', 'revision', [], 'revision')]
         args = fancyopts.fancyopts(args, opts, doptions,
                                    'hg diff [options] [files]')
-        revs = map(lambda x: repo.changelog.lookup(x), doptions['revision'])
+        revs = map(lambda x: repo.lookup(x), doptions['revision'])
     
     if len(revs) > 2:
         print "too many revisions to diff"
@@ -191,12 +192,12 @@ elif cmd == "diff":
     diff(args, *revs)
 
 elif cmd == "export":
-    node = repo.changelog.lookup(args[0])
+    node = repo.lookup(args[0])
     prev = repo.changelog.parents(node)[0]
     diff(None, prev, node)
 
 elif cmd == "debugchangegroup":
-    newer = repo.newer(map(repo.changelog.lookup, args))
+    newer = repo.newer(map(repo.lookup, args))
     for chunk in repo.changegroup(newer):
         sys.stdout.write(chunk)
 
@@ -288,6 +289,17 @@ elif cmd == "merge":
     else:
         print "missing source repository"
 
+elif cmd == "tags":
+    repo.lookup(0) # prime the cache
+    i = repo.tags.items()
+    i.sort()
+    for k, n in i:
+        try:
+            r = repo.changelog.rev(n)
+        except KeyError:
+            r = "?"
+        print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n))
+
 elif cmd == "debugoldmerge":
     if args:
         other = hg.repository(ui, args[0])
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -258,6 +258,7 @@ class localrepository:
         self.manifest = manifest(self.opener)
         self.changelog = changelog(self.opener)
         self.ignorelist = None
+        self.tags = None
 
         if not self.remote:
             self.dircache = dircache(self.opener, ui)
@@ -274,7 +275,7 @@ class localrepository:
         if self.ignorelist is None:
             self.ignorelist = []
             try:
-                l = open(os.path.join(self.root, ".hgignore")).readlines()
+                l = open(os.path.join(self.root, ".hgignore"))
                 for pat in l:
                     if pat != "\n":
                         self.ignorelist.append(re.compile(pat[:-1]))
@@ -283,6 +284,21 @@ class localrepository:
             if pat.search(f): return True
         return False
 
+    def lookup(self, key):
+        if self.tags is None:
+            self.tags = {}
+            try:
+                fl = self.file(".hgtags")
+                for l in fl.revision(fl.tip()).splitlines():
+                    if l:
+                        n, k = l.split(" ")
+                        self.tags[k] = bin(n)
+            except KeyError: pass
+        try:
+            return self.tags[key]
+        except KeyError:
+            return self.changelog.lookup(key)
+
     def join(self, f):
         return os.path.join(self.path, f)
 
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -73,7 +73,7 @@ class revlog:
                 if id in hex(n):
                     c.append(n)
             if len(c) > 1: raise KeyError("Ambiguous identifier")
-            if len(c) < 1: raise KeyError
+            if len(c) < 1: raise KeyError("No match found")
             return c[0]
                 
         return None
--- a/setup.py
+++ b/setup.py
@@ -8,7 +8,7 @@
 from distutils.core import setup
 
 setup(name='mercurial',
-            version='0.4e',
+            version='0.4f',
             author='Matt Mackall',
             author_email='mpm@selenic.com',
             url='http://selenic.com/mercurial',