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
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):
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),