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