From b219743a762bb7b328f50e075d176e4f0e63f7cf Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 9 Nov 2014 22:55:00 -0500 Subject: [PATCH] Refactor, preparing for amemd. Regression test passes and EDITOR works. --- src | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src b/src index e2023ea..948763b 100755 --- 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: -- 2.43.0