From c7415355d141111a422f39fbe3d70de5081390d2 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 9 Nov 2014 22:41:54 -0500 Subject: [PATCH] Refactor, preparing for amend. Regression test passes. --- src | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src b/src index b9a1cee..e2023ea 100755 --- 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") -- 2.43.0