@matheusbsbs / matheus-bagliano / commits / 608d9c9365
Fork 0

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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 14, 2020 at 13:22 UTC 608d9c93658d6ec2d585748ed45218cc1f404640
2 files changed +24 -3
builtin/rev-list.c
+18 -3
@@ -374,7 +374,10 @@ static inline int parse_missing_action_value(const char *value)
374
375 static int try_bitmap_count(struct rev_info *revs)
376 {
377 - uint32_t commit_count;
377 + uint32_t commit_count = 0,
378 + tag_count = 0,
379 + tree_count = 0,
380 + blob_count = 0;
381 int max_count;
382 struct bitmap_index *bitmap_git;
383
@@ -389,6 +392,15 @@ static int try_bitmap_count(struct rev_info *revs)
392 if (revs->left_right || revs->cherry_mark)
393 return -1;
394
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 +
404 /*
405 * This must be saved before doing any walking, since the revision
406 * machinery will count it down to zero while traversing.
@@ -399,11 +411,14 @@ static int try_bitmap_count(struct rev_info *revs)
411 if (!bitmap_git)
412 return -1;
413
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);
418 if (max_count >= 0 && max_count < commit_count)
419 commit_count = max_count;
420
406 - printf("%d\n", commit_count);
421 + printf("%d\n", commit_count + tree_count + blob_count + tag_count);
422 free_bitmap_index(bitmap_git);
423 return 0;
424 }
t/t5310-pack-bitmaps.sh
+6
@@ -74,6 +74,12 @@ rev_list_tests() {
74 test_cmp expect actual
75 '
76
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 +
83 test_expect_success "enumerate --objects ($state)" '
84 git rev-list --objects --use-bitmap-index HEAD >tmp &&
85 cut -d" " -f1 <tmp >tmp2 &&