[MERGE REVIEW] Use InventoryDirectory to represent tree root

John Arbash Meinel john at arbash-meinel.com
Tue Aug 8 00:48:13 BST 2006


Aaron Bentley wrote:

...

     dir_cnt = 0
-    for file_id in work_inv:
-        if work_inv.get_file_kind(file_id) == 'directory':
-            dir_cnt += 1
+    entries = work_inv.iter_entries()
+    entries.next()
+    dir_cnt = len([ie for path, ie in entries if ie.kind == 'directory'])
     print '  %8d versioned %s' \
           % (dir_cnt,
              plural(dir_cnt, 'subdirectory', 'subdirectories'))

Actually, I think the above could be done as:
entries = work_inv.iter_entries()
entries.next()
dir_cnt = sum(1 for path, ie in entries if ie.kind == 'directory')

Which means it doesn't have to build up a list in memory, just to call
len() on it, and then throw it away.
Or you could just do:

dir_cnt = sum(ie.kind == 'directory' for path,ie in entries)

(I checked, you can sum over booleans, but if you don't like it, you
could also do int(ie.kind == 'directory')).

Its kind of a micro-optimization, so it just depends what we think is
clear for the user.

The rest of the changes look good to me.

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/20060807/b7c475fc/attachment.pgp 


More information about the bazaar mailing list