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.',
109
msgfile = os.fdopen(tmp_fileno, 'w')
111
if start_message is not None:
112
msgfile.write("%s\n" % start_message.encode(
113
bzrlib.user_encoding, 'replace'))
115
if infotext is not None and infotext != "":
117
msgfile.write("\n\n%s\n\n%s" % (ignoreline,
118
infotext.encode(bzrlib.user_encoding,
125
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):
130
112
lastline, nlines = 0, 0
131
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):
132
117
stripped_line = line.strip()
133
118
# strip empty line before the log message starts
164
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)
167
193
def make_commit_message_template(working_tree, specific_files):
168
194
"""Prepare a template file for a commit into a branch.