]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/rev-list.c
Merge branch 'jk/rev-list-disk-usage'
[thirdparty/git.git] / builtin / rev-list.c
CommitLineData
64745109 1#include "cache.h"
b2141fc1 2#include "config.h"
64745109 3#include "commit.h"
c4e05b1a 4#include "diff.h"
ae563542 5#include "revision.h"
c64ed70d 6#include "list-objects.h"
caf3827e
JH
7#include "list-objects-filter.h"
8#include "list-objects-filter-options.h"
7c0fe330 9#include "object.h"
cbd53a21 10#include "object-store.h"
aa32939f
VM
11#include "pack.h"
12#include "pack-bitmap.h"
5fb61b8d 13#include "builtin.h"
50e62a8e 14#include "log-tree.h"
7fefda5c 15#include "graph.h"
a2ad79ce 16#include "bisect.h"
434ea3cd 17#include "progress.h"
7f97de5e 18#include "reflog-walk.h"
caf3827e 19#include "oidset.h"
df11e196 20#include "packfile.h"
8906300f 21
a6f68d47 22static const char rev_list_usage[] =
1b1dd23f 23"git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
69e0c256 24" limiting output:\n"
62b4698e
ŠN
25" --max-count=<n>\n"
26" --max-age=<epoch>\n"
27" --min-age=<epoch>\n"
69e0c256
JH
28" --sparse\n"
29" --no-merges\n"
ad5aeede
MG
30" --min-parents=<n>\n"
31" --no-min-parents\n"
32" --max-parents=<n>\n"
33" --no-max-parents\n"
93b74bca 34" --remove-empty\n"
69e0c256 35" --all\n"
a5aa930d
UKK
36" --branches\n"
37" --tags\n"
38" --remotes\n"
42cabc34 39" --stdin\n"
27350891 40" --quiet\n"
69e0c256 41" ordering output:\n"
69e0c256 42" --topo-order\n"
4c8725f1 43" --date-order\n"
7ccd3667 44" --reverse\n"
69e0c256
JH
45" formatting output:\n"
46" --parents\n"
72276a3e 47" --children\n"
c6496575 48" --objects | --objects-edge\n"
69e0c256
JH
49" --unpacked\n"
50" --header | --pretty\n"
42357b4e 51" --[no-]object-names\n"
62b4698e 52" --abbrev=<n> | --no-abbrev\n"
5c51c985 53" --abbrev-commit\n"
b24bace5 54" --left-right\n"
75d2e5a7 55" --count\n"
69e0c256 56" special purpose:\n"
457f08a0 57" --bisect\n"
50e62a8e
CC
58" --bisect-vars\n"
59" --bisect-all"
69e0c256 60;
a6f68d47 61
434ea3cd
JK
62static struct progress *progress;
63static unsigned progress_counter;
64
caf3827e
JH
65static struct list_objects_filter_options filter_options;
66static struct oidset omitted_objects;
67static int arg_print_omitted; /* print objects omitted by filter */
68
69static struct oidset missing_objects;
70enum missing_action {
71 MA_ERROR = 0, /* fail if any missing objects are encountered */
72 MA_ALLOW_ANY, /* silently allow ALL missing objects */
73 MA_PRINT, /* print ALL missing objects in special section */
df11e196 74 MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */
caf3827e
JH
75};
76static enum missing_action arg_missing_action;
77
42357b4e
ES
78/* display only the oid of each object encountered */
79static int arg_show_object_names = 1;
80
caf3827e
JH
81#define DEFAULT_OIDSET_SIZE (16*1024)
82
16950f83
JK
83static int show_disk_usage;
84static off_t total_disk_usage;
85
86static off_t get_object_disk_usage(struct object *obj)
87{
88 off_t size;
89 struct object_info oi = OBJECT_INFO_INIT;
90 oi.disk_sizep = &size;
91 if (oid_object_info_extended(the_repository, &obj->oid, &oi, 0) < 0)
92 die(_("unable to get disk usage of %s"), oid_to_hex(&obj->oid));
93 return size;
94}
95
d92349dd 96static void finish_commit(struct commit *commit);
11c211fa 97static void show_commit(struct commit *commit, void *data)
81f2bb1f 98{
d797257e
CC
99 struct rev_list_info *info = data;
100 struct rev_info *revs = info->revs;
11c211fa 101
434ea3cd
JK
102 display_progress(progress, ++progress_counter);
103
16950f83
JK
104 if (show_disk_usage)
105 total_disk_usage += get_object_disk_usage(&commit->object);
106
98993722 107 if (info->flags & REV_LIST_QUIET) {
d92349dd 108 finish_commit(commit);
98993722
NTND
109 return;
110 }
111
11c211fa 112 graph_show_commit(revs->graph);
7fefda5c 113
f69c5018 114 if (revs->count) {
b388e14b
MG
115 if (commit->object.flags & PATCHSAME)
116 revs->count_same++;
117 else if (commit->object.flags & SYMMETRIC_LEFT)
f69c5018
TR
118 revs->count_left++;
119 else
120 revs->count_right++;
d92349dd 121 finish_commit(commit);
f69c5018
TR
122 return;
123 }
124
d797257e 125 if (info->show_timestamp)
cb71f8bd 126 printf("%"PRItime" ", commit->date);
d797257e
CC
127 if (info->header_prefix)
128 fputs(info->header_prefix, stdout);
7528f27d 129
1df2d656
MG
130 if (!revs->graph)
131 fputs(get_revision_mark(revs, commit), stdout);
11c211fa 132 if (revs->abbrev_commit && revs->abbrev)
aab9583f 133 fputs(find_unique_abbrev(&commit->object.oid, revs->abbrev),
7594c4b2 134 stdout);
5c51c985 135 else
f2fd0760 136 fputs(oid_to_hex(&commit->object.oid), stdout);
11c211fa 137 if (revs->print_parents) {
81f2bb1f
LT
138 struct commit_list *parents = commit->parents;
139 while (parents) {
f2fd0760 140 printf(" %s", oid_to_hex(&parents->item->object.oid));
81f2bb1f
LT
141 parents = parents->next;
142 }
143 }
11c211fa 144 if (revs->children.name) {
72276a3e
JH
145 struct commit_list *children;
146
11c211fa 147 children = lookup_decoration(&revs->children, &commit->object);
72276a3e 148 while (children) {
f2fd0760 149 printf(" %s", oid_to_hex(&children->item->object.oid));
72276a3e
JH
150 children = children->next;
151 }
152 }
11c211fa
CC
153 show_decorations(revs, commit);
154 if (revs->commit_format == CMIT_FMT_ONELINE)
d87449c5
JH
155 putchar(' ');
156 else
157 putchar('\n');
158
7fa31b64 159 if (revs->verbose_header) {
f285a2d7 160 struct strbuf buf = STRBUF_INIT;
dd2e794a
TR
161 struct pretty_print_context ctx = {0};
162 ctx.abbrev = revs->abbrev;
163 ctx.date_mode = revs->date_mode;
f026c756 164 ctx.date_mode_explicit = revs->date_mode_explicit;
6bf13944 165 ctx.fmt = revs->commit_format;
ecaee805 166 ctx.output_encoding = get_log_output_encoding();
d75dfb10 167 ctx.color = revs->diffopt.use_color;
6bf13944 168 pretty_print_commit(&ctx, commit, &buf);
660e113c
JK
169 if (buf.len) {
170 if (revs->commit_format != CMIT_FMT_ONELINE)
171 graph_show_oneline(revs->graph);
7fefda5c 172
660e113c 173 graph_show_commit_msg(revs->graph, stdout, &buf);
7fefda5c 174
660e113c
JK
175 /*
176 * Add a newline after the commit message.
177 *
178 * Usually, this newline produces a blank
179 * padding line between entries, in which case
180 * we need to add graph padding on this line.
181 *
182 * However, the commit message may not end in a
183 * newline. In this case the newline simply
184 * ends the last line of the commit message,
185 * and we don't need any graph output. (This
186 * always happens with CMIT_FMT_ONELINE, and it
187 * happens with CMIT_FMT_USERFORMAT when the
188 * format doesn't explicitly end in a newline.)
189 */
190 if (buf.len && buf.buf[buf.len - 1] == '\n')
191 graph_show_padding(revs->graph);
98985c69 192 putchar(info->hdr_termination);
7fefda5c 193 } else {
660e113c
JK
194 /*
195 * If the message buffer is empty, just show
196 * the rest of the graph output for this
197 * commit.
198 */
199 if (graph_show_remainder(revs->graph))
200 putchar('\n');
201 if (revs->commit_format == CMIT_FMT_ONELINE)
202 putchar('\n');
7fefda5c 203 }
674d1727 204 strbuf_release(&buf);
7fefda5c 205 } else {
11c211fa 206 if (graph_show_remainder(revs->graph))
7fefda5c 207 putchar('\n');
7620d39f 208 }
06f59e9f 209 maybe_flush_or_die(stdout, "stdout");
d92349dd 210 finish_commit(commit);
27350891
SP
211}
212
d92349dd 213static void finish_commit(struct commit *commit)
27350891 214{
cb115748
LT
215 if (commit->parents) {
216 free_commit_list(commit->parents);
217 commit->parents = NULL;
218 }
6a7895fd
SB
219 free_commit_buffer(the_repository->parsed_objects,
220 commit);
a3437b8c
JS
221}
222
caf3827e
JH
223static inline void finish_object__ma(struct object *obj)
224{
df11e196
JT
225 /*
226 * Whether or not we try to dynamically fetch missing objects
227 * from the server, we currently DO NOT have the object. We
228 * can either print, allow (ignore), or conditionally allow
229 * (ignore) them.
230 */
caf3827e
JH
231 switch (arg_missing_action) {
232 case MA_ERROR:
7c0fe330
MD
233 die("missing %s object '%s'",
234 type_name(obj->type), oid_to_hex(&obj->oid));
caf3827e
JH
235 return;
236
237 case MA_ALLOW_ANY:
238 return;
239
240 case MA_PRINT:
241 oidset_insert(&missing_objects, &obj->oid);
242 return;
243
df11e196
JT
244 case MA_ALLOW_PROMISOR:
245 if (is_promisor_object(&obj->oid))
246 return;
7c0fe330
MD
247 die("unexpected missing %s object '%s'",
248 type_name(obj->type), oid_to_hex(&obj->oid));
df11e196
JT
249 return;
250
caf3827e
JH
251 default:
252 BUG("unhandled missing_action");
253 return;
254 }
255}
256
df11e196 257static int finish_object(struct object *obj, const char *name, void *cb_data)
27350891 258{
98993722 259 struct rev_list_info *info = cb_data;
f06ab027 260 if (oid_object_info_extended(the_repository, &obj->oid, NULL, 0) < 0) {
caf3827e 261 finish_object__ma(obj);
df11e196
JT
262 return 1;
263 }
98993722 264 if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
109cd76d 265 parse_object(the_repository, &obj->oid);
df11e196 266 return 0;
27350891
SP
267}
268
de1e67d0 269static void show_object(struct object *obj, const char *name, void *cb_data)
9de48752 270{
cb8da705 271 struct rev_list_info *info = cb_data;
55cb10f9
JK
272 struct rev_info *revs = info->revs;
273
df11e196
JT
274 if (finish_object(obj, name, cb_data))
275 return;
434ea3cd 276 display_progress(progress, ++progress_counter);
16950f83
JK
277 if (show_disk_usage)
278 total_disk_usage += get_object_disk_usage(obj);
98993722
NTND
279 if (info->flags & REV_LIST_QUIET)
280 return;
55cb10f9
JK
281
282 if (revs->count) {
20a5fd88
JH
283 /*
284 * The object count is always accumulated in the .count_right
285 * field for traversal that is not a left-right traversal,
286 * and cmd_rev_list() made sure that a .count request that
287 * wants to count non-commit objects, which is handled by
288 * the show_object() callback, does not ask for .left_right.
289 */
55cb10f9
JK
290 revs->count_right++;
291 return;
292 }
293
42357b4e
ES
294 if (arg_show_object_names)
295 show_object_with_name(stdout, obj, name);
296 else
297 printf("%s\n", oid_to_hex(&obj->oid));
9de48752
LT
298}
299
8d1d8f83
JH
300static void show_edge(struct commit *commit)
301{
f2fd0760 302 printf("-%s\n", oid_to_hex(&commit->object.oid));
8d1d8f83
JH
303}
304
38ef7507 305static void print_var_str(const char *var, const char *val)
280e65cb 306{
38ef7507 307 printf("%s='%s'\n", var, val);
280e65cb
CC
308}
309
38ef7507 310static void print_var_int(const char *var, int val)
280e65cb 311{
38ef7507 312 printf("%s=%d\n", var, val);
280e65cb
CC
313}
314
f1c92c63 315static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
9996983c 316{
98993722 317 int cnt, flags = info->flags;
dc01505f 318 char hex[GIT_MAX_HEXSZ + 1] = "";
95188648 319 struct commit_list *tried;
d797257e 320 struct rev_info *revs = info->revs;
9996983c 321
8ba8fe04 322 if (!revs->commits)
9996983c
CC
323 return 1;
324
9af3589e
CC
325 revs->commits = filter_skipped(revs->commits, &tried,
326 flags & BISECT_SHOW_ALL,
327 NULL, NULL);
95188648 328
9996983c 329 /*
7428d754 330 * revs->commits can reach "reaches" commits among
9996983c
CC
331 * "all" commits. If it is good, then there are
332 * (all-reaches) commits left to be bisected.
333 * On the other hand, if it is bad, then the set
334 * to bisect is "reaches".
335 * A bisect set of size N has (N-1) commits further
336 * to test, as we already know one bad one.
337 */
338 cnt = all - reaches;
339 if (cnt < reaches)
340 cnt = reaches;
6a17fad7 341
95188648 342 if (revs->commits)
2490574d 343 oid_to_hex_r(hex, &revs->commits->item->object.oid);
9996983c 344
37c4c38d 345 if (flags & BISECT_SHOW_ALL) {
d797257e 346 traverse_commit_list(revs, show_commit, show_object, info);
9996983c
CC
347 printf("------\n");
348 }
349
38ef7507
CC
350 print_var_str("bisect_rev", hex);
351 print_var_int("bisect_nr", cnt - 1);
352 print_var_int("bisect_good", all - reaches - 1);
353 print_var_int("bisect_bad", reaches - 1);
354 print_var_int("bisect_all", all);
355 print_var_int("bisect_steps", estimate_bisect_steps(all));
9996983c
CC
356
357 return 0;
358}
359
aa32939f 360static int show_object_fast(
20664967 361 const struct object_id *oid,
aa32939f
VM
362 enum object_type type,
363 int exclude,
364 uint32_t name_hash,
365 struct packed_git *found_pack,
366 off_t found_offset)
367{
20664967 368 fprintf(stdout, "%s\n", oid_to_hex(oid));
aa32939f
VM
369 return 1;
370}
371
caf3827e
JH
372static inline int parse_missing_action_value(const char *value)
373{
374 if (!strcmp(value, "error")) {
375 arg_missing_action = MA_ERROR;
376 return 1;
377 }
378
379 if (!strcmp(value, "allow-any")) {
380 arg_missing_action = MA_ALLOW_ANY;
df11e196 381 fetch_if_missing = 0;
caf3827e
JH
382 return 1;
383 }
384
385 if (!strcmp(value, "print")) {
386 arg_missing_action = MA_PRINT;
df11e196
JT
387 fetch_if_missing = 0;
388 return 1;
389 }
390
391 if (!strcmp(value, "allow-promisor")) {
392 arg_missing_action = MA_ALLOW_PROMISOR;
393 fetch_if_missing = 0;
caf3827e
JH
394 return 1;
395 }
396
397 return 0;
398}
399
2aaeb9ac
JK
400static int try_bitmap_count(struct rev_info *revs,
401 struct list_objects_filter_options *filter)
792f8119 402{
608d9c93
JK
403 uint32_t commit_count = 0,
404 tag_count = 0,
405 tree_count = 0,
406 blob_count = 0;
792f8119
JK
407 int max_count;
408 struct bitmap_index *bitmap_git;
409
410 /* This function only handles counting, not general traversal. */
411 if (!revs->count)
412 return -1;
413
414 /*
415 * A bitmap result can't know left/right, etc, because we don't
416 * actually traverse.
417 */
418 if (revs->left_right || revs->cherry_mark)
419 return -1;
420
608d9c93
JK
421 /*
422 * If we're counting reachable objects, we can't handle a max count of
423 * commits to traverse, since we don't know which objects go with which
424 * commit.
425 */
426 if (revs->max_count >= 0 &&
427 (revs->tag_objects || revs->tree_objects || revs->blob_objects))
428 return -1;
429
792f8119
JK
430 /*
431 * This must be saved before doing any walking, since the revision
432 * machinery will count it down to zero while traversing.
433 */
434 max_count = revs->max_count;
435
2aaeb9ac 436 bitmap_git = prepare_bitmap_walk(revs, filter);
792f8119
JK
437 if (!bitmap_git)
438 return -1;
439
608d9c93
JK
440 count_bitmap_commit_list(bitmap_git, &commit_count,
441 revs->tree_objects ? &tree_count : NULL,
442 revs->blob_objects ? &blob_count : NULL,
443 revs->tag_objects ? &tag_count : NULL);
792f8119
JK
444 if (max_count >= 0 && max_count < commit_count)
445 commit_count = max_count;
446
608d9c93 447 printf("%d\n", commit_count + tree_count + blob_count + tag_count);
792f8119
JK
448 free_bitmap_index(bitmap_git);
449 return 0;
450}
451
2aaeb9ac
JK
452static int try_bitmap_traversal(struct rev_info *revs,
453 struct list_objects_filter_options *filter)
792f8119
JK
454{
455 struct bitmap_index *bitmap_git;
456
457 /*
458 * We can't use a bitmap result with a traversal limit, since the set
459 * of commits we'd get would be essentially random.
460 */
461 if (revs->max_count >= 0)
462 return -1;
463
2aaeb9ac 464 bitmap_git = prepare_bitmap_walk(revs, filter);
792f8119
JK
465 if (!bitmap_git)
466 return -1;
467
4eb707eb 468 traverse_bitmap_commit_list(bitmap_git, revs, &show_object_fast);
792f8119
JK
469 free_bitmap_index(bitmap_git);
470 return 0;
471}
472
16950f83
JK
473static int try_bitmap_disk_usage(struct rev_info *revs,
474 struct list_objects_filter_options *filter)
475{
476 struct bitmap_index *bitmap_git;
477
478 if (!show_disk_usage)
479 return -1;
480
481 bitmap_git = prepare_bitmap_walk(revs, filter);
482 if (!bitmap_git)
483 return -1;
484
485 printf("%"PRIuMAX"\n",
486 (uintmax_t)get_disk_usage_from_bitmap(bitmap_git, revs));
487 return 0;
488}
489
a633fca0 490int cmd_rev_list(int argc, const char **argv, const char *prefix)
64745109 491{
11c211fa 492 struct rev_info revs;
d797257e 493 struct rev_list_info info;
bbcde41a
MD
494 struct setup_revision_opt s_r_opt = {
495 .allow_exclude_promisor_objects = 1,
496 };
d9a83684 497 int i;
ff62d732 498 int bisect_list = 0;
457f08a0 499 int bisect_show_vars = 0;
50e62a8e 500 int bisect_find_all = 0;
aa32939f 501 int use_bitmap_index = 0;
434ea3cd 502 const char *show_progress = NULL;
64745109 503
5a88f97c
JH
504 if (argc == 2 && !strcmp(argv[1], "-h"))
505 usage(rev_list_usage);
506
ef90d6d4 507 git_config(git_default_config, NULL);
2abf3503 508 repo_init_revisions(the_repository, &revs, prefix);
7337b138 509 revs.abbrev = DEFAULT_ABBREV;
7594c4b2 510 revs.commit_format = CMIT_FMT_UNSPECIFIED;
df11e196
JT
511
512 /*
513 * Scan the argument list before invoking setup_revisions(), so that we
514 * know if fetch_if_missing needs to be set to 0.
515 *
516 * "--exclude-promisor-objects" acts as a pre-filter on missing objects
517 * by not crossing the boundary from realized objects to promisor
518 * objects.
519 *
520 * Let "--missing" to conditionally set fetch_if_missing.
521 */
522 for (i = 1; i < argc; i++) {
523 const char *arg = argv[i];
524 if (!strcmp(arg, "--exclude-promisor-objects")) {
525 fetch_if_missing = 0;
526 revs.exclude_promisor_objects = 1;
527 break;
528 }
529 }
530 for (i = 1; i < argc; i++) {
531 const char *arg = argv[i];
532 if (skip_prefix(arg, "--missing=", &arg)) {
533 if (revs.exclude_promisor_objects)
534 die(_("cannot combine --exclude-promisor-objects and --missing"));
535 if (parse_missing_action_value(arg))
536 break;
537 }
538 }
539
ee4dfee2
JK
540 if (arg_missing_action)
541 revs.do_not_die_on_missing_tree = 1;
542
bbcde41a 543 argc = setup_revisions(argc, argv, &revs, &s_r_opt);
ae563542 544
d797257e
CC
545 memset(&info, 0, sizeof(info));
546 info.revs = &revs;
ad3f9a71
LT
547 if (revs.bisect)
548 bisect_list = 1;
d797257e 549
0d1e0e78 550 if (revs.diffopt.flags.quick)
98993722 551 info.flags |= REV_LIST_QUIET;
fcfda02b 552 for (i = 1 ; i < argc; i++) {
cf484544 553 const char *arg = argv[i];
fcfda02b 554
a6f68d47 555 if (!strcmp(arg, "--header")) {
7594c4b2 556 revs.verbose_header = 1;
9d97aa64
LT
557 continue;
558 }
dc68c4ff 559 if (!strcmp(arg, "--timestamp")) {
d797257e 560 info.show_timestamp = 1;
dc68c4ff
JH
561 continue;
562 }
8b3a1e05
LT
563 if (!strcmp(arg, "--bisect")) {
564 bisect_list = 1;
565 continue;
566 }
50e62a8e
CC
567 if (!strcmp(arg, "--bisect-all")) {
568 bisect_list = 1;
569 bisect_find_all = 1;
98993722 570 info.flags |= BISECT_SHOW_ALL;
6e46cc0d 571 revs.show_decorations = 1;
50e62a8e
CC
572 continue;
573 }
457f08a0
JH
574 if (!strcmp(arg, "--bisect-vars")) {
575 bisect_list = 1;
576 bisect_show_vars = 1;
577 continue;
578 }
aa32939f
VM
579 if (!strcmp(arg, "--use-bitmap-index")) {
580 use_bitmap_index = 1;
581 continue;
582 }
583 if (!strcmp(arg, "--test-bitmap")) {
584 test_bitmap_walk(&revs);
585 return 0;
586 }
434ea3cd
JK
587 if (skip_prefix(arg, "--progress=", &arg)) {
588 show_progress = arg;
589 continue;
590 }
caf3827e
JH
591
592 if (skip_prefix(arg, ("--" CL_ARG__FILTER "="), &arg)) {
593 parse_list_objects_filter(&filter_options, arg);
594 if (filter_options.choice && !revs.blob_objects)
595 die(_("object filtering requires --objects"));
caf3827e
JH
596 continue;
597 }
f4371a88 598 if (!strcmp(arg, ("--no-" CL_ARG__FILTER))) {
aa57b871 599 list_objects_filter_set_no_filter(&filter_options);
f4371a88
JH
600 continue;
601 }
caf3827e
JH
602 if (!strcmp(arg, "--filter-print-omitted")) {
603 arg_print_omitted = 1;
604 continue;
605 }
606
df11e196
JT
607 if (!strcmp(arg, "--exclude-promisor-objects"))
608 continue; /* already handled above */
609 if (skip_prefix(arg, "--missing=", &arg))
610 continue; /* already handled above */
caf3827e 611
42357b4e
ES
612 if (!strcmp(arg, ("--no-object-names"))) {
613 arg_show_object_names = 0;
614 continue;
615 }
616
617 if (!strcmp(arg, ("--object-names"))) {
618 arg_show_object_names = 1;
619 continue;
620 }
621
16950f83
JK
622 if (!strcmp(arg, "--disk-usage")) {
623 show_disk_usage = 1;
624 info.flags |= REV_LIST_QUIET;
625 continue;
626 }
627
ae563542 628 usage(rev_list_usage);
a6f68d47 629
fcfda02b 630 }
7594c4b2
JH
631 if (revs.commit_format != CMIT_FMT_UNSPECIFIED) {
632 /* The command line has a --pretty */
d797257e 633 info.hdr_termination = '\n';
7594c4b2 634 if (revs.commit_format == CMIT_FMT_ONELINE)
d797257e 635 info.header_prefix = "";
7594c4b2 636 else
d797257e 637 info.header_prefix = "commit ";
7594c4b2 638 }
db89665f
JH
639 else if (revs.verbose_header)
640 /* Only --header was specified */
641 revs.commit_format = CMIT_FMT_RAW;
fcfda02b 642
7f97de5e 643 if ((!revs.commits && reflog_walk_empty(revs.reflog_info) &&
c01499ef 644 (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
0159ba32 645 !revs.pending.nr) &&
a12cbe23 646 !revs.rev_input_given && !revs.read_from_stdin) ||
8c1f0b44 647 revs.diff)
7b34c2fa
LT
648 usage(rev_list_usage);
649
2aea7a51
JK
650 if (revs.show_notes)
651 die(_("rev-list does not support display of notes"));
652
55cb10f9
JK
653 if (revs.count &&
654 (revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
655 (revs.left_right || revs.cherry_mark))
656 die(_("marked counting is incompatible with --objects"));
657
80235ba7
JH
658 save_commit_buffer = (revs.verbose_header ||
659 revs.grep_filter.pattern_list ||
660 revs.grep_filter.header_list);
4e1dc640
JH
661 if (bisect_list)
662 revs.limited = 1;
9181ca2c 663
434ea3cd 664 if (show_progress)
8aade107 665 progress = start_delayed_progress(show_progress, 0);
434ea3cd 666
d90fe06e 667 if (use_bitmap_index) {
2aaeb9ac 668 if (!try_bitmap_count(&revs, &filter_options))
792f8119 669 return 0;
16950f83
JK
670 if (!try_bitmap_disk_usage(&revs, &filter_options))
671 return 0;
2aaeb9ac 672 if (!try_bitmap_traversal(&revs, &filter_options))
792f8119 673 return 0;
aa32939f
VM
674 }
675
3d51e1b5
MK
676 if (prepare_revision_walk(&revs))
677 die("revision walk setup failed");
a4a88b2b 678 if (revs.tree_objects)
4f6d26b1 679 mark_edges_uninteresting(&revs, show_edge, 0);
a4a88b2b 680
457f08a0 681 if (bisect_list) {
156e1782 682 int reaches, all;
ad464a4e 683 unsigned bisect_flags = 0;
457f08a0 684
ad464a4e
AL
685 if (bisect_find_all)
686 bisect_flags |= FIND_BISECTION_ALL;
687
688 if (revs.first_parent_only)
689 bisect_flags |= FIND_BISECTION_FIRST_PARENT_ONLY;
690
691 find_bisection(&revs.commits, &reaches, &all, bisect_flags);
95188648 692
9996983c 693 if (bisect_show_vars)
13858e57 694 return show_bisect_vars(&info, reaches, all);
457f08a0 695 }
7b34c2fa 696
caf3827e
JH
697 if (arg_print_omitted)
698 oidset_init(&omitted_objects, DEFAULT_OIDSET_SIZE);
699 if (arg_missing_action == MA_PRINT)
700 oidset_init(&missing_objects, DEFAULT_OIDSET_SIZE);
701
702 traverse_commit_list_filtered(
703 &filter_options, &revs, show_commit, show_object, &info,
704 (arg_print_omitted ? &omitted_objects : NULL));
705
706 if (arg_print_omitted) {
707 struct oidset_iter iter;
708 struct object_id *oid;
709 oidset_iter_init(&omitted_objects, &iter);
710 while ((oid = oidset_iter_next(&iter)))
711 printf("~%s\n", oid_to_hex(oid));
712 oidset_clear(&omitted_objects);
713 }
714 if (arg_missing_action == MA_PRINT) {
715 struct oidset_iter iter;
716 struct object_id *oid;
717 oidset_iter_init(&missing_objects, &iter);
718 while ((oid = oidset_iter_next(&iter)))
719 printf("?%s\n", oid_to_hex(oid));
720 oidset_clear(&missing_objects);
721 }
8906300f 722
434ea3cd
JK
723 stop_progress(&progress);
724
f69c5018 725 if (revs.count) {
b388e14b
MG
726 if (revs.left_right && revs.cherry_mark)
727 printf("%d\t%d\t%d\n", revs.count_left, revs.count_right, revs.count_same);
728 else if (revs.left_right)
f69c5018 729 printf("%d\t%d\n", revs.count_left, revs.count_right);
b388e14b
MG
730 else if (revs.cherry_mark)
731 printf("%d\t%d\n", revs.count_left + revs.count_right, revs.count_same);
f69c5018
TR
732 else
733 printf("%d\n", revs.count_left + revs.count_right);
734 }
735
16950f83
JK
736 if (show_disk_usage)
737 printf("%"PRIuMAX"\n", (uintmax_t)total_disk_usage);
738
64745109
LT
739 return 0;
740}