384
384
if not ignore_errors:
385
385
raise BzrError('command failed')
388
def _read_config_value(name):
389
"""Read a config value from the file ~/.bzr.conf/<name>
390
Return None if the file does not exist"""
392
f = file(os.path.join(config_dir(), name), "r")
393
return f.read().decode(bzrlib.user_encoding).rstrip("\r\n")
395
if e.errno == errno.ENOENT:
401
"""Return a sequence of possible editor binaries for the current platform"""
402
e = _read_config_value("editor")
406
if os.name == "windows":
408
elif os.name == "posix":
410
yield os.environ["EDITOR"]
415
def _run_editor(filename):
416
"""Try to execute an editor to edit the commit message. Returns True on success,
418
for e in _get_editor():
419
x = os.spawnvp(os.P_WAIT, e, (e, filename))
426
raise BzrError("Could not start any editor. Please specify $EDITOR or use ~/.bzr.conf/editor")
430
def get_text_message(infotext, ignoreline = "default"):
433
if ignoreline == "default":
434
ignoreline = "-- This line and the following will be ignored --"
437
tmp_fileno, msgfilename = tempfile.mkstemp()
438
msgfile = os.close(tmp_fileno)
439
if infotext is not None and infotext != "":
441
msgfile = file(msgfilename, "w")
442
msgfile.write("\n\n%s\n\n%s" % (ignoreline, infotext))
447
if not _run_editor(msgfilename):
452
lastline, nlines = 0, 0
453
for line in file(msgfilename, "r"):
454
stripped_line = line.strip()
455
# strip empty line before the log message starts
457
if stripped_line != "":
461
# check for the ignore line only if there
462
# is additional information at the end
463
if hasinfo and stripped_line == ignoreline:
466
# keep track of the last line that had some content
467
if stripped_line != "":
473
# delete empty lines at the end
475
# add a newline at the end, if needed
476
if not msg[-1].endswith("\n"):
477
return "%s%s" % ("".join(msg), "\n")
481
# delete the msg file in any case
482
try: os.unlink(msgfilename)