]> arthur.barton.de Git - bup.git/commitdiff
tag-cmd: Some fixups
authorGabriel Filion <lelutin@gmail.com>
Thu, 2 Dec 2010 23:01:40 +0000 (18:01 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Mon, 3 Jan 2011 04:44:12 +0000 (20:44 -0800)
* Make some error messages nicer in telling the tag name that was used.

* Move tag listing code in git.py and use this code in tag-cmd and vfs.py

* Make tag-cmd output the list of tags on stdout instead of stderr

* Don't error out when more than 2 arguments are given. When there are less
  than 2, be nice and show the usage.

* In tag-cmd, catch GitErrors that come out of git.rev_parse()

Signed-off-by: Gabriel Filion <lelutin@gmail.com>
cmd/tag-cmd.py
lib/bup/git.py
lib/bup/vfs.py
t/test.sh

index 760dce7dd07c1b81d0c17bf4af6e44c81d51ce4c..ad01d6c5ac710dabf778876fb4921d32f01b4dc6 100755 (executable)
@@ -35,33 +35,35 @@ if opt.delete:
     try:
         os.unlink(tag_file)
     except OSError, e:
-        log("bup: error: unable to delete tag: %s" % e)
+        log("bup: error: unable to delete tag '%s': %s" % (opt.delete, e))
         sys.exit(1)
 
     sys.exit(0)
 
-tags = []
-for (t, dummy) in git.list_refs():
-    if t.startswith('refs/tags/'):
-        tags.append(t[10:])
+tags = [t for sublist in git.tags().values() for t in sublist]
 
 if not extra:
     for t in tags:
-        log("%s\n" % t)
+        print t
     sys.exit(0)
-elif len(extra) != 2:
-    log('bup: error: no ref or hash given.')
-    sys.exit(1)
+elif len(extra) < 2:
+    o.fatal('no commit ref or hash given.')
 
-tag_name = extra[0]
-commit = extra[1]
-debug1("from args: tag name = %s; commit = %s\n" % (tag_name, commit))
+(tag_name, commit) = extra[:2]
+if not tag_name:
+    o.fatal("tag name must not be empty.")
+debug1("args: tag name = %s; commit = %s\n" % (tag_name, commit))
 
 if tag_name in tags:
     log("bup: error: tag '%s' already exists" % tag_name)
     sys.exit(1)
 
-hash = git.rev_parse(commit)
+try:
+    hash = git.rev_parse(commit)
+except git.GitError, e:
+    log("bup: error: %s" % e)
+    sys.exit(2)
+
 if not hash:
     log("bup: error: commit %s not found." % commit)
     sys.exit(2)
@@ -75,7 +77,7 @@ tag_file = git.repo('refs/tags/%s' % tag_name)
 try:
     tag = file(tag_file, 'w')
 except OSError, e:
-    log('bup: error: could not create tag %s: %s' % (tag_name, e))
+    log("bup: error: could not create tag '%s': %s" % (tag_name, e))
     sys.exit(3)
 
 tag.write(hash.encode('hex'))
index 6a65c435450233702dea291113c417e423c0419f..e48bfd3ddfe5516b78723e7cb9feff1ce261c549 100644 (file)
@@ -140,7 +140,7 @@ def _decode_packobj(buf):
 class PackIdx:
     def __init__(self):
         assert(0)
-    
+
     def find_offset(self, hash):
         """Get the offset of an object inside the index file."""
         idx = self._idx_from_hash(hash)
@@ -1031,3 +1031,16 @@ class CatPipe:
                 yield d
         except StopIteration:
             log('booger!\n')
+
+def tags():
+    """Return a dictionary of all tags in the form {hash: [tag_names, ...]}."""
+    tags = {}
+    for (n,c) in list_refs():
+        if n.startswith('refs/tags/'):
+            name = n[10:]
+            if not c in tags:
+                tags[c] = []
+
+            tags[c].append(name)  # more than one tag can point at 'c'
+
+    return tags
index 9b7158f7a1a5b690c3d65e131ea52671a126c512..16a8d33b858999d05d37e74eeac947592d89fea0 100644 (file)
@@ -477,14 +477,7 @@ class BranchList(Node):
     def _mksubs(self):
         self._subs = {}
 
-        tags = {}
-        for (n,c) in git.list_refs():
-            if n.startswith('refs/tags/'):
-                name = n[10:]
-                if not c in tags:
-                    tags[c] = []
-
-                tags[c].append(name)
+        tags = git.tags()
 
         revs = list(git.rev_list(self.hash.encode('hex')))
         for (date, commit) in revs:
index 0c83ba7882b54911513194023c2379d3e7f43d91..f955dfab01b92d329e4e073bdfb715427e7129e0 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -208,9 +208,9 @@ WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)"
 WVSTART "tag"
 WVFAIL bup tag -d v0.n 2>/dev/null
 WVFAIL bup tag v0.n non-existant 2>/dev/null
-WVPASSEQ "$(bup tag 2>&1)" ""
+WVPASSEQ "$(bup tag)" ""
 WVPASS bup tag v0.1 master
-WVPASSEQ "$(bup tag 2>&1)" "v0.1"
+WVPASSEQ "$(bup tag)" "v0.1"
 WVPASS bup tag -d v0.1
 
 # This section destroys data in the bup repository, so it is done last.