496
"""Return a sequence of possible editor binaries for the current platform"""
497
e = _read_config_value("editor")
501
if os.name == "windows":
503
elif os.name == "posix":
505
yield os.environ["EDITOR"]
510
def _run_editor(filename):
511
"""Try to execute an editor to edit the commit message. Returns True on success,
513
for e in _get_editor():
514
x = os.spawnvp(os.P_WAIT, e, (e, filename))
521
raise BzrError("Could not start any editor. Please specify $EDITOR or use ~/.bzr.conf/editor")
525
def get_text_message(infotext, ignoreline = "default"):
528
if ignoreline == "default":
529
ignoreline = "-- This line and the following will be ignored --"
532
tmp_fileno, msgfilename = tempfile.mkstemp()
533
msgfile = os.close(tmp_fileno)
534
if infotext is not None and infotext != "":
536
msgfile = file(msgfilename, "w")
537
msgfile.write("\n\n%s\n\n%s" % (ignoreline, infotext))
542
if not _run_editor(msgfilename):
547
lastline, nlines = 0, 0
548
for line in file(msgfilename, "r"):
549
stripped_line = line.strip()
550
# strip empty line before the log message starts
552
if stripped_line != "":
556
# check for the ignore line only if there
557
# is additional information at the end
558
if hasinfo and stripped_line == ignoreline:
561
# keep track of the last line that had some content
562
if stripped_line != "":
568
# delete empty lines at the end
570
# add a newline at the end, if needed
571
if not msg[-1].endswith("\n"):
572
return "%s%s" % ("".join(msg), "\n")
576
# delete the msg file in any case
577
try: os.unlink(msgfilename)