Skip to content

Commit dd9b30f

Browse files
committed
Merge branch 'jk/rev-list-count-with-bitmap' into next
"git rev-list --count" whose walk-length is limited with "-n" option did not work well with the counting optimized to look at the bitmap index. * jk/rev-list-count-with-bitmap: rev-list: disable bitmaps when "-n" is used with listing objects rev-list: "adjust" results of "--count --use-bitmap-index -n"
2 parents 536102f + fb85db8 commit dd9b30f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

builtin/rev-list.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,16 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
358358
if (use_bitmap_index && !revs.prune) {
359359
if (revs.count && !revs.left_right && !revs.cherry_mark) {
360360
uint32_t commit_count;
361+
int max_count = revs.max_count;
361362
if (!prepare_bitmap_walk(&revs)) {
362363
count_bitmap_commit_list(&commit_count, NULL, NULL, NULL);
364+
if (max_count >= 0 && max_count < commit_count)
365+
commit_count = max_count;
363366
printf("%d\n", commit_count);
364367
return 0;
365368
}
366-
} else if (revs.tag_objects && revs.tree_objects && revs.blob_objects) {
369+
} else if (revs.max_count < 0 &&
370+
revs.tag_objects && revs.tree_objects && revs.blob_objects) {
367371
if (!prepare_bitmap_walk(&revs)) {
368372
traverse_bitmap_commit_list(&show_object_fast);
369373
return 0;

t/t5310-pack-bitmaps.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ rev_list_tests() {
4747
test_cmp expect actual
4848
'
4949

50+
test_expect_success "counting commits with limit ($state)" '
51+
git rev-list --count -n 1 HEAD >expect &&
52+
git rev-list --use-bitmap-index --count -n 1 HEAD >actual &&
53+
test_cmp expect actual
54+
'
55+
5056
test_expect_success "counting non-linear history ($state)" '
5157
git rev-list --count other...master >expect &&
5258
git rev-list --use-bitmap-index --count other...master >actual &&

0 commit comments

Comments
 (0)