[PATCH] (updated) Use the first line of commit message in "log --line"
John A Meinel
john at arbash-meinel.com
Wed May 31 14:10:12 BST 2006
Matthieu Moy wrote:
> "Michael Ellerman" <michael at ellerman.id.au> writes:
>
>> I guess I'm having a really slow day, but I still don't understand why
>> it's preferable to split into a list of two elements, then return a
>> list containing only the first, then join the one element list with
>> the empty string?
>>
>>>>> message = 'foo'
>>>>> message.split('\n', 1)[0]
>> 'foo'
>>>>> message = 'foo\nbar'
>>>>> message.split('\n', 1)[0]
>> 'foo'
>>>>> message = ''
>>>>> message.split('\n', 1)[0]
>> ''
>
> True. The following patch should be OK then.
>
Specifically because an empty string will return an empty list, and [0]
will return an IndexError. But this was the problem with 'splitlines'
which acts slightly differently than split.
It seems that split('\n') will always return at least one entry
(possibly empty), so the above code is better.
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060531/8e217172/attachment.pgp
More information about the bazaar
mailing list