Skip the --links tests when the object count is zero, and for now have
gc.find_live_objects reject an existing_count of zero, i.e. detecting
an empty repository is the caller's responsibility.
Thanks to Greg Troxel for reporting the problem.
Signed-off-by: Rob Browning <
r...@defaultvalue.org>
Tested-by: Rob Browning <
r...@defaultvalue.org>
---
Pushed to main.
lib/bup/cmd/validate_refs.py | 25 +++++++++++++------------
lib/bup/gc.py | 1 +
test/ext/test-validate-refs | 1 +
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/lib/bup/cmd/validate_refs.py b/lib/bup/cmd/validate_refs.py
index 85f53365..f81b23f7 100644
--- a/lib/bup/cmd/validate_refs.py
+++ b/lib/bup/cmd/validate_refs.py
@@ -129,18 +129,19 @@ def main(argv):
existing_count = count_objects(git.repo(b'objects/pack'), verbosity)
if verbosity:
log(f'found {existing_count} objects\n')
- with ExitStack() as maybe_close_idxl:
- idxl = None
- if opt.links:
- idxl = git.PackIdxList(git.repo(b'objects/pack'))
- maybe_close_idxl.enter_context(idxl)
- live_objs, live_trees_ = \
- find_live_objects(existing_count, cat_pipe,
- refs=ref_info,
- idx_list=idxl,
- for_item=for_item,
- verbosity=verbosity)
- live_objs.close()
+ if existing_count:
+ with ExitStack() as maybe_close_idxl:
+ idxl = None
+ if opt.links:
+ idxl = git.PackIdxList(git.repo(b'objects/pack'))
+ maybe_close_idxl.enter_context(idxl)
+ live_objs, live_trees_ = \
+ find_live_objects(existing_count, cat_pipe,
+ refs=ref_info,
+ idx_list=idxl,
+ for_item=for_item,
+ verbosity=verbosity)
+ live_objs.close()
if bad_bupm:
return EXIT_FAILURE
if (ref_missing + found_missing + abridged_bupm):
diff --git a/lib/bup/gc.py b/lib/bup/gc.py
index 5ff5de3b..7ca2c280 100644
--- a/lib/bup/gc.py
+++ b/lib/bup/gc.py
@@ -85,6 +85,7 @@ def find_live_objects(existing_count, cat_pipe, refs=None, *,
# has been provided and does not return True, then a MissingObject
# will be raised. If idx_list is provided, then existence checks
# will be broad.
+ assert existing_count > 0, existing_count
pack_dir = git.repo(b'objects/pack')
ffd, bloom_filename = tempfile.mkstemp(b'.bloom', b'tmp-gc-', pack_dir)
os.close(ffd)
diff --git a/test/ext/test-validate-refs b/test/ext/test-validate-refs
index 41d15190..b8bc38ab 100755
--- a/test/ext/test-validate-refs
+++ b/test/ext/test-validate-refs
@@ -21,6 +21,7 @@ WVPASS cd "$tmpdir"
WVSTART 'handling of correct refs'
WVPASS rm -rf bup src
WVPASS bup init
+WVPASS bup validate-refs
WVPASS git config bup.split.trees true
WVPASS mkdir src
WVPASS mkdir -p src/a/b
--
2.47.3