Merge branch 'jk/cat-file-avoid-bitmap-when-unneeded'

Fix for a performance regression in "git cat-file".

* jk/cat-file-avoid-bitmap-when-unneeded:
  cat-file: only use bitmaps when filtering
This commit is contained in:
Junio C Hamano 2026-01-16 12:40:26 -08:00
commit 8c5f0adf21
2 changed files with 19 additions and 3 deletions

View File

@ -846,12 +846,14 @@ static void batch_each_object(struct batch_options *opt,
.callback = callback, .callback = callback,
.payload = _payload, .payload = _payload,
}; };
struct bitmap_index *bitmap = prepare_bitmap_git(the_repository); struct bitmap_index *bitmap = NULL;
for_each_loose_object(the_repository->objects, batch_one_object_loose, &payload, 0); for_each_loose_object(the_repository->objects, batch_one_object_loose, &payload, 0);
if (bitmap && !for_each_bitmapped_object(bitmap, &opt->objects_filter, if (opt->objects_filter.choice != LOFC_DISABLED &&
batch_one_object_bitmapped, &payload)) { (bitmap = prepare_bitmap_git(the_repository)) &&
!for_each_bitmapped_object(bitmap, &opt->objects_filter,
batch_one_object_bitmapped, &payload)) {
struct packed_git *pack; struct packed_git *pack;
repo_for_each_pack(the_repository, pack) { repo_for_each_pack(the_repository, pack) {

View File

@ -9,4 +9,18 @@ test_perf 'cat-file --batch-check' '
git cat-file --batch-all-objects --batch-check git cat-file --batch-all-objects --batch-check
' '
test_perf 'list all objects (sorted)' '
git cat-file --batch-all-objects --batch-check="%(objectname)"
'
test_perf 'list all objects (unsorted)' '
git cat-file --batch-all-objects --batch-check="%(objectname)" \
--unordered
'
test_perf 'list blobs' '
git cat-file --batch-all-objects --batch-check="%(objectname)" \
--unordered --filter=object:type=blob
'
test_done test_done