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

Wouter van Heyst larstiq at larstiq.dyndns.org
Thu Sep 21 22:25:51 BST 2006


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




More information about the bazaar mailing list