/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/msgeditor.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 23:15:15 UTC
  • mfrom: (7180 work)
  • mto: This revision was merged to the branch mainline in revision 7183.
  • Revision ID: jelmer@jelmer.uk-20181116231515-zqd2yn6kj8lfydyp
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
 
47
47
 
48
48
def _get_editor():
49
 
    """Return a sequence of possible editor binaries for the current platform"""
 
49
    """Return sequence of possible editor binaries for the current platform"""
50
50
    try:
51
51
        yield os.environ["BRZ_EDITOR"], '$BRZ_EDITOR'
52
52
    except KeyError:
73
73
    for candidate, candidate_source in _get_editor():
74
74
        edargs = cmdline.split(candidate)
75
75
        try:
76
 
            ## mutter("trying editor: %r", (edargs +[filename]))
77
76
            x = call(edargs + [filename])
78
77
        except OSError as e:
79
78
            if candidate_source is not None:
93
92
            break
94
93
    raise BzrError("Could not start any editor.\nPlease specify one with:\n"
95
94
                   " - $BRZ_EDITOR\n - editor=/some/path in %s\n"
96
 
                   " - $VISUAL\n - $EDITOR" % \
97
 
                    config.config_filename())
 
95
                   " - $VISUAL\n - $EDITOR" %
 
96
                   config.config_filename())
98
97
 
99
98
 
100
99
DEFAULT_IGNORE_LINE = "%(bar)s %(msg)s %(bar)s" % \
101
 
    { 'bar' : '-' * 14, 'msg' : 'This line and the following will be ignored' }
 
100
    {'bar': '-' * 14, 'msg': 'This line and the following will be ignored'}
102
101
 
103
102
 
104
103
def edit_commit_message(infotext, ignoreline=DEFAULT_IGNORE_LINE,
121
120
    :return:    commit message or None.
122
121
    """
123
122
 
124
 
    if not start_message is None:
 
123
    if start_message is not None:
125
124
        start_message = start_message.encode(osutils.get_user_encoding())
126
125
    infotext = infotext.encode(osutils.get_user_encoding(), 'replace')
127
126
    return edit_commit_message_encoded(infotext, ignoreline, start_message)
151
150
    msgfilename = None
152
151
    try:
153
152
        msgfilename, hasinfo = _create_temp_file_with_commit_template(
154
 
                                    infotext, ignoreline, start_message)
 
153
            infotext, ignoreline, start_message)
155
154
        if not msgfilename:
156
155
            return None
157
156
        basename = osutils.basename(msgfilename)
158
 
        msg_transport = transport.get_transport_from_path(osutils.dirname(msgfilename))
 
157
        msg_transport = transport.get_transport_from_path(
 
158
            osutils.dirname(msgfilename))
159
159
        reference_content = msg_transport.get_bytes(basename)
160
160
        if not _run_editor(msgfilename):
161
161
            return None
164
164
            if not ui.ui_factory.confirm_action(
165
165
                u"Commit message was not edited, use anyway",
166
166
                "breezy.msgeditor.unchanged",
167
 
                {}):
 
167
                    {}):
168
168
                # Returning "" makes cmd_commit raise 'empty commit message
169
169
                # specified' which is a reasonable error, given the user has
170
170
                # rejected using the unedited template.
306
306
        These are all empty initially.
307
307
        """
308
308
        Hooks.__init__(self, "breezy.msgeditor", "hooks")
309
 
        self.add_hook('set_commit_message',
 
309
        self.add_hook(
 
310
            'set_commit_message',
310
311
            "Set a fixed commit message. "
311
312
            "set_commit_message is called with the "
312
 
            "breezy.commit.Commit object (so you can also change e.g. revision "
313
 
            "properties by editing commit.builder._revprops) and the message "
314
 
            "so far. set_commit_message must return the message to use or None"
315
 
            " if it should use the message editor as normal.", (2, 4))
316
 
        self.add_hook('commit_message_template',
 
313
            "breezy.commit.Commit object (so you can also change e.g. "
 
314
            "revision properties by editing commit.builder._revprops) and the "
 
315
            "message so far. set_commit_message must return the message to "
 
316
            "use or None if it should use the message editor as normal.",
 
317
            (2, 4))
 
318
        self.add_hook(
 
319
            'commit_message_template',
317
320
            "Called when a commit message is being generated. "
318
321
            "commit_message_template is called with the breezy.commit.Commit "
319
322
            "object and the message that is known so far. "