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