[BUG] Strip trailing whitespace from commit message

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


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

John Arbash Meinel wrote:
> Jari Aalto wrote:
>

...

> 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")

There is one other side effect, which is that that statement will remove
a final newline. For example:

>>> '\n'.join('a\nb\n'.splitlines())
'a\nb'

We could instead do:

>>> '\n'.join('a\nb\n'.split('\n'))
'a\nb\n'

my_message = '\n'.join(l.rstrip() for l in my_message.split('\n'))

Which also won't change '\r\n' => '\n'.

Oh, and we currently have a slight platform dependent effect. In that
under Linux we won't strip '\r\n' => '\n' (because Linux doesn't have a
text mode for files).

I can't really say which is "best". I kind of like thinking that there
won't be any '\r' in user's commit messages. But at the same time, I
feel pretty strongly that we shouldn't be doing too much modification to
user input. Because there might be times where users want it, and what
do we do then?

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

iD8DBQFFirc1JdeBCYSNAAMRAg+5AKDQOuUVbklQyebs0Oig/FfihfIYywCgsrxk
6iR6f9ugKj/ynWoqFEAd4iw=
=zwKp
-----END PGP SIGNATURE-----




More information about the bazaar mailing list