]> thyrsus.com Git - src.git/commitdiff
Useful boilerpplare in the editor when committing or appending.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 13 Nov 2014 04:25:09 +0000 (23:25 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 13 Nov 2014 04:25:09 +0000 (23:25 -0500)
Regression test passes.

TODO
src

diff --git a/TODO b/TODO
index e94335b62f7c8ca08e9923611db55fe4d6648a50..a6d06ff28172163b6660642cabb0cdb2107e88b7 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,5 +1,7 @@
                        SRC TODO list
 
+* Branch names are not yet resolved in revspecs.
+
 * src branch delete. Should branch_delete really obsolesce branches or just
   mark them dead?
 
diff --git a/src b/src
index 328e299f91d11389cf50d09e0c1c70d48e93286a..89977ce381b779b9a1c5c1b5c689c59c26ae5994 100755 (executable)
--- a/src
+++ b/src
@@ -526,28 +526,33 @@ The cut line and things below it will not become part of the comment text.
                     croak("couldn't open %s." % args[1])
     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 and not self.force_edit:
+            self.comment = self.leader
+        else:
             if self.leader:
                 content = self.leader + content
             if trailer:
-                content += CommentContext.COMMENT_CUTLINE + CommentContext.COMMENT_EXPLANATION + trailer
+                content += "\n" + CommentContext.COMMENT_CUTLINE + CommentContext.COMMENT_EXPLANATION + trailer
             editor = os.getenv("EDITOR") or "emacsclient"
             try:
                 commentfile = "/tmp/src%dtmp" % os.getpid()
                 open(commentfile, "w").write(content)
                 do_or_die(editor + " " + commentfile, loud=True)
                 self.comment = open(commentfile).read()
+                if not self.comment.strip():
+                    return False
             except IOError:
-                croak("amend aborted.")
-        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
-        for badnews in backend.delimiters:
-            if badnews in self.comment:
-                croak("malformed comment")
+                croak("in %s, amend aborted." % arg)
+            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
+            for badnews in backend.delimiters:
+                if badnews in self.comment:
+                    croak("malformed comment")
         if not self.comment.endswith("\n"):
             self.comment += "\n"
+        return True
     def content(self):
         "Return the edited comment."
         return self.comment
@@ -566,13 +571,15 @@ def commit_method(*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):
-            backend.checkin(arg, comment.content())
-        if not quiet and len(args) > 1:
-            announce("%s -> %d" % (arg, len(History(arg))))
+        if not comment.edit(content="", trailer=trailer):
+            announce("in %s, commit cancelled" % arg)
+        else:
+            if not os.path.exists(backend.master(arg)):
+                backend.add(arg)
+            with backend.lifter(arg):
+                backend.checkin(arg, comment.content())
+            if not quiet and len(args) > 1:
+                announce("%s -> %d" % (arg, len(History(arg))))
 
 def amend_method(*args):
     "Amend comments in stored revisions."
@@ -594,9 +601,11 @@ def amend_method(*args):
         if ctx.is_empty():
             ctx.start = metadata.tip().revno
         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,
+        if not comment.edit(metadata.by_revno(ctx.start).log, trailer):
+            announce("in %s, amend cancelled" % arg)
+        else:
+            with backend.lifter(arg):
+                backend.amend(arg,
                           metadata.revno_to_native(ctx.start),
                           comment.content())
     if not quiet and len(args) > 1: