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