at commit a0189536

1 #define USE_THE_REPOSITORY_VARIABLE
2 #define DISABLE_SIGN_COMPARE_WARNINGS
3
4 #include "builtin.h"
5 #include "config.h"
6 #include "commit.h"
7 #include "diff.h"
8 #include "environment.h"
9 #include "gettext.h"
10 #include "hex.h"
11 #include "revision.h"
12 #include "list-objects.h"
13 #include "list-objects-filter-options.h"
14 #include "object.h"
15 #include "object-name.h"
16 #include "object-file.h"
17 #include "odb.h"
18 #include "pack-bitmap.h"
19 #include "parse-options.h"
20 #include "log-tree.h"
21 #include "graph.h"
22 #include "bisect.h"
23 #include "progress.h"
24 #include "reflog-walk.h"
25 #include "oidset.h"
26 #include "oidmap.h"
27 #include "packfile.h"
28 #include "commit-reach.h"
29 #include "quote.h"
30 #include "strbuf.h"
31
32 struct rev_list_info {
33 struct rev_info *revs;
34 int flags;
35 int show_timestamp;
36 int hdr_termination;
37 const char *header_prefix;
38 };
39
40 static const char rev_list_usage[] =
41 "git rev-list [<options>] <commit>... [--] [<path>...]\n"
42 "\n"
43 " limiting output:\n"
44 " --max-count=<n>\n"
45 " --max-age=<epoch>\n"
46 " --min-age=<epoch>\n"
47 " --sparse\n"
48 " --no-merges\n"
49 " --min-parents=<n>\n"
50 " --no-min-parents\n"
51 " --max-parents=<n>\n"
52 " --no-max-parents\n"
53 " --remove-empty\n"
54 " --all\n"
55 " --branches\n"
56 " --tags\n"
57 " --remotes\n"
58 " --stdin\n"
59 " --exclude-hidden=[fetch|receive|uploadpack]\n"
60 " --quiet\n"
61 " ordering output:\n"
62 " --topo-order\n"
63 " --date-order\n"
64 " --reverse\n"
65 " formatting output:\n"
66 " --parents\n"
67 " --children\n"
68 " --objects | --objects-edge\n"
69 " --disk-usage[=human]\n"
70 " --unpacked\n"
71 " --header | --pretty\n"
72 " --[no-]object-names\n"
73 " --abbrev=<n> | --no-abbrev\n"
74 " --abbrev-commit\n"
75 " --left-right\n"
76 " --count\n"
77 " -z\n"
78 " special purpose:\n"
79 " --bisect\n"
80 " --bisect-vars\n"
81 " --bisect-all"
82 ;
83
84 static struct progress *progress;
85 static unsigned progress_counter;
86
87 static struct oidset omitted_objects;
88 static int arg_print_omitted; /* print objects omitted by filter */
89
90 struct missing_objects_map_entry {
91 struct oidmap_entry entry;
92 char *path;
93 unsigned type;
94 };
95
96 static void missing_objects_map_entry_free(void *e)
97 {
98 struct missing_objects_map_entry *entry =
99 container_of(e, struct missing_objects_map_entry, entry);
100
101 free(entry->path);
102 free(entry);
103 }
104
105 static struct oidmap missing_objects;
106 enum missing_action {
107 MA_ERROR = 0, /* fail if any missing objects are encountered */
108 MA_ALLOW_ANY, /* silently allow ALL missing objects */
109 MA_PRINT, /* print ALL missing objects in special section */
110 MA_PRINT_INFO, /* same as MA_PRINT but also prints missing object info */
111 MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */
112 };
113 static enum missing_action arg_missing_action;
114 static int arg_missing_only;
115
116 static inline int should_collect_missing(void)
117 {
118 return arg_missing_action == MA_PRINT ||
119 arg_missing_action == MA_PRINT_INFO;
120 }
121
122 /* display only the oid of each object encountered */
123 static int arg_show_object_names = 1;
124
125 #define DEFAULT_OIDSET_SIZE (16*1024)
126
127 static char line_term = '\n';
128 static char info_term = ' ';
129
130 static int show_disk_usage;
131 static off_t total_disk_usage;
132 static int human_readable;
133
134 static off_t get_object_disk_usage(struct object *obj)
135 {
136 off_t size;
137 struct object_info oi = OBJECT_INFO_INIT;
138 oi.disk_sizep = &size;
139 if (odb_read_object_info_extended(the_repository->objects,
140 &obj->oid, &oi, 0) < 0)
141 die(_("unable to get disk usage of %s"), oid_to_hex(&obj->oid));
142 return size;
143 }
144
145 static void add_missing_object_entry(struct object_id *oid, const char *path,
146 unsigned type)
147 {
148 struct missing_objects_map_entry *entry;
149
150 if (oidmap_get(&missing_objects, oid))
151 return;
152
153 CALLOC_ARRAY(entry, 1);
154 entry->entry.oid = *oid;
155 entry->type = type;
156 if (path)
157 entry->path = xstrdup(path);
158 oidmap_put(&missing_objects, entry);
159 }
160
161 static void print_missing_object(struct missing_objects_map_entry *entry,
162 int print_missing_info)
163 {
164 struct strbuf sb = STRBUF_INIT;
165
166 /*
167 * --missing-only filters present objects out of the walk output.
168 * It still uses the selected --missing= format for missing ones,
169 * except the human "?" prefix is omitted (script-friendly OIDs).
170 */
171 if (arg_missing_only && line_term)
172 printf("%s", oid_to_hex(&entry->entry.oid));
173 else if (line_term)
174 printf("?%s", oid_to_hex(&entry->entry.oid));
175 else
176 printf("%s%cmissing=yes", oid_to_hex(&entry->entry.oid),
177 info_term);
178
179 if (!print_missing_info) {
180 putchar(line_term);
181 return;
182 }
183
184 if (entry->path && *entry->path) {
185 strbuf_addf(&sb, "%cpath=", info_term);
186
187 if (line_term) {
188 struct strbuf path = STRBUF_INIT;
189
190 quote_path(entry->path, NULL, &path, QUOTE_PATH_QUOTE_SP);
191 strbuf_addbuf(&sb, &path);
192
193 strbuf_release(&path);
194 } else {
195 strbuf_addstr(&sb, entry->path);
196 }
197 }
198 if (entry->type)
199 strbuf_addf(&sb, "%ctype=%s", info_term, type_name(entry->type));
200
201 fwrite(sb.buf, sizeof(char), sb.len, stdout);
202 putchar(line_term);
203
204 strbuf_release(&sb);
205 }
206
207 static inline void finish_object__ma(struct object *obj, const char *name)
208 {
209 /*
210 * Whether or not we try to dynamically fetch missing objects
211 * from the server, we currently DO NOT have the object. We
212 * can either print, allow (ignore), or conditionally allow
213 * (ignore) them.
214 */
215 switch (arg_missing_action) {
216 case MA_ERROR:
217 die("missing %s object '%s'",
218 type_name(obj->type), oid_to_hex(&obj->oid));
219 return;
220
221 case MA_ALLOW_ANY:
222 return;
223
224 case MA_PRINT:
225 case MA_PRINT_INFO:
226 add_missing_object_entry(&obj->oid, name, obj->type);
227 return;
228
229 case MA_ALLOW_PROMISOR:
230 if (is_promisor_object(the_repository, &obj->oid))
231 return;
232 die("unexpected missing %s object '%s'",
233 type_name(obj->type), oid_to_hex(&obj->oid));
234 return;
235
236 default:
237 BUG("unhandled missing_action");
238 return;
239 }
240 }
241
242 static void finish_commit(struct commit *commit)
243 {
244 commit_list_free(commit->parents);
245 commit->parents = NULL;
246 free_commit_buffer(the_repository->parsed_objects,
247 commit);
248 }
249
250 static void show_commit(struct commit *commit, void *data)
251 {
252 struct rev_list_info *info = data;
253 struct rev_info *revs = info->revs;
254
255 display_progress(progress, ++progress_counter);
256
257 if (revs->do_not_die_on_missing_objects &&
258 oidset_contains(&revs->missing_commits, &commit->object.oid)) {
259 finish_object__ma(&commit->object, NULL);
260 return;
261 }
262
263 if (arg_missing_only) {
264 finish_commit(commit);
265 return;
266 }
267
268 if (show_disk_usage)
269 total_disk_usage += get_object_disk_usage(&commit->object);
270
271 if (info->flags & REV_LIST_QUIET) {
272 finish_commit(commit);
273 return;
274 }
275
276 graph_show_commit(revs->graph);
277
278 if (revs->count) {
279 if (commit->object.flags & PATCHSAME)
280 revs->count_same++;
281 else if (commit->object.flags & SYMMETRIC_LEFT)
282 revs->count_left++;
283 else
284 revs->count_right++;
285 finish_commit(commit);
286 return;
287 }
288
289 if (info->show_timestamp)
290 printf("%"PRItime" ", commit->date);
291 if (info->header_prefix)
292 fputs(info->header_prefix, stdout);
293
294 if (revs->include_header) {
295 if (!revs->graph && line_term)
296 fputs(get_revision_mark(revs, commit), stdout);
297 if (revs->abbrev_commit && revs->abbrev)
298 fputs(repo_find_unique_abbrev(the_repository, &commit->object.oid, revs->abbrev),
299 stdout);
300 else
301 fputs(oid_to_hex(&commit->object.oid), stdout);
302
303 if (!line_term) {
304 if (commit->object.flags & BOUNDARY)
305 printf("%cboundary=yes", info_term);
306 }
307 }
308 if (revs->print_parents) {
309 struct commit_list *parents = commit->parents;
310 while (parents) {
311 printf(" %s", oid_to_hex(&parents->item->object.oid));
312 parents = parents->next;
313 }
314 }
315 if (revs->children.name) {
316 struct commit_list *children;
317
318 children = lookup_decoration(&revs->children, &commit->object);
319 while (children) {
320 printf(" %s", oid_to_hex(&children->item->object.oid));
321 children = children->next;
322 }
323 }
324 show_decorations(revs, commit);
325 if (revs->commit_format == CMIT_FMT_ONELINE)
326 putchar(' ');
327 else if (revs->include_header)
328 putchar(line_term);
329
330 if (revs->verbose_header) {
331 struct strbuf buf = STRBUF_INIT;
332 struct pretty_print_context ctx = {0};
333 ctx.abbrev = revs->abbrev;
334 ctx.date_mode = revs->date_mode;
335 ctx.date_mode_explicit = revs->date_mode_explicit;
336 ctx.fmt = revs->commit_format;
337 ctx.output_encoding = get_log_output_encoding();
338 ctx.color = revs->diffopt.use_color;
339 ctx.rev = revs;
340 pretty_print_commit(&ctx, commit, &buf);
341 if (buf.len) {
342 if (revs->commit_format != CMIT_FMT_ONELINE)
343 graph_show_oneline(revs->graph);
344
345 graph_show_commit_msg(revs->graph, stdout, &buf);
346
347 /*
348 * Add a newline after the commit message.
349 *
350 * Usually, this newline produces a blank
351 * padding line between entries, in which case
352 * we need to add graph padding on this line.
353 *
354 * However, the commit message may not end in a
355 * newline. In this case the newline simply
356 * ends the last line of the commit message,
357 * and we don't need any graph output. (This
358 * always happens with CMIT_FMT_ONELINE, and it
359 * happens with CMIT_FMT_USERFORMAT when the
360 * format doesn't explicitly end in a newline.)
361 */
362 if (buf.len && buf.buf[buf.len - 1] == '\n')
363 graph_show_padding(revs->graph);
364 putchar(info->hdr_termination);
365 } else {
366 /*
367 * If the message buffer is empty, just show
368 * the rest of the graph output for this
369 * commit.
370 */
371 if (graph_show_remainder(revs->graph))
372 putchar('\n');
373 if (revs->commit_format == CMIT_FMT_ONELINE)
374 putchar('\n');
375 }
376 strbuf_release(&buf);
377 } else {
378 if (graph_show_remainder(revs->graph))
379 putchar('\n');
380 }
381 maybe_flush_or_die(stdout, "stdout");
382 finish_commit(commit);
383 }
384
385 static int finish_object(struct object *obj, const char *name, void *cb_data)
386 {
387 struct rev_list_info *info = cb_data;
388 if (odb_read_object_info_extended(the_repository->objects,
389 &obj->oid, NULL, 0) < 0) {
390 finish_object__ma(obj, name);
391 return 1;
392 }
393 if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
394 parse_object(the_repository, &obj->oid);
395 return 0;
396 }
397
398 static void show_object(struct object *obj, const char *name, void *cb_data)
399 {
400 struct rev_list_info *info = cb_data;
401 struct rev_info *revs = info->revs;
402
403 if (finish_object(obj, name, cb_data))
404 return;
405 display_progress(progress, ++progress_counter);
406 if (arg_missing_only)
407 return;
408 if (show_disk_usage)
409 total_disk_usage += get_object_disk_usage(obj);
410 if (info->flags & REV_LIST_QUIET)
411 return;
412
413 if (revs->count) {
414 /*
415 * The object count is always accumulated in the .count_right
416 * field for traversal that is not a left-right traversal,
417 * and cmd_rev_list() made sure that a .count request that
418 * wants to count non-commit objects, which is handled by
419 * the show_object() callback, does not ask for .left_right.
420 */
421 revs->count_right++;
422 return;
423 }
424
425 printf("%s", oid_to_hex(&obj->oid));
426
427 if (arg_show_object_names) {
428 if (line_term) {
429 putchar(info_term);
430 for (const char *p = name; *p && *p != '\n'; p++)
431 putchar(*p);
432 } else if (*name) {
433 printf("%cpath=%s", info_term, name);
434 }
435 }
436
437 putchar(line_term);
438 }
439
440 static void show_edge(struct commit *commit)
441 {
442 printf("-%s\n", oid_to_hex(&commit->object.oid));
443 }
444
445 static void print_var_str(const char *var, const char *val)
446 {
447 printf("%s='%s'\n", var, val);
448 }
449
450 static void print_var_int(const char *var, int val)
451 {
452 printf("%s=%d\n", var, val);
453 }
454
455 static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
456 {
457 int cnt, flags = info->flags;
458 char hex[GIT_MAX_HEXSZ + 1] = "";
459 struct commit_list *tried;
460 struct rev_info *revs = info->revs;
461
462 if (!revs->commits)
463 return 1;
464
465 revs->commits = filter_skipped(revs->commits, &tried,
466 flags & BISECT_SHOW_ALL,
467 NULL, NULL);
468
469 /*
470 * revs->commits can reach "reaches" commits among
471 * "all" commits. If it is good, then there are
472 * (all-reaches) commits left to be bisected.
473 * On the other hand, if it is bad, then the set
474 * to bisect is "reaches".
475 * A bisect set of size N has (N-1) commits further
476 * to test, as we already know one bad one.
477 */
478 cnt = all - reaches;
479 if (cnt < reaches)
480 cnt = reaches;
481
482 if (revs->commits)
483 oid_to_hex_r(hex, &revs->commits->item->object.oid);
484
485 if (flags & BISECT_SHOW_ALL) {
486 traverse_commit_list(revs, show_commit, show_object, info);
487 printf("------\n");
488 }
489
490 print_var_str("bisect_rev", hex);
491 print_var_int("bisect_nr", cnt - 1);
492 print_var_int("bisect_good", all - reaches - 1);
493 print_var_int("bisect_bad", reaches - 1);
494 print_var_int("bisect_all", all);
495 print_var_int("bisect_steps", estimate_bisect_steps(all));
496
497 return 0;
498 }
499
500 static int show_object_fast(
501 const struct object_id *oid,
502 enum object_type type UNUSED,
503 int exclude UNUSED,
504 uint32_t name_hash UNUSED,
505 struct packed_git *found_pack UNUSED,
506 off_t found_offset UNUSED,
507 void *payload UNUSED)
508 {
509 fprintf(stdout, "%s\n", oid_to_hex(oid));
510 return 0;
511 }
512
513 static void print_disk_usage(off_t size)
514 {
515 struct strbuf sb = STRBUF_INIT;
516 if (human_readable)
517 strbuf_humanise_bytes(&sb, size);
518 else
519 strbuf_addf(&sb, "%"PRIuMAX, (uintmax_t)size);
520 puts(sb.buf);
521 strbuf_release(&sb);
522 }
523
524 static inline int parse_missing_action_value(struct repository *repo,
525 const char *value)
526 {
527 if (!strcmp(value, "error")) {
528 arg_missing_action = MA_ERROR;
529 return 1;
530 }
531
532 if (!strcmp(value, "allow-any")) {
533 arg_missing_action = MA_ALLOW_ANY;
534 repo->fetch_if_missing = 0;
535 return 1;
536 }
537
538 if (!strcmp(value, "print")) {
539 arg_missing_action = MA_PRINT;
540 repo->fetch_if_missing = 0;
541 return 1;
542 }
543
544 if (!strcmp(value, "print-info")) {
545 arg_missing_action = MA_PRINT_INFO;
546 repo->fetch_if_missing = 0;
547 return 1;
548 }
549
550 if (!strcmp(value, "allow-promisor")) {
551 arg_missing_action = MA_ALLOW_PROMISOR;
552 repo->fetch_if_missing = 0;
553 return 1;
554 }
555
556 return 0;
557 }
558
559 static int try_bitmap_count(struct rev_info *revs,
560 int filter_provided_objects)
561 {
562 uint32_t commit_count = 0,
563 tag_count = 0,
564 tree_count = 0,
565 blob_count = 0;
566 int max_count;
567 struct bitmap_index *bitmap_git;
568
569 /* This function only handles counting, not general traversal. */
570 if (!revs->count)
571 return -1;
572
573 /*
574 * A bitmap result can't know left/right, etc, because we don't
575 * actually traverse.
576 */
577 if (revs->left_right || revs->cherry_mark)
578 return -1;
579
580 /*
581 * If we're counting reachable objects, we can't handle a max count of
582 * commits to traverse, since we don't know which objects go with which
583 * commit.
584 */
585 if (revs->max_count >= 0 &&
586 (revs->tag_objects || revs->tree_objects || revs->blob_objects))
587 return -1;
588
589 /*
590 * This must be saved before doing any walking, since the revision
591 * machinery will count it down to zero while traversing.
592 */
593 max_count = revs->max_count;
594
595 bitmap_git = prepare_bitmap_walk(revs, filter_provided_objects);
596 if (!bitmap_git)
597 return -1;
598
599 count_bitmap_commit_list(bitmap_git, &commit_count,
600 revs->tree_objects ? &tree_count : NULL,
601 revs->blob_objects ? &blob_count : NULL,
602 revs->tag_objects ? &tag_count : NULL);
603 if (max_count >= 0 && max_count < commit_count)
604 commit_count = max_count;
605
606 printf("%d\n", commit_count + tree_count + blob_count + tag_count);
607 free_bitmap_index(bitmap_git);
608 return 0;
609 }
610
611 static int try_bitmap_traversal(struct rev_info *revs,
612 int filter_provided_objects)
613 {
614 struct bitmap_index *bitmap_git;
615
616 /*
617 * We can't use a bitmap result with a traversal limit, since the set
618 * of commits we'd get would be essentially random.
619 */
620 if (revs->max_count >= 0)
621 return -1;
622
623 /*
624 * We can't know which commits were left/right in a single traversal,
625 * and we don't yet know how to traverse them separately.
626 */
627 if (revs->left_right)
628 return -1;
629
630 bitmap_git = prepare_bitmap_walk(revs, filter_provided_objects);
631 if (!bitmap_git)
632 return -1;
633
634 traverse_bitmap_commit_list(bitmap_git, revs, &show_object_fast);
635 free_bitmap_index(bitmap_git);
636 return 0;
637 }
638
639 static int try_bitmap_disk_usage(struct rev_info *revs,
640 int filter_provided_objects)
641 {
642 struct bitmap_index *bitmap_git;
643 off_t size_from_bitmap;
644
645 if (!show_disk_usage)
646 return -1;
647
648 bitmap_git = prepare_bitmap_walk(revs, filter_provided_objects);
649 if (!bitmap_git)
650 return -1;
651
652 size_from_bitmap = get_disk_usage_from_bitmap(bitmap_git, revs);
653 print_disk_usage(size_from_bitmap);
654
655 free_bitmap_index(bitmap_git);
656 return 0;
657 }
658
659 /*
660 * If revs->maximal_only is set and no other walk modifiers are provided,
661 * run a faster computation to filter the independent commits and prepare
662 * them for output. Set revs->no_walk to prevent later walking.
663 *
664 * If this algorithm doesn't apply, then no changes are made to revs.
665 */
666 static void prepare_maximal_independent(struct rev_info *revs)
667 {
668 struct commit_list *c;
669
670 if (!revs->maximal_only)
671 return;
672
673 for (c = revs->commits; c; c = c->next) {
674 if (c->item->object.flags & UNINTERESTING)
675 return;
676 }
677
678 if (revs->limited ||
679 revs->topo_order ||
680 revs->first_parent_only ||
681 revs->reverse ||
682 revs->max_count >= 0 ||
683 revs->skip_count >= 0 ||
684 revs->min_age != (timestamp_t)-1 ||
685 revs->max_age != (timestamp_t)-1 ||
686 revs->min_parents > 0 ||
687 revs->max_parents >= 0 ||
688 revs->prune_data.nr ||
689 revs->count ||
690 revs->left_right ||
691 revs->boundary ||
692 revs->tag_objects ||
693 revs->tree_objects ||
694 revs->blob_objects ||
695 revs->filter.choice ||
696 revs->reflog_info ||
697 revs->diff ||
698 revs->grep_filter.pattern_list ||
699 revs->grep_filter.header_list ||
700 revs->verbose_header ||
701 revs->print_parents ||
702 revs->edge_hint ||
703 revs->unpacked ||
704 revs->no_kept_objects ||
705 revs->line_level_traverse)
706 return;
707
708 reduce_heads_replace(&revs->commits);
709
710 /* Modify 'revs' to only output this commit list. */
711 revs->no_walk = 1;
712 }
713
714 int cmd_rev_list(int argc,
715 const char **argv,
716 const char *prefix,
717 struct repository *repo)
718 {
719 struct rev_info revs;
720 struct rev_list_info info;
721 struct setup_revision_opt s_r_opt = {
722 .allow_exclude_promisor_objects = 1,
723 };
724 int i;
725 int bisect_list = 0;
726 int bisect_show_vars = 0;
727 int bisect_find_all = 0;
728 int use_bitmap_index = 0;
729 int filter_provided_objects = 0;
730 const char *show_progress = NULL;
731 int ret = 0;
732
733 show_usage_if_asked(argc, argv, rev_list_usage);
734
735 repo_config(the_repository, git_default_config, NULL);
736 repo_init_revisions(the_repository, &revs, prefix);
737 revs.abbrev = DEFAULT_ABBREV;
738 revs.commit_format = CMIT_FMT_UNSPECIFIED;
739 revs.include_header = 1;
740
741 /*
742 * Scan the argument list before invoking setup_revisions(), so that we
743 * know if fetch_if_missing needs to be set to 0.
744 *
745 * "--exclude-promisor-objects" acts as a pre-filter on missing objects
746 * by not crossing the boundary from realized objects to promisor
747 * objects.
748 *
749 * Let "--missing" to conditionally set fetch_if_missing.
750 */
751
752 /*
753 * NEEDSWORK: The next loop is utterly broken. It tries to
754 * notice an option is used, but without understanding if each
755 * option takes an argument, which fundamentally would not
756 * work. It would not know "--grep
757 * --exclude-promisor-objects" is not triggering
758 * "--exclude-promisor-objects" option, for example.
759 *
760 * We really need setup_revisions() to have a mechanism to
761 * allow and disallow some sets of options for different
762 * commands (like rev-list, replay, etc). Such a mechanism
763 * should do an early parsing of options and be able to manage
764 * the `--missing=...` and `--exclude-promisor-objects`
765 * options below.
766 */
767 for (i = 1; i < argc; i++) {
768 const char *arg = argv[i];
769 if (!strcmp(arg, "--exclude-promisor-objects")) {
770 repo->fetch_if_missing = 0;
771 revs.exclude_promisor_objects = 1;
772 } else if (skip_prefix(arg, "--missing=", &arg)) {
773 parse_missing_action_value(repo, arg);
774 } else if (!strcmp(arg, "--missing-only")) {
775 arg_missing_only = 1;
776 } else if (!strcmp(arg, "-z")) {
777 line_term = '\0';
778 info_term = '\0';
779 }
780 }
781
782 if (arg_missing_only && !should_collect_missing())
783 die(_("--missing-only requires --missing=print or --missing=print-info"));
784
785 die_for_incompatible_opt2(revs.exclude_promisor_objects,
786 "--exclude_promisor_objects",
787 arg_missing_action, "--missing");
788
789 if (arg_missing_action)
790 revs.do_not_die_on_missing_objects = 1;
791
792 argc = setup_revisions(argc, argv, &revs, &s_r_opt);
793
794 memset(&info, 0, sizeof(info));
795 info.revs = &revs;
796 if (revs.bisect)
797 bisect_list = 1;
798
799 if (revs.diffopt.flags.quick)
800 info.flags |= REV_LIST_QUIET;
801 for (i = 1 ; i < argc; i++) {
802 const char *arg = argv[i];
803
804 if (!strcmp(arg, "--header")) {
805 revs.verbose_header = 1;
806 continue;
807 }
808 if (!strcmp(arg, "--timestamp")) {
809 info.show_timestamp = 1;
810 continue;
811 }
812 if (!strcmp(arg, "--bisect")) {
813 bisect_list = 1;
814 continue;
815 }
816 if (!strcmp(arg, "--bisect-all")) {
817 bisect_list = 1;
818 bisect_find_all = 1;
819 info.flags |= BISECT_SHOW_ALL;
820 revs.show_decorations = 1;
821 continue;
822 }
823 if (!strcmp(arg, "--bisect-vars")) {
824 bisect_list = 1;
825 bisect_show_vars = 1;
826 continue;
827 }
828 if (!strcmp(arg, "--use-bitmap-index")) {
829 use_bitmap_index = 1;
830 continue;
831 }
832 if (!strcmp(arg, "--test-bitmap")) {
833 test_bitmap_walk(&revs);
834 goto cleanup;
835 }
836 if (skip_prefix(arg, "--progress=", &arg)) {
837 show_progress = arg;
838 continue;
839 }
840 if (!strcmp(arg, "--filter-provided-objects")) {
841 filter_provided_objects = 1;
842 continue;
843 }
844 if (!strcmp(arg, "--filter-print-omitted")) {
845 arg_print_omitted = 1;
846 continue;
847 }
848
849 if (!strcmp(arg, "--exclude-promisor-objects"))
850 continue; /* already handled above */
851 if (skip_prefix(arg, "--missing=", &arg))
852 continue; /* already handled above */
853
854 if (!strcmp(arg, ("--no-object-names"))) {
855 arg_show_object_names = 0;
856 continue;
857 }
858
859 if (!strcmp(arg, ("--object-names"))) {
860 arg_show_object_names = 1;
861 continue;
862 }
863
864 if (!strcmp(arg, ("--commit-header"))) {
865 revs.include_header = 1;
866 continue;
867 }
868
869 if (!strcmp(arg, ("--no-commit-header"))) {
870 revs.include_header = 0;
871 continue;
872 }
873
874 if (skip_prefix(arg, "--disk-usage", &arg)) {
875 if (*arg == '=') {
876 if (!strcmp(++arg, "human")) {
877 human_readable = 1;
878 } else
879 die(_("invalid value for '%s': '%s', the only allowed format is '%s'"),
880 "--disk-usage=<format>", arg, "human");
881 } else if (*arg) {
882 /*
883 * Arguably should goto a label to continue chain of ifs?
884 * Doesn't matter unless we try to add --disk-usage-foo
885 * afterwards.
886 */
887 usage(rev_list_usage);
888 }
889 show_disk_usage = 1;
890 info.flags |= REV_LIST_QUIET;
891 continue;
892 }
893
894 if (!strcmp(arg, "--missing-only"))
895 continue;
896
897 usage(rev_list_usage);
898
899 }
900
901 /*
902 * Reject options currently incompatible with -z. For some options, this
903 * is not an inherent limitation and support may be implemented in the
904 * future.
905 */
906 if (!line_term) {
907 if (revs.graph || revs.verbose_header || show_disk_usage ||
908 info.show_timestamp || info.header_prefix || bisect_list ||
909 use_bitmap_index || revs.edge_hint || revs.left_right ||
910 revs.cherry_mark)
911 die(_("-z option used with unsupported option"));
912 }
913
914 if (revs.commit_format != CMIT_FMT_USERFORMAT)
915 revs.include_header = 1;
916 if (revs.commit_format != CMIT_FMT_UNSPECIFIED) {
917 /* The command line has a --pretty */
918 info.hdr_termination = '\n';
919 if (revs.commit_format == CMIT_FMT_ONELINE || !revs.include_header)
920 info.header_prefix = "";
921 else
922 info.header_prefix = "commit ";
923 }
924 else if (revs.verbose_header)
925 /* Only --header was specified */
926 revs.commit_format = CMIT_FMT_RAW;
927
928 if ((!revs.commits && reflog_walk_empty(revs.reflog_info) &&
929 (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
930 !revs.pending.nr) &&
931 !revs.rev_input_given && !revs.read_from_stdin) ||
932 revs.diff)
933 usage(rev_list_usage);
934
935 if (revs.show_notes)
936 die(_("rev-list does not support display of notes"));
937
938 if (revs.count &&
939 (revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
940 (revs.left_right || revs.cherry_mark))
941 die(_("marked counting and '%s' cannot be used together"), "--objects");
942
943 die_for_incompatible_opt2(arg_missing_only, "--missing-only",
944 revs.count, "--count");
945 die_for_incompatible_opt2(arg_missing_only, "--missing-only",
946 show_disk_usage, "--disk-usage");
947
948 save_commit_buffer = (revs.verbose_header ||
949 revs.grep_filter.pattern_list ||
950 revs.grep_filter.header_list);
951 if (bisect_list)
952 revs.limited = 1;
953
954 if (show_progress)
955 progress = start_delayed_progress(the_repository,
956 show_progress, 0);
957
958 if (use_bitmap_index) {
959 if (!try_bitmap_count(&revs, filter_provided_objects))
960 goto cleanup;
961 if (!try_bitmap_disk_usage(&revs, filter_provided_objects))
962 goto cleanup;
963 if (!try_bitmap_traversal(&revs, filter_provided_objects))
964 goto cleanup;
965 }
966
967 if (prepare_revision_walk(&revs))
968 die("revision walk setup failed");
969
970 prepare_maximal_independent(&revs);
971
972 if (revs.tree_objects)
973 mark_edges_uninteresting(&revs, show_edge, 0);
974
975 if (bisect_list) {
976 int reaches, all;
977 unsigned bisect_flags = 0;
978
979 if (bisect_find_all)
980 bisect_flags |= FIND_BISECTION_ALL;
981
982 if (revs.first_parent_only)
983 bisect_flags |= FIND_BISECTION_FIRST_PARENT_ONLY;
984
985 find_bisection(&revs.commits, &reaches, &all, bisect_flags);
986
987 if (bisect_show_vars) {
988 ret = show_bisect_vars(&info, reaches, all);
989 goto cleanup;
990 }
991 }
992
993 if (filter_provided_objects) {
994 struct commit_list *c;
995 for (i = 0; i < revs.pending.nr; i++) {
996 struct object_array_entry *pending = revs.pending.objects + i;
997 pending->item->flags |= NOT_USER_GIVEN;
998 }
999 for (c = revs.commits; c; c = c->next)
1000 c->item->object.flags |= NOT_USER_GIVEN;
1001 }
1002
1003 if (arg_print_omitted)
1004 oidset_init(&omitted_objects, DEFAULT_OIDSET_SIZE);
1005 if (should_collect_missing()) {
1006 struct oidset_iter iter;
1007 struct object_id *oid;
1008
1009 oidmap_init(&missing_objects, DEFAULT_OIDSET_SIZE);
1010 oidset_iter_init(&revs.missing_commits, &iter);
1011
1012 /* Add missing tips */
1013 while ((oid = oidset_iter_next(&iter)))
1014 add_missing_object_entry(oid, NULL, 0);
1015
1016 oidset_clear(&revs.missing_commits);
1017 }
1018
1019 traverse_commit_list_filtered(
1020 &revs, show_commit, show_object, &info,
1021 (arg_print_omitted ? &omitted_objects : NULL));
1022
1023 if (arg_print_omitted) {
1024 struct oidset_iter iter;
1025 struct object_id *oid;
1026 oidset_iter_init(&omitted_objects, &iter);
1027 while ((oid = oidset_iter_next(&iter)))
1028 printf("~%s\n", oid_to_hex(oid));
1029 oidset_clear(&omitted_objects);
1030 }
1031 if (should_collect_missing()) {
1032 struct missing_objects_map_entry *entry;
1033 struct oidmap_iter iter;
1034
1035 oidmap_iter_init(&missing_objects, &iter);
1036
1037 while ((entry = oidmap_iter_next(&iter))) {
1038 print_missing_object(entry, arg_missing_action ==
1039 MA_PRINT_INFO);
1040 }
1041
1042 oidmap_clear_with_free(&missing_objects, missing_objects_map_entry_free);
1043 }
1044
1045 stop_progress(&progress);
1046
1047 if (revs.count) {
1048 if (revs.left_right && revs.cherry_mark)
1049 printf("%d\t%d\t%d\n", revs.count_left, revs.count_right, revs.count_same);
1050 else if (revs.left_right)
1051 printf("%d\t%d\n", revs.count_left, revs.count_right);
1052 else if (revs.cherry_mark)
1053 printf("%d\t%d\n", revs.count_left + revs.count_right, revs.count_same);
1054 else
1055 printf("%d\n", revs.count_left + revs.count_right);
1056 }
1057
1058 if (show_disk_usage)
1059 print_disk_usage(total_disk_usage);
1060
1061 cleanup:
1062 release_revisions(&revs);
1063 return ret;
1064 }