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