Skip to content

Commit 55cb10f

Browse files
peffgitster
authored andcommitted
rev-list: make --count work with --objects
The current behavior from "rev-list --count --objects" is nonsensical: we enumerate all of the objects except commits, but then give a count of commits. This wasn't planned, and is just what the code happens to do. Instead, let's give the answer the user almost certainly wanted: the full count of objects. Note that there are more complicated cases around cherry-marking, etc. We'll punt on those for now, but let the user know that we can't produce an answer (rather than giving them something useless). We'll test both the new feature as well as a vanilla --count of commits, since that surprisingly doesn't seem to be covered in the existing tests. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 792f811 commit 55cb10f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

builtin/rev-list.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,19 @@ static int finish_object(struct object *obj, const char *name, void *cb_data)
253253
static void show_object(struct object *obj, const char *name, void *cb_data)
254254
{
255255
struct rev_list_info *info = cb_data;
256+
struct rev_info *revs = info->revs;
257+
256258
if (finish_object(obj, name, cb_data))
257259
return;
258260
display_progress(progress, ++progress_counter);
259261
if (info->flags & REV_LIST_QUIET)
260262
return;
263+
264+
if (revs->count) {
265+
revs->count_right++;
266+
return;
267+
}
268+
261269
if (arg_show_object_names)
262270
show_object_with_name(stdout, obj, name);
263271
else
@@ -584,6 +592,11 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
584592
if (revs.show_notes)
585593
die(_("rev-list does not support display of notes"));
586594

595+
if (revs.count &&
596+
(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
597+
(revs.left_right || revs.cherry_mark))
598+
die(_("marked counting is incompatible with --objects"));
599+
587600
if (filter_options.choice)
588601
use_bitmap_index = 0;
589602

t/t6000-rev-list-misc.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,16 @@ test_expect_success 'rev-list --end-of-options' '
148148
test_cmp expect actual
149149
'
150150

151+
test_expect_success 'rev-list --count' '
152+
count=$(git rev-list --count HEAD) &&
153+
git rev-list HEAD >actual &&
154+
test_line_count = $count actual
155+
'
156+
157+
test_expect_success 'rev-list --count --objects' '
158+
count=$(git rev-list --count --objects HEAD) &&
159+
git rev-list --objects HEAD >actual &&
160+
test_line_count = $count actual
161+
'
162+
151163
test_done

0 commit comments

Comments
 (0)