]> arthur.barton.de Git - bup.git/commitdiff
ls: read metadata only if needed
authorJohannes Berg <johannes@sipsolutions.net>
Wed, 5 Feb 2020 21:24:01 +0000 (22:24 +0100)
committerRob Browning <rlb@defaultvalue.org>
Sun, 30 May 2021 17:17:50 +0000 (12:17 -0500)
If we just want to get a list of files, there's no point in
reading metadata, since it simply isn't needed. Pass want_meta
to the appropriate functions only when we need the metadata,
and similarly call vfs.augment_item_meta() only then.

Note that the previous vfs change really made this effective,
we'd otherwise lose the information.

Note also that unfortunately this is necessary even for the
--file-type command line option because otherwise we cannot
identify FIFOs; for everything else the git mode appears to
be sufficient.

Together, this reduces the number of blob reads from 62 to 8
for 'bup ls' on a trivial folder (the bup git's root folder).

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/ls.py

index 2dbe99d67ad5fd078e1f62b41f07e4423df83f28..4bd673022cc8379cd07e2049aaafcfc51ccf98cf 100644 (file)
@@ -114,6 +114,7 @@ def within_repo(repo, opt, out, pwd=b''):
                          human_readable=opt.human_readable)
 
     ret = 0
+    want_meta = bool(opt.long_listing or opt.classification)
     pending = []
     last_n = len(opt.paths) - 1
     for n, printpath in enumerate(opt.paths):
@@ -125,7 +126,7 @@ def within_repo(repo, opt, out, pwd=b''):
             if opt.directory:
                 resolved = vfs.resolve(repo, path, follow=False)
             else:
-                resolved = vfs.try_resolve(repo, path)
+                resolved = vfs.try_resolve(repo, path, want_meta=want_meta)
 
             leaf_name, leaf_item = resolved[-1]
             if not leaf_item:
@@ -135,7 +136,7 @@ def within_repo(repo, opt, out, pwd=b''):
                 ret = 1
                 continue
             if not opt.directory and S_ISDIR(vfs.item_mode(leaf_item)):
-                items = vfs.contents(repo, leaf_item)
+                items = vfs.contents(repo, leaf_item, want_meta=want_meta)
                 if opt.show_hidden == 'all':
                     # Match non-bup "ls -a ... /".
                     parent = resolved[-2] if len(resolved) > 1 else resolved[0]
@@ -149,7 +150,7 @@ def within_repo(repo, opt, out, pwd=b''):
                     if opt.l:
                         sub_item = vfs.ensure_item_has_metadata(repo, sub_item,
                                                                 include_size=True)
-                    else:
+                    elif want_meta:
                         sub_item = vfs.augment_item_meta(repo, sub_item,
                                                          include_size=True)
                     line = item_line(sub_item, sub_name)
@@ -159,8 +160,9 @@ def within_repo(repo, opt, out, pwd=b''):
                         out.write(line)
                         out.write(b'\n')
             else:
-                leaf_item = vfs.augment_item_meta(repo, leaf_item,
-                                                  include_size=True)
+                if opt.long_listing:
+                    leaf_item = vfs.augment_item_meta(repo, leaf_item,
+                                                      include_size=True)
                 line = item_line(leaf_item, os.path.normpath(path))
                 if not opt.long_listing and istty1:
                     pending.append(line)