]> thyrsus.com Git - src.git/commitdiff
Add src amend. Also seal gracefully with keyboard interrupts.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 10 Nov 2014 16:01:47 +0000 (11:01 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 10 Nov 2014 16:01:47 +0000 (11:01 -0500)
NEWS
src
src.asc
srctest

diff --git a/NEWS b/NEWS
index 4bf7238d80537d1204539cdd28681cdcafafc8ca..8079d554fac1c96bb3aa0d44a4f8ec74dd37e1bf 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@
 Repository head:
    Improvements to src fast-import.
    src commit now has an -e option to force editing after -m or -f.
+   There is now a "src amend".
 
 0.3: 2014-11-09
    There is now a "src status" command, and .srcignore affects it.
diff --git a/src b/src
index 8cb5ca743012bf036083f862cb9d0985fba884b5..037ca74e2806f08f6de11b6b360cd9ed31060fcd 100755 (executable)
--- a/src
+++ b/src
@@ -198,12 +198,16 @@ src add ['file'...]
    Initialize new project histories for specified files. Creates
    the repository directory if required.
 
-src commit [- | -m 'commentstring' | -f 'commentfile' | -e] ['file'...]
+src commit [- | -m 'string' | -f 'file' | -e] ['file'...]
    Enters a commit for specified files. Separately to each one.
    With '-', take comment text from stdin; with '-m' use the
    following string as the comment; with '-f' take from a file.
    With '-e', edit even after '-f' or '-m'.   ci is a synonym for commit.
 
+src amend [- | -m string | -f file | -e] ['revision'] ['file'...]::
+   Amends the stored comment for a specified revision, defaulting to the
+   latest revision on the current branch. Flags are as for commit.
+
 src checkout ['revision'] ['file'...]
    Refresh the working copy of the file(s) from their history files.
    co is a synonym for checkout.
@@ -826,6 +830,7 @@ dispatch = {
     "add":         add_method,
     "commit":      commit_method,
     "ci":          commit_method,
+    "amend":       amend_method,
     "list":        list_method,
     "log":         log_method,
     "checkout":    checkout_method,
@@ -892,6 +897,10 @@ class RCS:
     def checkout(self, arg, revision):
         "Check out a revision. Leaves it writeable."
         do_or_die("rm -f {0} && rcs -q -u {0},v && co -q -l{1} {0}".format(arg, revision))
+    def amend(self, arg, rev, comment):
+        "Amend a commit comment."
+        # Relies on caller to escape comment string
+        do_or_die("rcs -m{0}:{1} {2}".format(rev, comment, arg))
     def cat(self, arg, revision, fn=""):
         "Ship the contents of a revision to stdout or a named file."
         if fn:
@@ -1020,37 +1029,40 @@ class RCS:
                 print "\tsymbols:", metadata.symbols
 
 
-if __name__ == "__main__":    
-    command = list(sys.argv[1:])
-    explicit = False
-    while command and command[0].startswith("-"):
-        if command[0] == '-d':
-            debug += 1
-        elif command[0] == '-q':
-            quiet = True
-        elif command[0] == '-T':
-            pseudotime = True
-        elif command[0] == '-S':
-            repodir = command[1]
-            explicit = True
+if __name__ == "__main__":
+    try:
+        command = list(sys.argv[1:])
+        explicit = False
+        while command and command[0].startswith("-"):
+            if command[0] == '-d':
+                debug += 1
+            elif command[0] == '-q':
+                quiet = True
+            elif command[0] == '-T':
+                pseudotime = True
+            elif command[0] == '-S':
+                repodir = command[1]
+                explicit = True
+                command.pop(0)
             command.pop(0)
-        command.pop(0)
 
-    # RCS backwards-compatibility hack
-    if not explicit and not os.path.exists(repodir) and  os.path.exists("RCS"):
-        repodir = "RCS"
+        # RCS backwards-compatibility hack
+        if not explicit and not os.path.exists(repodir) and  os.path.exists("RCS"):
+            repodir = "RCS"
 
-    # Presently there is only one backend
-    backend = RCS()
+        # Presently there is only one backend
+        backend = RCS()
 
-    if not command:
-        help_method()
-    else:
-        try:
-            apply(dispatch[command[0]], command[1:])
-        except KeyError:
-            sys.stderr.write("src: no such command as '%s'.  Try 'src help'\n" \
-                           % command[0])
+        if not command:
+            help_method()
+        else:
+            try:
+                apply(dispatch[command[0]], command[1:])
+            except KeyError:
+                sys.stderr.write("src: no such command as '%s'.  Try 'src help'\n" \
+                               % command[0])
+    except KeyboardInterrupt:
+        pass
 
 # The following sets edit modes for GNU EMACS
 # Local Variables:
diff --git a/src.asc b/src.asc
index e61e8b90f39fbbbe8b4dfbd0489a94fceb012cd8..cbb322de899f06c88eb34be20e1002aa9c8501dd 100644 (file)
--- a/src.asc
+++ b/src.asc
@@ -48,12 +48,16 @@ src add ['file'...]::
    Initialize new project histories for specified files. Creates
    the repository directory if required.
 
-src commit [- | -m commentstring | -f commentfile | -e] ['file'...]::
+src commit [- | -m string | -f file | -e] ['file'...]::
    Enters a commit for specified files. Separately to each one.
    With '-', take comment text from stdin; with '-m' use the
    following string as the comment; with '-f' take from a file.
    With '-e', edit even after '-f' or '-m'. ci is a synonym for commit.
 
+src amend [- | -m string | -f file | -e] ['revision'] ['file'...]::
+   Amends the stored comment for a specified revision, defaulting to the
+   latest revision on the current branch. Flags are as for commit.
+
 src checkout [revision] ['file'...]::
    Refresh the working copy of the file(s) from their history files.
    co is a synonym for checkout.
diff --git a/srctest b/srctest
index 912bf6a5f7f5158cfdbb771d646d58e6dbfc1695..0eb28880f539ca72a9f24c159dd89562cbd5a38c 100755 (executable)
--- a/srctest
+++ b/srctest
@@ -230,6 +230,12 @@ rm -f $SANDBOX/testfile16,v
 src $TESTOPTS status testfile16 | grep "^?" >/dev/null
 check "? status check after master deletion"
 
+src $TESTOPTS amend -m "Amended comment" newname1
+check "amend"
+
+src $TESTOPTS list 3 newname1 | grep "Amended comment" >/dev/null
+check "amended comment content"
+
 rm -fr $SANDBOX
 
 # end