~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/msgeditor.py

  • Committer: James Westby
  • Date: 2007-02-26 21:48:05 UTC
  • mto: (2304.1.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2305.
  • Revision ID: jw+debian@jameswestby.net-20070226214805-umfrbzkqnvvrna64
Make the handling of the msgfile more sane.

  * Close it in a finally block for more safety.
  * Open it at the start and just write to it instead of building up the
    message.
  * Don't close the fileno from mkstemp, just convert it to a filehandle
    straight away.

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
    msgfilename = None
105
105
    try:
106
106
        tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr_log.', dir=u'.')
107
 
        os.close(tmp_fileno)
108
 
        msgfile = None
109
 
        if start_message is not None:
110
 
            message = "%s\n" % start_message.encode(bzrlib.user_encoding,
111
 
                                                    'replace')
112
 
        else:
113
 
            message = ''
114
 
 
115
 
        if infotext is not None and infotext != "":
116
 
            hasinfo = True
117
 
            message = message + ("\n\n%s\n\n%s" % (ignoreline,
118
 
                infotext.encode(bzrlib.user_encoding, 'replace')))
119
 
        else:
120
 
            hasinfo = False
121
 
 
122
 
        if message != '':
123
 
            msgfile = file(msgfilename, "w")
124
 
            msgfile.write(message)
 
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:
125
121
            msgfile.close()
126
122
 
127
123
        if not _run_editor(msgfilename):