Skip to content

Commit 608d9c9

Browse files
peffgitster
authored andcommitted
rev-list: allow bitmaps when counting objects
The prior commit taught "--count --objects" to work without bitmaps. We should be able to get the same answer much more quickly with bitmaps. Note that we punt on the max_count case here. This perhaps _could_ be made to work if we find all of the boundary commits and treat them as UNINTERESTING, subtracting them (and their reachable objects) from the set we return. That implies an actual commit traversal, but we'd still be faster due to avoiding opening up any trees. Given the complexity and the fact that anyone is unlikely to want this, it makes sense to just fall back to the non-bitmap case for now. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 55cb10f commit 608d9c9

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

builtin/rev-list.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ static inline int parse_missing_action_value(const char *value)
374374

375375
static int try_bitmap_count(struct rev_info *revs)
376376
{
377-
uint32_t commit_count;
377+
uint32_t commit_count = 0,
378+
tag_count = 0,
379+
tree_count = 0,
380+
blob_count = 0;
378381
int max_count;
379382
struct bitmap_index *bitmap_git;
380383

@@ -389,6 +392,15 @@ static int try_bitmap_count(struct rev_info *revs)
389392
if (revs->left_right || revs->cherry_mark)
390393
return -1;
391394

395+
/*
396+
* If we're counting reachable objects, we can't handle a max count of
397+
* commits to traverse, since we don't know which objects go with which
398+
* commit.
399+
*/
400+
if (revs->max_count >= 0 &&
401+
(revs->tag_objects || revs->tree_objects || revs->blob_objects))
402+
return -1;
403+
392404
/*
393405
* This must be saved before doing any walking, since the revision
394406
* machinery will count it down to zero while traversing.
@@ -399,11 +411,14 @@ static int try_bitmap_count(struct rev_info *revs)
399411
if (!bitmap_git)
400412
return -1;
401413

402-
count_bitmap_commit_list(bitmap_git, &commit_count, NULL, NULL, NULL);
414+
count_bitmap_commit_list(bitmap_git, &commit_count,
415+
revs->tree_objects ? &tree_count : NULL,
416+
revs->blob_objects ? &blob_count : NULL,
417+
revs->tag_objects ? &tag_count : NULL);
403418
if (max_count >= 0 && max_count < commit_count)
404419
commit_count = max_count;
405420

406-
printf("%d\n", commit_count);
421+
printf("%d\n", commit_count + tree_count + blob_count + tag_count);
407422
free_bitmap_index(bitmap_git);
408423
return 0;
409424
}

t/t5310-pack-bitmaps.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ rev_list_tests() {
7474
test_cmp expect actual
7575
'
7676

77+
test_expect_success "counting objects via bitmap ($state)" '
78+
git rev-list --count --objects HEAD >expect &&
79+
git rev-list --use-bitmap-index --count --objects HEAD >actual &&
80+
test_cmp expect actual
81+
'
82+
7783
test_expect_success "enumerate --objects ($state)" '
7884
git rev-list --objects --use-bitmap-index HEAD >tmp &&
7985
cut -d" " -f1 <tmp >tmp2 &&

0 commit comments

Comments
 (0)