]> thyrsus.com Git - src.git/commitdiff
src amend gets a useful trailer.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 13 Nov 2014 02:03:34 +0000 (21:03 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 13 Nov 2014 02:03:34 +0000 (21:03 -0500)
src

diff --git a/src b/src
index 5cda6768de18a65fb6e4fa15d1388245974de08e..224946c3caa77c5212afb9f793df426cc6ba5252 100755 (executable)
--- 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),