From d7931bd551c04a13ab1c4d86bd8049383be3ac0b Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 12 Nov 2014 21:03:34 -0500 Subject: [PATCH] src amend gets a useful trailer. --- src | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src b/src index 5cda676..224946c 100755 --- a/src +++ b/src @@ -489,6 +489,10 @@ class CommandContext: return [metadata.by_revno(s) for s in self.seq] class CommentContext: + COMMENT_LEADER = """\ +............................................................................. +The cut line and things below it will not become part of the comment text. +""" def __init__(self, legend, args): "Attempt to collect a comment from command line args." self.comment = None @@ -517,17 +521,21 @@ class CommentContext: croak("%s -f requires a following filename argument" % legend) except OSError: croak("couldn't open %s." % args[1]) - def edit(self): + def edit(self, initial_text): "Interactively edit a comment if required, then prepare for handoff." if self.comment is None or self.force_edit: editor = os.getenv("EDITOR") or "emacsclient" try: commentfile = "/tmp/src%dtmp" % os.getpid() + open(commentfile, "w").write(initial_text) do_or_die(editor + " " + commentfile, loud=True) self.comment = open(commentfile).read() except IOError: croak("amend aborted.") - # Can be removed if we every parse RC files directly + where = self.comment.find(CommentContext.COMMENT_LEADER) + if where != -1: + self.comment = self.comment[:where] + # Can be removed if we ever parse RC files directly for badnews in backend.delimiters: if badnews in self.comment: croak("malformed comment") @@ -550,7 +558,7 @@ def commit_method(*args): for arg in ctx.args: if not os.path.exists(arg): croak("I see no '%s' here." % arg) - comment.edit() + comment.edit("") for arg in ctx.args: if not os.path.exists(backend.master(arg)): backend.add(arg) @@ -573,12 +581,14 @@ def amend_method(*args): croak("I see no '%s' here." % arg) elif not os.path.exists(backend.master(arg)): croak("%s is not registered." % arg) - comment.edit() for arg in ctx.args: metadata = History(arg) ctx.resolve(metadata) if ctx.is_empty(): ctx.start = metadata.tip().revno + trailer = CommentContext.COMMENT_LEADER + "Amending {0} revision {1}.\n" + trailer = trailer.format(arg, ctx.start) + comment.edit(metadata.by_revno(ctx.start).log + trailer) with backend.lifter(arg): backend.amend(arg, metadata.revno_to_native(ctx.start), -- 2.43.0