From: Eric S. Raymond Date: Thu, 13 Nov 2014 04:25:09 +0000 (-0500) Subject: Useful boilerpplare in the editor when committing or appending. X-Git-Tag: 0.6~2 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=15dc41c21c4759398109e07fd6fdc5adbad38ab8;p=src.git Useful boilerpplare in the editor when committing or appending. Regression test passes. --- diff --git a/TODO b/TODO index e94335b..a6d06ff 100644 --- 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 328e299..89977ce 100755 --- 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: