]> thyrsus.com Git - src.git/commitdiff
Break rename out into its own command. Regression tests pass.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 16 Nov 2014 14:14:24 +0000 (09:14 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 16 Nov 2014 14:15:10 +0000 (09:15 -0500)
NEWS
src
src.asc
srctest

diff --git a/NEWS b/NEWS
index d6021ef1d969b654bbb86d4375edd6199dd34be2..0038b2f9ba8d39e7abfe97242398396b783e4bf9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,8 @@
                        src project news
 
 Repository head:
-   Branch deletion is imple,ented and tested.
+   Branch deletion is implemented and tested.
+   'src rename' now renames tags and branches - no longer an alias for 'move'.
    SRC is now feature-complete as planned. Not all documentation is in place.
 
 0.8: 2014-11-14
diff --git a/src b/src
index bf5cda3592b0b507a81c781cbf6e508ce1beef68..9bccee523dc936f5cfddcff9a08d66ff02fcfc0d 100755 (executable)
--- a/src
+++ b/src
@@ -275,7 +275,7 @@ fast-export -- the fast-export command: export history to other systems.
 fast-import -- the fast-import command: import history from other systems.
 ignores     -- .srcignore files and their uses.
 
-The 'help', 'ls', 'move', 'copy', and 'version' commands are
+The 'help', 'rename', 'ls', 'move', 'copy', and 'version' commands are
 completely described in the command summary.
 """,
     "intro": """
@@ -372,14 +372,18 @@ src status [-a] ['file'...]
    tracked, I = ignored, L = locked (recover with src checkout).
    Find more details under 'help status'. 'st' is a synonym fot status.
 
-src tag [list|-l|delete|del|-d|rename|-r] ['name'] ['revision'] ['file'...] 
-   Create, rename, or delete a tag. With no or only file arguments, list tags.
+src tag [list|-l|delete|del|-d] ['name'] ['revision'] ['file'...] 
+   Create or delete a tag. With no or only file arguments, list tags.
 
-src branch [list|-l|delete|del|-d|rename|-r] ['name'] ['revision'] ['file'...]
-   Create, rename, switch to, or delete a branch. With no arguments,
+src branch [list|-l|delete|del|-d] ['name'] ['revision'] ['file'...]
+   Create, switch to, or delete a branch. With no arguments,
    list branches; the active branch is first in the list. The default
    branch is 'trunk'.
 
+src rename ['tag'|'branch'] ['oldname'] ['newname']  ['file'...]
+   Rename a tag or branch. Refuses to step on an existing symbol or
+   rename a nonexistent one.  'rn' is a synonym for 'rename'.
+
 src list ['revision-range'] ['file'...]
    Sends summary information about the specified commits to standard output.
    The summary line tagged with '*' is the state that the file would
@@ -399,7 +403,7 @@ src ls
 
 src move 'old' 'new'
    Rename a workfile and its history. Refuses to step on existing
-   workfiles or histories.  'mv' and 'rename' are synonyms.
+   workfiles or histories.  'mv' is a synonym for 'move'.
 
 src copy 'old' 'new'
    Copy a workfile and its history. Refuses to step on existing files
@@ -1161,33 +1165,6 @@ def tag_helper(args, legend, validation_hook, delete_method, set_method):
                     if backend.isbranch(value) == (legend == "branch"):
                         sys.stdout.write("%4s\t%s\n" % (display,key))
             return
-        if args[0] in ("-r", "rename"):
-            args.pop(0)
-            if not args:
-                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)
-            ctx = CommandContext(legend + " renaming", args, require_empty=True)
-            for arg in ctx.args:
-                metadata = History(arg)
-                if name not in metadata.symbols:
-                    croak("in %s, cannot rename nonexistent %s %s" % (arg, legend, name))
-                if newname in metadata.symbols:
-                    croak("in %s, cannot rename to existing %s %s" % (arg, 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)
-                    backend.delete_tag(name, metadata)
-                if not quiet and len(args) > 1:
-                    announce("in %s, %s -> %s" % (arg, name, newname))
-            return
     if not args:
         croak("%s setting requires a name argument" % legend)
     name = args.pop(0)
@@ -1224,6 +1201,37 @@ def branch_method(*args):
                branch_set_validate,
                backend.delete_branch, backend.set_branch)
 
