~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/msgeditor.py

  • Committer: Robert Collins
  • Date: 2007-03-05 03:43:56 UTC
  • mfrom: (2312 +trunk)
  • mto: (2255.11.6 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: robertc@robertcollins.net-20070305034356-og43j35eg62m952f
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
    { 'bar' : '-' * 14, 'msg' : 'This line and the following will be ignored' }
81
81
 
82
82
 
83
 
def edit_commit_message(infotext, ignoreline=DEFAULT_IGNORE_LINE):
 
83
def edit_commit_message(infotext, ignoreline=DEFAULT_IGNORE_LINE,
 
84
                        start_message=None):
84
85
    """Let the user edit a commit message in a temp file.
85
86
 
86
87
    This is run if they don't give a message or
90
91
        Text to be displayed at bottom of message for
91
92
        the user's reference; currently similar to
92
93
        'bzr status'.
 
94
 
 
95
    ignoreline:
 
96
        The separator to use above the infotext.
 
97
 
 
98
    start_message:
 
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.
93
101
    """
94
102
    import tempfile
95
103
 
96
104
    msgfilename = None
97
105
    try:
98
106
        tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr_log.', dir=u'.')
99
 
        msgfile = os.close(tmp_fileno)
100
 
        if infotext is not None and infotext != "":
101
 
            hasinfo = True
102
 
            msgfile = file(msgfilename, "w")
103
 
            msgfile.write("\n\n%s\n\n%s" % (ignoreline,
104
 
                infotext.encode(bzrlib.user_encoding, 'replace')))
 
107
        msgfile = os.fdopen(tmp_fileno, 'w')
 
108
        try:
 
109
            if start_message is not None:
 
110
                msgfile.write("%s\n" % start_message.encode(
 
111
                                           bzrlib.user_encoding, 'replace'))
 
112
 
 
113
            if infotext is not None and infotext != "":
 
114
                hasinfo = True
 
115
                msgfile.write("\n\n%s\n\n%s" % (ignoreline,
 
116
                              infotext.encode(bzrlib.user_encoding,
 
117
                                                    'replace')))
 
118
            else:
 
119
                hasinfo = False
 
120
        finally:
105
121
            msgfile.close()
106
 
        else:
107
 
            hasinfo = False
108
122
 
109
123
        if not _run_editor(msgfilename):
110
124
            return None