From 73e996bc79d3693eadad405dda7c7b55a8f7fad9 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Wed, 5 Feb 2020 22:24:01 +0100 Subject: [PATCH] ls: read metadata only if needed 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 Reviewed-by: Rob Browning Tested-by: Rob Browning --- lib/bup/ls.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/bup/ls.py b/lib/bup/ls.py index 2dbe99d..4bd6730 100644 --- a/lib/bup/ls.py +++ b/lib/bup/ls.py @@ -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) -- 2.39.2