From b32dc93302e45ccc723ebb63ce0ac3254f7bc52c Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 10 Nov 2014 11:01:47 -0500 Subject: [PATCH] Add src amend. Also seal gracefully with keyboard interrupts. --- NEWS | 1 + src | 68 +++++++++++++++++++++++++++++++++------------------------ src.asc | 6 ++++- srctest | 6 +++++ 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/NEWS b/NEWS index 4bf7238..8079d55 100644 --- 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 8cb5ca7..037ca74 100755 --- 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 e61e8b9..cbb322d 100644 --- 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 912bf6a..0eb2888 100755 --- 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 -- 2.43.0