[MERGE] Add a way to specify a template commit message

Martin Pool mbp at canonical.com
Tue Feb 6 01:02:32 GMT 2007


On  4 Feb 2007, James Westby <jw+debian at jameswestby.net> wrote:
> And here is the bundle.

Looks good, though maybe you could do a followup cleanup?

>      This is run if they don't give a message or
> @@ -90,6 +91,13 @@
>          Text to be displayed at bottom of message for
>          the user's reference; currently similar to
>          'bzr status'.
> +
> +    ignoreline:
> +        The separator to use above the infotext.
> +
> +    start_message:
> +        The text to place above the separator, if any. This will not be
> +        removed from the message after the user has edited it.
>      """
>      import tempfile
>  
> @@ -97,15 +105,25 @@
>      try:
>          tmp_fileno, msgfilename = tempfile.mkstemp(prefix='bzr_log.', dir=u'.')
>          msgfile = os.close(tmp_fileno)

OK I realize you didn't change it but this line is very odd -- surely
os.close returns None?

> +        havefile = False
> +        if start_message is not None:
> +            havefile = True
> +            msgfile = file(msgfilename, "w")
> +            msgfile.write("%s\n" % start_message.encode(
> +                                     bzrlib.user_encoding, 'replace'))
>          if infotext is not None and infotext != "":
>              hasinfo = True
> -            msgfile = file(msgfilename, "w")
> +            if not havefile:
> +              msgfile = file(msgfilename, "w")
> +              havefile = True
>              msgfile.write("\n\n%s\n\n%s" % (ignoreline,
>                  infotext.encode(bzrlib.user_encoding, 'replace')))
> -            msgfile.close()
>          else:
>              hasinfo = False
>  
> +        if havefile:
> +          msgfile.close()
> +
>          if not _run_editor(msgfilename):
>              return None

The handling of the file seems over complicated and it is preferable to
have close() in a finally block, particularly on Windows.  How about
just 

  ... mkstemp
  msgfile = os.fdopen(tmp_fileno)
  try:
    ....
  finally:
    msgfile.close()


-- 
Martin



More information about the bazaar mailing list