87
87
This is run if they don't give a message or
88
88
message-containing file on the command line.
91
Text to be displayed at bottom of message for
92
the user's reference; currently similar to
96
The separator to use above the infotext.
99
The text to place above the separator, if any. This will not be
100
removed from the message after the user has edited it.
90
:param infotext: Text to be displayed at bottom of message
91
for the user's reference;
92
currently similar to 'bzr status'.
94
:param ignoreline: The separator to use above the infotext.
96
:param start_message: The text to place above the separator, if any.
97
This will not be removed from the message
98
after the user has edited it.
100
:return: commit message or None.
104
102
msgfilename = None
106
tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr_log.', dir=u'.')
107
msgfile = os.fdopen(tmp_fileno, 'w')
109
if start_message is not None:
110
msgfile.write("%s\n" % start_message.encode(
111
bzrlib.user_encoding, 'replace'))
113
if infotext is not None and infotext != "":
115
msgfile.write("\n\n%s\n\n%s" % (ignoreline,
116
infotext.encode(bzrlib.user_encoding,
123
if not _run_editor(msgfilename):
104
msgfilename, hasinfo = _create_temp_file_with_commit_template(
105
infotext, ignoreline, start_message)
107
if not msgfilename or not _run_editor(msgfilename):
128
112
lastline, nlines = 0, 0
129
for line in codecs.open(msgfilename, 'r', bzrlib.user_encoding):
113
# codecs.open() ALWAYS opens file in binary mode but we need text mode
114
# 'rU' mode useful when bzr.exe used on Cygwin (bialix 20070430)
115
f = file(msgfilename, 'rU')
116
for line in codecs.getreader(bzrlib.user_encoding)(f):
130
117
stripped_line = line.strip()
131
118
# strip empty line before the log message starts
162
150
warning("failed to unlink %s: %s; ignored", msgfilename, e)
153
def _create_temp_file_with_commit_template(infotext,
154
ignoreline=DEFAULT_IGNORE_LINE,
156
"""Create temp file and write commit template in it.
158
:param infotext: Text to be displayed at bottom of message
159
for the user's reference;
160
currently similar to 'bzr status'.
162
:param ignoreline: The separator to use above the infotext.
164
:param start_message: The text to place above the separator, if any.
165
This will not be removed from the message
166
after the user has edited it.
168
:return: 2-tuple (temp file name, hasinfo)
171
tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr_log.',
174
msgfile = os.fdopen(tmp_fileno, 'w')
176
if start_message is not None:
177
msgfile.write("%s\n" % start_message.encode(
178
bzrlib.user_encoding, 'replace'))
180
if infotext is not None and infotext != "":
182
msgfile.write("\n\n%s\n\n%s" % (ignoreline,
183
infotext.encode(bzrlib.user_encoding,
190
return (msgfilename, hasinfo)
165
193
def make_commit_message_template(working_tree, specific_files):
166
194
"""Prepare a template file for a commit into a branch.