~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/msgeditor.py

  • Committer: IWATA Hidetaka
  • Date: 2010-12-26 13:19:11 UTC
  • mto: This revision was merged to the branch mainline in revision 5593.
  • Revision ID: iwata0303@gmail.com-20101226131911-o7txs0fnji5zekq1
add icon resources tbzrcommand(w)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Commit message editor support."""
19
19
 
20
20
import codecs
21
 
import errno
22
21
import os
23
22
from subprocess import call
24
23
import sys
27
26
    config,
28
27
    osutils,
29
28
    trace,
 
29
    transport,
 
30
    ui,
30
31
    )
31
32
from bzrlib.errors import BzrError, BadCommitMessageEncoding
32
33
from bzrlib.hooks import HookPoint, Hooks
139
140
    try:
140
141
        msgfilename, hasinfo = _create_temp_file_with_commit_template(
141
142
                                    infotext, ignoreline, start_message)
142
 
 
143
 
        if not msgfilename or not _run_editor(msgfilename):
144
 
            return None
145
 
 
 
143
        if not msgfilename:
 
144
            return None
 
145
        basename = osutils.basename(msgfilename)
 
146
        msg_transport = transport.get_transport(osutils.dirname(msgfilename))
 
147
        reference_content = msg_transport.get_bytes(basename)
 
148
        if not _run_editor(msgfilename):
 
149
            return None
 
150
        edited_content = msg_transport.get_bytes(basename)
 
151
        if edited_content == reference_content:
 
152
            if not ui.ui_factory.confirm_action(
 
153
                "Commit message was not edited, use anyway",
 
154
                "bzrlib.msgeditor.unchanged",
 
155
                {}):
 
156
                # Returning "" makes cmd_commit raise 'empty commit message
 
157
                # specified' which is a reasonable error, given the user has
 
158
                # rejected using the unedited template.
 
159
                return ""
146
160
        started = False
147
161
        msg = []
148
162
        lastline, nlines = 0, 0
194
208
 
195
209
def _create_temp_file_with_commit_template(infotext,
196
210
                                           ignoreline=DEFAULT_IGNORE_LINE,
197
 
                                           start_message=None):
 
211
                                           start_message=None,
 
212
                                           tmpdir=None):
198
213
    """Create temp file and write commit template in it.
199
214
 
200
 
    :param infotext:    Text to be displayed at bottom of message
201
 
                        for the user's reference;
202
 
                        currently similar to 'bzr status'.
203
 
                        The text is already encoded.
 
215
    :param infotext: Text to be displayed at bottom of message for the
 
216
        user's reference; currently similar to 'bzr status'.  The text is
 
217
        already encoded.
204
218
 
205
219
    :param ignoreline:  The separator to use above the infotext.
206
220
 
207
 
    :param start_message:   The text to place above the separator, if any.
208
 
                            This will not be removed from the message
209
 
                            after the user has edited it.
210
 
                            The string is already encoded
 
221
    :param start_message: The text to place above the separator, if any.
 
222
        This will not be removed from the message after the user has edited
 
223
        it.  The string is already encoded
211
224
 
212
225
    :return:    2-tuple (temp file name, hasinfo)
213
226
    """
214
227
    import tempfile
215
228
    tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr_log.',
216
 
                                               dir='.',
217
 
                                               text=True)
218
 
    msgfilename = osutils.basename(msgfilename)
 
229
                                               dir=tmpdir, text=True)
219
230
    msgfile = os.fdopen(tmp_fileno, 'w')
220
231
    try:
221
232
        if start_message is not None: