at commit fd6c4dc8

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(const char *value)
525 {
526 if (!strcmp(value, "error")) {
527 arg_missing_action = MA_ERROR;
528 return 1;
529 }
530
531 if (!strcmp(value, "allow-any")) {
532 arg_missing_action = MA_ALLOW_ANY;
533 fetch_if_missing = 0;
534 return 1;
535 }
536
537 if (!strcmp(value, "print")) {
538 arg_missing_action = MA_PRINT;
539 fetch_if_missing = 0;
540 return 1;
541 }
542
543 if (!strcmp(value, "print-info")) {
544 arg_missing_action = MA_PRINT_INFO;
545 fetch_if_missing = 0;
546 return 1;
547 }
548
549 if (!strcmp(value, "allow-promisor")) {
550 arg_missing_action = MA_ALLOW_PROMISOR;
551 fetch_if_missing = 0;
552 return 1;
553 }
554
555 return 0;
556 }
557
558 static int try_bitmap_count(struct rev_info *revs,
559 int filter_provided_objects)
560 {
561 uint32_t commit_count = 0,
562 tag_count = 0,
563 tree_count = 0,
564 blob_count = 0;
565 int max_count;
566 struct bitmap_index *bitmap_git;
567
568 /* This function only handles counting, not general traversal. */
569 if (!revs->count)
570 return -1;
571
572 /*
573 * A bitmap result can't know left/right, etc, because we don't
574 * actually traverse.
575 */
576 if (revs->left_right || revs->cherry_mark)
577 return -1;
578
579 /*
580 * If we're counting reachable objects, we can't handle a max count of
581 * commits to traverse, since we don't know which objects go with which
582 * commit.
583 */
584 if (revs->max_count >= 0 &&
585 (revs->tag_objects || revs->tree_objects || revs->blob_objects))
586 return -1;
587
588 /*
589 * This must be saved before doing any walking, since the revision
590 * machinery will count it down to zero while traversing.
591 */
592 max_count = revs->max_count;
593
594 bitmap_git = prepare_bitmap_walk(revs, filter_provided_objects);
595 if (!bitmap_git)
596 return -1;
597
598 count_bitmap_commit_list(bitmap_git, &commit_count,
599 revs->tree_objects ? &tree_count : NULL,
600 revs->blob_objects ? &blob_count : NULL,
601 revs->tag_objects ? &tag_count : NULL);
602 if (max_count >= 0 && max_count < commit_count)
603 commit_count = max_count;
604
605 printf("%d\n", commit_count + tree_count + blob_count + tag_count);
606 free_bitmap_index(bitmap_git);
607 return 0;
608 }
609
610 static int try_bitmap_traversal(struct rev_info *revs,
611 int filter_provided_objects)
612 {
613 struct bitmap_index *bitmap_git;
614
615 /*
616 * We can't use a bitmap result with a traversal limit, since the set
617 * of commits we'd get would be essentially random.
618 */
619 if (revs->max_count >= 0)
620 return -1;
621
622 /*
623 * We can't know which commits were left/right in a single traversal,
624 * and we don't yet know how to traverse them separately.
625 */
626 if (revs->left_right)
627 return -1;
628
629 bitmap_git = prepare_bitmap_walk(revs, filter_provided_objects);
630 if (!bitmap_git)
631 return -1;
632
633 traverse_bitmap_commit_list(bitmap_git, revs, &show_object_fast);
634 free_bitmap_index(bitmap_git);
635 return 0;
636 }
637
638 static int try_bitmap_disk_usage(struct rev_info *revs,
639 int filter_provided_objects)
640 {
641 struct bitmap_index *bitmap_git;
642 off_t size_from_bitmap;
643
644 if (!show_disk_usage)
645 return -1;
646
647 bitmap_git = prepare_bitmap_walk(revs, filter_provided_objects);
648 if (!bitmap_git)
649 return -1;
650
651 size_from_bitmap = get_disk_usage_from_bitmap(bitmap_git, revs);
652 print_disk_usage(size_from_bitmap);
653
654 free_bitmap_index(bitmap_git);
655 return 0;
656 }
657
658 /*
659 * If revs->maximal_only is set and no other walk modifiers are provided,
660 * run a faster computation to filter the independent commits and prepare
661 * them for output. Set revs->no_walk to prevent later walking.
662 *
663 * If this algorithm doesn't apply, then no changes are made to revs.
664 */
665 static void prepare_maximal_independent(struct rev_info *revs)
666 {
667 struct commit_list *c;
668
669 if (!revs->maximal_only)
670 return;
671
672 for (c = revs->commits; c; c = c->next) {
673 if (c->item->object.flags & UNINTERESTING)
674 return;
675 }
676
677 if (revs->limited ||
678 revs->topo_order ||
679 revs->first_parent_only ||
680 revs->reverse ||
681 revs->max_count >= 0 ||
682 revs->skip_count >= 0 ||
683 revs->min_age != (timestamp_t)-1 ||
684 revs->max_age != (timestamp_t)-1 ||
685 revs->min_parents > 0 ||
686 revs->max_parents >= 0 ||
687 revs->prune_data.nr ||
688 revs->count ||
689 revs->left_right ||
690 revs->boundary ||
691 revs->tag_objects ||
692 revs->tree_objects ||
693 revs->blob_objects ||
694 revs->filter.choice ||
695 revs->reflog_info ||
696 revs->diff ||
697 revs->grep_filter.pattern_list ||
698 revs->grep_filter.header_list ||
699 revs->verbose_header ||
700 revs->print_parents ||
701 revs->edge_hint ||
702 revs->unpacked ||
703 revs->no_kept_objects ||
704 revs->line_level_traverse)
705 return;
706
707 reduce_heads_replace(&revs->commits);
708
709 /* Modify 'revs' to only output this commit list. */
710 revs->no_walk = 1;
711 }
712
713 int cmd_rev_list(int argc,
714 const char **argv,
715 const char *prefix,
716 struct repository *repo UNUSED)
717 {
718 struct rev_info revs;
719 struct rev_list_info info;
720 struct setup_revision_opt s_r_opt = {
721 .allow_exclude_promisor_objects = 1,
722 };
723 int i;
724 int bisect_list = 0;
725 int bisect_show_vars = 0;
726 int bisect_find_all = 0;
727 int use_bitmap_index = 0;
728 int filter_provided_objects = 0;
729 const char *show_progress = NULL;
730 int ret = 0;
731
732 show_usage_if_asked(argc, argv, rev_list_usage);
733
734 repo_config(the_repository, git_default_config, NULL);
735 repo_init_revisions(the_repository, &revs, prefix);
736 revs.abbrev = DEFAULT_ABBREV;
737 revs.commit_format = CMIT_FMT_UNSPECIFIED;
738 revs.include_header = 1;
739
740 /*
741 * Scan the argument list before invoking setup_revisions(), so that we
742 * know if fetch_if_missing needs to be set to 0.
743 *
744 * "--exclude-promisor-objects" acts as a pre-filter on missing objects
745 * by not crossing the boundary from realized objects to promisor
746 * objects.
747 *
748 * Let "--missing" to conditionally set fetch_if_missing.
749 */
750
751 /*
752 * NEEDSWORK: The next loop is utterly broken. It tries to
753 * notice an option is used, but without understanding if each
754 * option takes an argument, which fundamentally would not
755 * work. It would not know "--grep
756 * --exclude-promisor-objects" is not triggering
757 * "--exclude-promisor-objects" option, for example.
758 *
759 * We really need setup_revisions() to have a mechanism to
760 * allow and disallow some sets of options for different
761 * commands (like rev-list, replay, etc). Such a mechanism
762 * should do an early parsing of options and be able to manage
763 * the `--missing=...` and `--exclude-promisor-objects`
764 * options below.
765 */
766 for (i = 1; i < argc; i++) {
767 const char *arg = argv[i];
768 if (!strcmp(arg, "--exclude-promisor-objects")) {
769 fetch_if_missing = 0;
770 revs.exclude_promisor_objects = 1;
771 } else if (skip_prefix(arg, "--missing=", &arg)) {
772 parse_missing_action_value(arg);
773 } else if (!strcmp(arg, "--missing-only")) {
774 arg_missing_only = 1;
775 } else if (!strcmp(arg, "-z")) {
776 line_term = '\0';
777 info_term = '\0';
778 }
779 }
780
781 if (arg_missing_only && !should_collect_missing())
782 die(_("--missing-only requires --missing=print or --missing=print-info"));
783
784 die_for_incompatible_opt2(revs.exclude_promisor_objects,
785 "--exclude_promisor_objects",
786 arg_missing_action, "--missing");
787
788 if (arg_missing_action)
789 revs.do_not_die_on_missing_objects = 1;
790
791 argc = setup_revisions(argc, argv, &revs, &s_r_opt);
792
793 memset(&info, 0, sizeof(info));
794 info.revs = &revs;
795 if (revs.bisect)
796 bisect_list = 1;
797
798 if (revs.diffopt.flags.quick)
799 info.flags |= REV_LIST_QUIET;
800 for (i = 1 ; i < argc; i++) {
801 const char *arg = argv[i];
802
803 if (!strcmp(arg, "--header")) {
804 revs.verbose_header = 1;
805 continue;
806 }
807 if (!strcmp(arg, "--timestamp")) {
808 info.show_timestamp = 1;
809 continue;
810 }
811 if (!strcmp(arg, "--bisect")) {
812 bisect_list = 1;
813 continue;
814 }
815 if (!strcmp(arg, "--bisect-all")) {
816 bisect_list = 1;
817 bisect_find_all = 1;
818 info.flags |= BISECT_SHOW_ALL;
819 revs.show_decorations = 1;
820 continue;
821 }
822 if (!strcmp(arg, "--bisect-vars")) {
823 bisect_list = 1;
824 bisect_show_vars = 1;
825 continue;
826 }
827 if (!strcmp(arg, "--use-bitmap-index")) {
828 use_bitmap_index = 1;
829 continue;
830 }
831 if (!strcmp(arg, "--test-bitmap")) {
832 test_bitmap_walk(&revs);
833 goto cleanup;
834 }
835 if (skip_prefix(arg, "--progress=", &arg)) {
836 show_progress = arg;
837 continue;
838 }
839 if (!strcmp(arg, "--filter-provided-objects")) {
840 filter_provided_objects = 1;
841 continue;
842 }
843 if (!strcmp(arg, "--filter-print-omitted")) {
844 arg_print_omitted = 1;
845 continue;
846 }
847
848 if (!strcmp(arg, "--exclude-promisor-objects"))
849 continue; /* already handled above */
850 if (skip_prefix(arg, "--missing=", &arg))
851 continue; /* already handled above */
852
853 if (!strcmp(arg, ("--no-object-names"))) {
854 arg_show_object_names = 0;
855 continue;
856 }
857
858 if (!strcmp(arg, ("--object-names"))) {
859 arg_show_object_names = 1;
860 continue;
861 }
862
863 if (!strcmp(arg, ("--commit-header"))) {
864 revs.include_header = 1;
865 continue;
866 }
867
868 if (!strcmp(arg, ("--no-commit-header"))) {
869 revs.include_header = 0;
870 continue;
871 }
872
873 if (skip_prefix(arg, "--disk-usage", &arg)) {
874 if (*arg == '=') {
875 if (!strcmp(++arg, "human")) {
876 human_readable = 1;
877 } else
878 die(_("invalid value for '%s': '%s', the only allowed format is '%s'"),
879 "--disk-usage=<format>", arg, "human");
880 } else if (*arg) {
881 /*
882 * Arguably should goto a label to continue chain of ifs?
883 * Doesn't matter unless we try to add --disk-usage-foo
884 * afterwards.
885 */
886 usage(rev_list_usage);
887 }
888 show_disk_usage = 1;
889 info.flags |= REV_LIST_QUIET;
890 continue;
891 }
892
893 if (!strcmp(arg, "--missing-only"))
894 continue;
895
896 usage(rev_list_usage);
897
898 }
899
900 /*
901 * Reject options currently incompatible with -z. For some options, this
902 * is not an inherent limitation and support may be implemented in the
903 * future.
904 */
905 if (!line_term) {
906 if (revs.graph || revs.verbose_header || show_disk_usage ||
907 info.show_timestamp || info.header_prefix || bisect_list ||
908 use_bitmap_index || revs.edge_hint || revs.left_right ||
909 revs.cherry_mark)
910 die(_("-z option used with unsupported option"));
911 }
912
913 if (revs.commit_format != CMIT_FMT_USERFORMAT)
914 revs.include_header = 1;
915 if (revs.commit_format != CMIT_FMT_UNSPECIFIED) {
916 /* The command line has a --pretty */
917 info.hdr_termination = '\n';
918 if (revs.commit_format == CMIT_FMT_ONELINE || !revs.include_header)
919 info.header_prefix = "";
920 else
921 info.header_prefix = "commit ";
922 }
923 else if (revs.verbose_header)
924 /* Only --header was specified */
925 revs.commit_format = CMIT_FMT_RAW;
926
927 if ((!revs.commits && reflog_walk_empty(revs.reflog_info) &&
928 (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
929 !revs.pending.nr) &&
930 !revs.rev_input_given && !revs.read_from_stdin) ||
931 revs.diff)
932 usage(rev_list_usage);
933
934 if (revs.show_notes)
935 die(_("rev-list does not support display of notes"));
936
937 if (revs.count &&
938 (revs.tag_objects || revs.tree_objects || revs.blob_objects) &&
939 (revs.left_right || revs.cherry_mark))
940 die(_("marked counting and '%s' cannot be used together"), "--objects");
941
942 die_for_incompatible_opt2(arg_missing_only, "--missing-only",
943 revs.count, "--count");
944 die_for_incompatible_opt2(arg_missing_only, "--missing-only",
945 show_disk_usage, "--disk-usage");
946
947 save_commit_buffer = (revs.verbose_header ||
948 revs.grep_filter.pattern_list ||
949 revs.grep_filter.header_list);
950 if (bisect_list)
951 revs.limited = 1;
952
953 if (show_progress)
954 progress = start_delayed_progress(the_repository,
955 show_progress, 0);
956
957 if (use_bitmap_index) {
958 if (!try_bitmap_count(&revs, filter_provided_objects))
959 goto cleanup;
960 if (!try_bitmap_disk_usage(&revs, filter_provided_objects))
961 goto cleanup;
962 if (!try_bitmap_traversal(&revs, filter_provided_objects))
963 goto cleanup;
964 }
965
966 if (prepare_revision_walk(&revs))
967 die("revision walk setup failed");
968
969 prepare_maximal_independent(&revs);
970
971 if (revs.tree_objects)
972 mark_edges_uninteresting(&revs, show_edge, 0);
973
974 if (bisect_list) {
975 int reaches, all;
976 unsigned bisect_flags = 0;
977
978 if (bisect_find_all)
979 bisect_flags |= FIND_BISECTION_ALL;
980
981 if (revs.first_parent_only)
982 bisect_flags |= FIND_BISECTION_FIRST_PARENT_ONLY;
983
984 find_bisection(&revs.commits, &reaches, &all, bisect_flags);
985
986 if (bisect_show_vars) {
987 ret = show_bisect_vars(&info, reaches, all);
988 goto cleanup;
989 }
990 }
991
992 if (filter_provided_objects) {
993 struct commit_list *c;
994 for (i = 0; i < revs.pending.nr; i++) {
995 struct object_array_entry *pending = revs.pending.objects + i;
996 pending->item->flags |= NOT_USER_GIVEN;
997 }
998 for (c = revs.commits; c; c = c->next)
999 c->item->object.flags |= NOT_USER_GIVEN;
1000 }
1001
1002 if (arg_print_omitted)
1003 oidset_init(&omitted_objects, DEFAULT_OIDSET_SIZE);
1004 if (should_collect_missing()) {
1005 struct oidset_iter iter;
1006 struct object_id *oid;
1007
1008 oidmap_init(&missing_objects, DEFAULT_OIDSET_SIZE);
1009 oidset_iter_init(&revs.missing_commits, &iter);
1010
1011 /* Add missing tips */
1012 while ((oid = oidset_iter_next(&iter)))
1013 add_missing_object_entry(oid, NULL, 0);
1014
1015 oidset_clear(&revs.missing_commits);
1016 }
1017
1018 traverse_commit_list_filtered(
1019 &revs, show_commit, show_object, &info,
1020 (arg_print_omitted ? &omitted_objects : NULL));
1021
1022 if (arg_print_omitted) {
1023 struct oidset_iter iter;
1024 struct object_id *oid;
1025 oidset_iter_init(&omitted_objects, &iter);
1026 while ((oid = oidset_iter_next(&iter)))
1027 printf("~%s\n", oid_to_hex(oid));
1028 oidset_clear(&omitted_objects);
1029 }
1030 if (should_collect_missing()) {
1031 struct missing_objects_map_entry *entry;
1032 struct oidmap_iter iter;
1033
1034 oidmap_iter_init(&missing_objects, &iter);
1035
1036 while ((entry = oidmap_iter_next(&iter))) {
1037 print_missing_object(entry, arg_missing_action ==
1038 MA_PRINT_INFO);
1039 }
1040
1041 oidmap_clear_with_free(&missing_objects, missing_objects_map_entry_free);
1042 }
1043
1044 stop_progress(&progress);
1045
1046 if (revs.count) {
1047 if (revs.left_right && revs.cherry_mark)
1048 printf("%d\t%d\t%d\n", revs.count_left, revs.count_right, revs.count_same);
1049 else if (revs.left_right)
1050 printf("%d\t%d\n", revs.count_left, revs.count_right);
1051 else if (revs.cherry_mark)
1052 printf("%d\t%d\n", revs.count_left + revs.count_right, revs.count_same);
1053 else
1054 printf("%d\n", revs.count_left + revs.count_right);
1055 }
1056
1057 if (show_disk_usage)
1058 print_disk_usage(total_disk_usage);
1059
1060 cleanup:
1061 release_revisions(&revs);
1062 return ret;
1063 }