]> thyrsus.com Git - src.git/commitdiff
Refactor, preparing for amend. Regression test passes.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 10 Nov 2014 03:41:54 +0000 (22:41 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 10 Nov 2014 03:41:54 +0000 (22:41 -0500)
src

diff --git a/src b/src
index b9a1ceeba4fbac746e7378486d16a4d5e1378e6a..e2023ea0530f649ae442bdd0dfc218326bf92a05 100755 (executable)
--- a/src
+++ b/src
@@ -435,11 +435,8 @@ def add_method(*args):
            if not quiet and len(args) > 1:
               announce("%s -> 0" % arg) 
 
-def commit_method(*args):
-    "Commit changes to files."
-    if not os.path.exists(repodir):
-        croak("repository subdirectory %s does not exist" % repodir)
-    args = list(args)
+def getcomment(legend, args):
+    "Attempt to collect a comment from command line args."
     comment = None
     if args:
         if args[0] == '--':
@@ -453,16 +450,31 @@ def commit_method(*args):
                 comment = args[0]
                 args.pop(0)
             except IndexError:
-                croak("commit -m requires a following string.")
+                croak("%s -m requires a following string" % legend)
         elif args[0] == "-f":
             args.pop(0)
             try:
                 comment = open(args[0]).read()
                 args.pop(0)
             except IndexError:
-                croak("commit -f requires a following filename argument.")
+                croak("%s -f requires a following filename argument" % legend)
             except OSError:
                 croak("couldn't open %s." % args[1])
+    return comment
+
+def edit_comment():
+    "Interactively edit a coment."
+    editor = os.getenv("EDITOR") or "emacsclient"
+    commentfile = "/tmp/src%dtmp" % os.getpid()
+    do_or_die(editor + " " + commentfile, loud=True)
+    comment = open(commentfile).read()
+
+def commit_method(*args):
+    "Commit changes to files."
+    if not os.path.exists(repodir):
+        croak("repository subdirectory %s does not exist" % repodir)
+    args = list(args)
+    comment = getcomment("commit", args)
     (revspec, args) = preamble("commit", args)
     if revspec is not None:
         croak("commit doesn't take a revision spec")
@@ -474,10 +486,7 @@ def commit_method(*args):
        else:
            metadata = History(arg)
            if not comment:
-               editor = os.getenv("EDITOR") or "emacsclient"
-               commentfile = "/tmp/src%dtmp" % os.getpid()
-               do_or_die(editor + " " + commentfile, loud=True)
-               comment = open(commentfile).read()
+               comment = edit_comment()
            # Delimiter won't be set just after add
            if metadata.delimiter and metadata.delimiter in comment:
                croak("malformed comment")