26
26
from bzrlib import (
30
31
from bzrlib.errors import BzrError, BadCommitMessageEncoding
31
32
from bzrlib.hooks import Hooks
32
from bzrlib.trace import warning, mutter
36
36
"""Return a sequence of possible editor binaries for the current platform"""
38
yield os.environ["BZR_EDITOR"]
38
yield os.environ["BZR_EDITOR"], '$BZR_EDITOR'
42
42
e = config.GlobalConfig().get_editor()
44
yield e, config.config_filename()
46
46
for varname in 'VISUAL', 'EDITOR':
47
47
if varname in os.environ:
48
yield os.environ[varname]
48
yield os.environ[varname], '$' + varname
50
50
if sys.platform == 'win32':
51
51
for editor in 'wordpad.exe', 'notepad.exe':
54
54
for editor in ['/usr/bin/editor', 'vi', 'pico', 'nano', 'joe']:
58
58
def _run_editor(filename):
59
59
"""Try to execute an editor to edit the commit message."""
60
for e in _get_editor():
60
for candidate, candidate_source in _get_editor():
61
edargs = candidate.split(' ')
63
63
## mutter("trying editor: %r", (edargs +[filename]))
64
64
x = call(edargs + [filename])
66
66
# We're searching for an editor, so catch safe errors and continue
67
if e.errno in (errno.ENOENT, ):
67
if e.errno in (errno.ENOENT, errno.EACCES):
68
if candidate_source is not None:
69
# We tried this editor because some user configuration (an
70
# environment variable or config file) said to try it. Let
71
# the user know their configuration is broken.
73
'Could not start editor "%s" (specified by %s): %s\n'
74
% (candidate, candidate_source, str(e)))
184
191
os.unlink(msgfilename)
185
192
except IOError, e:
186
warning("failed to unlink %s: %s; ignored", msgfilename, e)
194
"failed to unlink %s: %s; ignored", msgfilename, e)
189
197
def _create_temp_file_with_commit_template(infotext,