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

diff --git a/src b/src
index e2023ea0530f649ae442bdd0dfc218326bf92a05..948763b292eb08b711b1016c6c68d8d2fda00a66 100755 (executable)
--- a/src
+++ b/src
@@ -435,7 +435,7 @@ def add_method(*args):
            if not quiet and len(args) > 1:
               announce("%s -> 0" % arg) 
 
-def getcomment(legend, args):
+def get_comment(legend, args):
     "Attempt to collect a comment from command line args."
     comment = None
     if args:
@@ -467,14 +467,24 @@ def edit_comment():
     editor = os.getenv("EDITOR") or "emacsclient"
     commentfile = "/tmp/src%dtmp" % os.getpid()
     do_or_die(editor + " " + commentfile, loud=True)
-    comment = open(commentfile).read()
+    return open(commentfile).read()
+
+def prepare_comment(comment, metadata):
+    "Validate comment text and preapare it to be passed to the back end."
+    # Delimiter won't be set just after add
+    if metadata.delimiter and metadata.delimiter in comment:
+        croak("malformed comment")
+    if not comment.endswith("\n"):
+        comment += "\n"
+    # Because it's going to be handed back in single quotes
+    return comment.replace("'", r"\'")
 
 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)
+    comment = get_comment("commit", args)
     (revspec, args) = preamble("commit", args)
     if revspec is not None:
         croak("commit doesn't take a revision spec")
@@ -487,12 +497,7 @@ def commit_method(*args):
            metadata = History(arg)
            if not comment:
                comment = edit_comment()
-           # Delimiter won't be set just after add
-           if metadata.delimiter and metadata.delimiter in comment:
-               croak("malformed comment")
-           if not comment.endswith("\n"):
-               comment += "\n"
-           comment = comment.replace("'", r"\'")
+           comment = prepare_comment(comment, metadata)
            with backend.lifter(arg):
                backend.checkin(arg, comment)
            if not quiet and len(args) > 1: