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
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."
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: