[merge][0.11] 'bzr annotate' fails on empty files

John Arbash Meinel john at arbash-meinel.com
Fri Sep 22 00:26:40 BST 2006


Wouter van Heyst wrote:
> On Thu, Sep 21, 2006 at 02:43:24PM -0500, John Arbash Meinel wrote:
>> 'bzr annotate' calls max(list) but the list is empty if there are no
>> lines in the file.
>>
>> The attached patch adds a test case, and a fix for bug:
>> https://launchpad.net/products/bzr/+bug/56814
>>
>> John
>> =:->
> 
> 
> +1
> 
> ...
> 
>>      annotation = list(_annotate_file(branch, rev_id, file_id))
>> -    max_origin_len = max(len(origin) for origin in set(x[1] for x in annotation))
>> +    if len(annotation) == 0:
>> +        max_origin_len = 0
>> +    else:
>> +        max_origin_len = max(len(origin) for origin in set(x[1] for x in annotation))
>>      for (revno_str, author, date_str, line_rev_id, text ) in annotation:
> 
> Any reason you didn't go with
> 
> try:
>     max_origin_len = max(len(origin) for origin in set(x[1] for x in annotation))
> except ValueError:
>     max_origin_len = 0
> 
> 
> The former is perhaps clearer, and directly convertable to the 2.5
> conditional expression, but these cases always makes me wonder what
> approach to use.
> 
> Wouter van Heyst

Personally, I believe in checking your data before, rather than waiting
for an exception. I use the latter for stuff like Transport, because
there is a specific performance issue with doing a round trip to
validate. Also, there could be many reasons why the loop might raise a
ValueError, and I only know that I'm fixing 1 case.

Especially something like ValueError, lots of things raise ValueError. I
try to only catch it when there is only one source, so I don't suppress
other bugs.

But that is just me. I could easily be convinced otherwise if there is a
reason.

Oh, and for Transport stuff we have a very rich set of Exceptions. We
don't catch the generic BzrError everywhere, only specific ones that
match a very clear (semi-)failure mode.

John
=:->


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060921/08650bf5/attachment.pgp 


More information about the bazaar mailing list