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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Feb 14, 2020 at 13:22 UTC
55cb10f9b5cd7216652a5879b792bcd7ac173035
2 files changed
+25
builtin/rev-list.c
+13
@@ -253,11 +253,19 @@ static int finish_object(struct object *obj, const char *name, void *cb_data)
253
static void show_object(struct object *obj, const char *name, void *cb_data)
254
{
255
struct rev_list_info *info = cb_data;
256
+ struct rev_info *revs = info->revs;
257
+
258
if (finish_object(obj, name, cb_data))
259
return;
260
display_progress(progress, ++progress_counter);
261
if (info->flags & REV_LIST_QUIET)
262
return;
263
+
264
+ if (revs->count) {
265
+ revs->count_right++;
266
+ return;
267
+ }
268
+
269
if (arg_show_object_names)
270
show_object_with_name(stdout, obj, name);
271
else
@@ -584,6 +592,11 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
592
if (revs.show_notes)
593
die(_("rev-list does not support display of notes"));
594
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
+
600
if (filter_options.choice)
601
use_bitmap_index = 0;
602
t/t6000-rev-list-misc.sh
+12
@@ -148,4 +148,16 @@ test_expect_success 'rev-list --end-of-options' '
148
test_cmp expect actual
149
'
150
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
+
163
test_done