]> thyrsus.com Git - src.git/commitdiff
Amending now includes the old comment.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 13 Nov 2014 02:57:06 +0000 (21:57 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 13 Nov 2014 02:57:06 +0000 (21:57 -0500)
TODO
src

diff --git a/TODO b/TODO
index 113c922458affc6e0f34da632128eb37c5ab026f..e94335b62f7c8ca08e9923611db55fe4d6648a50 100644 (file)
--- 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 224946c3caa77c5212afb9f793df426cc6ba5252..328e299f91d11389cf50d09e0c1c70d48e93286a 100755 (executable)
--- 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),