From e07f7ede11ffd7eee23fa2669922c59ca395ee0a Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 12 Nov 2014 21:57:06 -0500 Subject: [PATCH] Amending now includes the old comment. --- TODO | 2 -- src | 34 ++++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index 113c922..e94335b 100644 --- a/TODO +++ b/TODO @@ -8,5 +8,3 @@ KNOWN BUGS * chungy reports timestamp issues messing up status on ZFS. - -* amend needs to initialize the buffer with the old content value. diff --git a/src b/src index 224946c..328e299 100755 --- a/src +++ b/src @@ -489,50 +489,57 @@ class CommandContext: return [metadata.by_revno(s) for s in self.seq] class CommentContext: - COMMENT_LEADER = """\ + COMMENT_CUTLINE = """\ ............................................................................. +""" + COMMENT_EXPLANATION = """\ 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.leader = "" self.comment = None self.force_edit = False if args: if args[0] == '--': args.pop(0) elif args[0] == "-": - self.comment = sys.stdin.read() + self.leader = sys.stdin.read() args.pop(0) elif args[0] == "-e": self.force_edit = True elif args[0] == "-m": args.pop(0) try: - self.comment = args[0] + self.leader = args[0] args.pop(0) except IndexError: croak("%s -m requires a following string" % legend) elif args[0] == "-f": args.pop(0) try: - self.comment = open(args[0]).read() + self.leader = open(args[0]).read() args.pop(0) except IndexError: croak("%s -f requires a following filename argument" % legend) except OSError: croak("couldn't open %s." % args[1]) - def edit(self, initial_text): + def edit(self, content="", trailer=""): "Interactively edit a comment if required, then prepare for handoff." if self.comment is None or self.force_edit: + if self.leader: + content = self.leader + content + if trailer: + content += CommentContext.COMMENT_CUTLINE + CommentContext.COMMENT_EXPLANATION + trailer editor = os.getenv("EDITOR") or "emacsclient" try: commentfile = "/tmp/src%dtmp" % os.getpid() - open(commentfile, "w").write(initial_text) + open(commentfile, "w").write(content) do_or_die(editor + " " + commentfile, loud=True) self.comment = open(commentfile).read() except IOError: croak("amend aborted.") - where = self.comment.find(CommentContext.COMMENT_LEADER) + where = self.comment.find(CommentContext.COMMENT_CUTLINE) if where != -1: self.comment = self.comment[:where] # Can be removed if we ever parse RC files directly @@ -556,10 +563,10 @@ def commit_method(*args): comment = CommentContext("commit", args) ctx = CommandContext("commit", args, require_empty=True) for arg in ctx.args: - if not os.path.exists(arg): - croak("I see no '%s' here." % arg) - comment.edit("") - for arg in ctx.args: + if not os.path.exists(arg): + croak("I see no '%s' here." % arg) + trailer ="Committing {0} revision {1}.\n".format(arg, ctx.start) + comment.edit(content="", trailer=trailer) if not os.path.exists(backend.master(arg)): backend.add(arg) with backend.lifter(arg): @@ -586,9 +593,8 @@ def amend_method(*args): 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) + trailer ="Amending {0} revision {1}.\n".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