+def rename_method(*args):
+    "Rename a branch or tag."
+    args = list(args)
+    if not args or args[0] not in ("tag", "branch"):
+        croak("rename requires a following 'tag' or 'branch'")
+    legend = args.pop(0)
+    if not args:
+         croak("rename requires a source name argument")
+    name = args.pop(0)
+    if not args:
+        croak("rename requires a target name argument")
+    newname = args.pop(0)
+    ctx = CommandContext(legend + " renaming", args, require_empty=True)
+    for arg in ctx.args:
+        metadata = History(arg)
+        if name not in metadata.symbols:
+            croak("in %s, cannot rename nonexistent %s %s" % (arg, legend, name))
+        if newname in metadata.symbols:
+            croak("in %s, cannot rename to existing %s %s" % (arg, 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)
+            backend.delete_tag(name, metadata)
+        if not quiet and len(args) > 1:
+            announce("in %s, %s -> %s" % (arg, name, newname))
+
 def filecmd(legend, hook, args):
     CommandContext(legend, args, require_empty=True)
     if len(args) != 2:
@@ -1372,10 +1380,11 @@ dispatch = {
     "di":          diff_method,
     "tag":         tag_method,
     "branch":      branch_method,
+    "rn":          rename_method,
+    "rename":      rename_method,
     "ls":          ls_method,
     "move":        move_method,
     "mv":          move_method,
-    "rename":      move_method,
     "copy":        copy_method,
     "cp":          copy_method,
     "fast-export": fast_export_method,
diff --git a/src.asc b/src.asc
index 6d2d6e831dad58ace2c59fe341408bd1bc70e69f..bb1e8642997dcb2e23ef8c1834c77705d0922d26 100644 (file)
--- a/src.asc
+++ b/src.asc
@@ -79,14 +79,18 @@ src status [-a] ['file'...]::
    give the -a switch or specify which files to look at. "st" is a
    synonym for status.
 
-src tag [list|-ldelete|del|-d}rename|-r] ['name'] ['revision'] ['file'...]::
-   Create, rename, or delete a tag. With no or only file arguments, list tags.
+src tag [list|-l|delete|del|-d] ['name'] ['revision'] ['file'...]::
+   Create or delete a tag. With no or only file arguments, list tags.
 
-src branch [list|-l|delete|del|-d] ['name'] ['revision'] ['file...']::
-   Create, rename, switch to, or delete a branch. With no arguments,
+src branch [list|-l|delete|del|-d] ['name'] ['revision'] ['file'...]::
+   Create, switch to, or delete a branch. With no arguments,
    list branches; the active branch is first in the list. The default
    branch is 'trunk'.
 
+src rename ['tag'|'branch'] ['oldname'] ['newname']  ['file'...]::
+   Rename a tag or branch. Refuses to step on an existing symbol or
+   rename a nonexistent one.  'rn' is a synonym for 'rename'.
+
 src list ['revision-range'] ['file'...]::
    Sends summary information about the specified commits to standard output.
    The summary line tagged with '*' is the state that the file would
@@ -106,9 +110,9 @@ src diff ['revision-range'] ['file'...]::
 src ls::
    List all registered files.
 
-src rename 'old' 'new'::
+src move 'old' 'new'::
    Rename a workfile and its history. Refuses to step on existing
-   workfiles or histories. 'mv' and 'rename' are synonyms.
+   workfiles or histories. 'mv' is a synonym for 'move'.
 
 src copy 'old' 'new'::
    Copy a file and its master. Refuses to step on existing files or masters.
diff --git a/srctest b/srctest
index 5099841f7564d7cd517b36a807c113d2d7e3b989..15bf44b44572498e364a26ddc3556832814b02ec 100755 (executable)
--- a/srctest
+++ b/srctest
@@ -188,7 +188,7 @@ rm -fr foo
 grep jrh testfile15 >/dev/null
 check "fast-export content check"
 
-src $TESTOPTS rename testfile1 newname1
+src $TESTOPTS move testfile1 newname1
 check "move command"
 if [ -e newname1 -a -e .src/newname1,v ]
 then
@@ -518,7 +518,7 @@ src $TESTOPTS list @GLARB sample >tryit
 diff -u tryit sample.taglog
 check "named-tag lookup with @"
 
-src $TESTOPTS tag -r GLARB GROTTY sample
+src $TESTOPTS rename tag GLARB GROTTY sample
 check "tag renaming"
 
 cat >changes <<EOF