]> arthur.barton.de Git - bup.git/commitdiff
fix helpers.columnate bug when list is empty
authorGabriel Filion <lelutin@gmail.com>
Sun, 25 Jul 2010 17:34:13 +0000 (13:34 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Mon, 26 Jul 2010 03:09:31 +0000 (23:09 -0400)
When the list given to the columnate function is empty, the function
raises an exception when determining the max(len of all elements), since
the list given to max is empty.

One indirect example of when this bug is apparent is in the 'bup ftp'
command when listing an empty directory:

    bup> ls backupname/latest/etc/keys
    error: max() arg is an empty sequence

Add a special condition at the beginning of the columnate function that
returns an empty string if the list of elements is empty.

Signed-off-by: Gabriel Filion <lelutin@gmail.com>
lib/bup/helpers.py

index 352485951a5684d1b2fbcde206ed27430d38cd4f..65dbc3fd499f63add0bebc55f7dcb6c933846c9e 100644 (file)
@@ -348,6 +348,8 @@ def columnate(l, prefix):
     The number of columns is determined automatically based on the string
     lengths.
     """
+    if not l:
+        return ""
     l = l[:]
     clen = max(len(s) for s in l)
     ncols = (78 - len(prefix)) / (clen + 2)