]> thyrsus.com Git - src.git/commitdiff
Tag renaming works and has a test. All tests pass.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 12 Nov 2014 22:05:08 +0000 (17:05 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 12 Nov 2014 22:05:08 +0000 (17:05 -0500)
NEWS
src
srctest

diff --git a/NEWS b/NEWS
index aab389f6e0c0e946df91a5bd592f9995f917065e..4605b3b0c44ad6045a74ae81f546c479a60db347 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,7 @@
 `                      src project news
 
 Repository head:
-   Tag names for revisions work.
+   Tag names for revisions work; so does tag renaming.
    Branch-sensitive traversal with .. is working.
    Fixed yet another fast-export bug.
 
diff --git a/src b/src
index 759fe0d0c9ca8f39c199d7dc623384db9d68beb6..97ad9f6c09f826d865f2a97eeebfc85ea97bed20 100755 (executable)
--- a/src
+++ b/src
@@ -752,9 +752,7 @@ def tag_helper(args, legend, validation_hook, delete_method, set_method):
                 return
         if args[0] in ("-l", "list"):
             args.pop(0)
-            ctx = CommandContext(legend, args)
-            if not ctx.is_empty():
-                croak("can't accept a revision-spec when %s listing." % legend)
+            ctx = CommandContext(legend + " listing", args, require_empty=True)
             width = screenwidth()
             for arg in ctx.args:
                 metadata = History(arg)
@@ -773,20 +771,31 @@ def tag_helper(args, legend, validation_hook, delete_method, set_method):
             return
         if args[0] in ("-r", "rename"):
             args.pop(0)
-            if name not in metadata.symbols:
-                croak("cannot rename nonexistent %s" % legend)
             if not args:
-                croak("rename requires a second name argement")
+                croak("rename requires a source name argement")
+            name = args.pop(0)
+            if not args:
+                croak("rename requires a target name argement")
             newname = args.pop(0)
-            if newname in metadata.symbols:
-                croak("cannot rename to existing %s" % legend)
-            ctx = CommandContext(legend, args)
-            if not ctx.is_empty():
-                croak("can't accept a revision-spec when %s renaming." % legend)
-            # In the case of a branch, we want to change only the tag reference.
+            ctx = CommandContext(legend + " renaming", args, require_empty=True)
             for arg in ctx.args:
-                backend.set_tag(newname, metadata.symbols[name], metadata, arg)
-                backend.delete_tag(name, arg)
+                metadata = History(arg)
+                if name not in metadata.symbols:
+                    croak("cannot rename nonexistent %s %s" % (legend, name))
+                if newname in metadata.symbols:
+                    croak("cannot rename to existing %s %s" % (legend, name))
+                ctx = CommandContext(legend, args)
+                if not ctx.is_empty():
+                    croak("can't accept a revision-spec when renaming a %s." \
+                          % legend)
+                # In the case of a branch, we want to change only the
+                # tag reference.
+                with backend.lifter(arg):
+                    backend.set_tag(newname, metadata.symbols[name], metadata, arg)
+                    backend.delete_tag(name, arg)
+                if not quiet and len(args) > 1:
+                    announce("%s -> %s in %s" % (name, newname, arg))
+            return
     if not args:
         croak("%s setting requires a name argument" % legend)
     name = args.pop(0)
@@ -799,8 +808,7 @@ def tag_helper(args, legend, validation_hook, delete_method, set_method):
         with backend.lifter(arg):
             set_method(name, revision, metadata, arg)
             if not quiet and len(args) > 1:
-                announce("%s %s = %s in " % (legend, name, revno, arg))
-                pass
+                announce("%s %s = %s in %s" % (legend, name, revno, arg))
 
 def tag_method(*args):
     "Inspect, create, and delete tags."
diff --git a/srctest b/srctest
index 975ed02d34fda7a8fdb79eeab33d36febfaf2ceb..60252268aa599f031c656fc9ce78c3c33fc4de14 100755 (executable)
--- a/srctest
+++ b/srctest
@@ -440,6 +440,18 @@ src $TESTOPTS list @BLARGH sample >tryit
 diff -u tryit sample.taglog
 check "named-tag lookup with @"
 
+src $TESTOPTS tag -r BLARGH GROTTY sample
+check "tag renaming"
+
+cat >changes <<EOF
+= sample ====================================================================
+   8   GORP
+   4   GROTTY
+EOF
+
+src $TESTOPTS tag -l sample >tryit
+diff -u tryit changes
+check "tag list after rename"
 
 rm -fr $SANDBOX