[BUG] Strip trailing whitespace from commit message

John Arbash Meinel john at arbash-meinel.com
Thu Dec 21 16:27:23 GMT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jari Aalto wrote:
> I mistakely did:
> 
>     bzr ci -m "- use xmlSaveFile => xmlSaveFormatFileEnc "
> 
> Ooops, there was trailing space. Verify:
> 
>     bzr log src/data.c | cat -vET
> 
>     ------------------------------------------------------------$
>     revno: 6$
>     committer: jari.aalto at cante.net$
>     branch nick: feature.clay-to-dlume$
>     timestamp: Thu 2006-12-21 18:13:53 +0200$
>     message:$
>       - use xmlSaveFile => xmlSaveFormatFileEnc $
> 
> SUGGESTION
> 
> Please remove all trailing whitespcae from the commit message lines.
> 
> Jari

I'm generally not comfortable modifying the data that users give us,
unless there is a strict reason to.

Especially if you start to have multiple lines. We don't necesarily know
where the data came from, or if trailing whitespace is significant or not.

One specific case would be converters, which try to take the message
verbatim from the source, and commit it to bzr.

We could get around this a bit by making the strip happen in
cmd_commit() rather than inside Commit.commit().

Since all the converters I know of try to do it directly in python,
rather than spawning "bzr" each time. (Certainly it is a lot faster to
convert that way).

Anyway, I'm probably +0 on doing this, but if people really want it,
this patch should do it:

=== modified file 'bzrlib/builtins.py'
- --- bzrlib/builtins.py  2006-12-21 04:38:20 +0000
+++ bzrlib/builtins.py  2006-12-21 16:24:06 +0000
@@ -1894,6 +1894,8 @@
             if file:
                 my_message = codecs.open(file, 'rt',
                                          bzrlib.user_encoding).read()
+            # Strip whitespace from each line
+            my_message = '\n'.join(l.rstrip() for l in
my_message.splitlines())
             if my_message == "":
                 raise errors.BzrCommandError("empty commit message
specified")
             return my_message


I think this also has the side effect of replacing \r\n => \n, which I
would guess that people who want to get rid of trailing whitespace would
also want to do. Though I also see that 'edit_commit_message()' is
already opening the file in text mode ('r'), so on Win32 it should be
stripping them anyway.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFirXrJdeBCYSNAAMRAsJ1AJ0Y3TUxtmOcSUMKbM4AACnLg7AAgQCePyMT
gkVeaJU5RtTfNismJPbAw6U=
=0GGF
-----END PGP SIGNATURE-----




More information about the bazaar mailing list