]>
Commit | Line | Data |
---|---|---|
64745109 | 1 | #include "cache.h" |
b2141fc1 | 2 | #include "config.h" |
64745109 | 3 | #include "commit.h" |
c4e05b1a | 4 | #include "diff.h" |
ae563542 | 5 | #include "revision.h" |
c64ed70d | 6 | #include "list-objects.h" |
aa32939f VM |
7 | #include "pack.h" |
8 | #include "pack-bitmap.h" | |
5fb61b8d | 9 | #include "builtin.h" |
50e62a8e | 10 | #include "log-tree.h" |
7fefda5c | 11 | #include "graph.h" |
a2ad79ce | 12 | #include "bisect.h" |
434ea3cd | 13 | #include "progress.h" |
7f97de5e | 14 | #include "reflog-walk.h" |
8906300f | 15 | |
a6f68d47 | 16 | static const char rev_list_usage[] = |
1b1dd23f | 17 | "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n" |
69e0c256 | 18 | " limiting output:\n" |
62b4698e ŠN |
19 | " --max-count=<n>\n" |
20 | " --max-age=<epoch>\n" | |
21 | " --min-age=<epoch>\n" | |
69e0c256 JH |
22 | " --sparse\n" |
23 | " --no-merges\n" | |
ad5aeede MG |
24 | " --min-parents=<n>\n" |
25 | " --no-min-parents\n" | |
26 | " --max-parents=<n>\n" | |
27 | " --no-max-parents\n" | |
93b74bca | 28 | " --remove-empty\n" |
69e0c256 | 29 | " --all\n" |
a5aa930d UKK |
30 | " --branches\n" |
31 | " --tags\n" | |
32 | " --remotes\n" | |
42cabc34 | 33 | " --stdin\n" |
27350891 | 34 | " --quiet\n" |
69e0c256 | 35 | " ordering output:\n" |
69e0c256 | 36 | " --topo-order\n" |
4c8725f1 | 37 | " --date-order\n" |
7ccd3667 | 38 | " --reverse\n" |
69e0c256 JH |
39 | " formatting output:\n" |
40 | " --parents\n" | |
72276a3e | 41 | " --children\n" |
c6496575 | 42 | " --objects | --objects-edge\n" |
69e0c256 JH |
43 | " --unpacked\n" |
44 | " --header | --pretty\n" | |
62b4698e | 45 | " --abbrev=<n> | --no-abbrev\n" |
5c51c985 | 46 | " --abbrev-commit\n" |
b24bace5 | 47 | " --left-right\n" |
75d2e5a7 | 48 | " --count\n" |
69e0c256 | 49 | " special purpose:\n" |
457f08a0 | 50 | " --bisect\n" |
50e62a8e CC |
51 | " --bisect-vars\n" |
52 | " --bisect-all" | |
69e0c256 | 53 | ; |
a6f68d47 | 54 | |
434ea3cd JK |
55 | static struct progress *progress; |
56 | static unsigned progress_counter; | |
57 | ||
11c211fa CC |
58 | static void finish_commit(struct commit *commit, void *data); |
59 | static void show_commit(struct commit *commit, void *data) | |
81f2bb1f | 60 | { |
d797257e CC |
61 | struct rev_list_info *info = data; |
62 | struct rev_info *revs = info->revs; | |
11c211fa | 63 | |
434ea3cd JK |
64 | display_progress(progress, ++progress_counter); |
65 | ||
98993722 NTND |
66 | if (info->flags & REV_LIST_QUIET) { |
67 | finish_commit(commit, data); | |
68 | return; | |
69 | } | |
70 | ||
11c211fa | 71 | graph_show_commit(revs->graph); |
7fefda5c | 72 | |
f69c5018 | 73 | if (revs->count) { |
b388e14b MG |
74 | if (commit->object.flags & PATCHSAME) |
75 | revs->count_same++; | |
76 | else if (commit->object.flags & SYMMETRIC_LEFT) | |
f69c5018 TR |
77 | revs->count_left++; |
78 | else | |
79 | revs->count_right++; | |
80 | finish_commit(commit, data); | |
81 | return; | |
82 | } | |
83 | ||
d797257e | 84 | if (info->show_timestamp) |
cb71f8bd | 85 | printf("%"PRItime" ", commit->date); |
d797257e CC |
86 | if (info->header_prefix) |
87 | fputs(info->header_prefix, stdout); | |
7528f27d | 88 | |
1df2d656 MG |
89 | if (!revs->graph) |
90 | fputs(get_revision_mark(revs, commit), stdout); | |
11c211fa | 91 | if (revs->abbrev_commit && revs->abbrev) |
ed1c9977 | 92 | fputs(find_unique_abbrev(commit->object.oid.hash, revs->abbrev), |
7594c4b2 | 93 | stdout); |
5c51c985 | 94 | else |
f2fd0760 | 95 | fputs(oid_to_hex(&commit->object.oid), stdout); |
11c211fa | 96 | if (revs->print_parents) { |
81f2bb1f LT |
97 | struct commit_list *parents = commit->parents; |
98 | while (parents) { | |
f2fd0760 | 99 | printf(" %s", oid_to_hex(&parents->item->object.oid)); |
81f2bb1f LT |
100 | parents = parents->next; |
101 | } | |
102 | } | |
11c211fa | 103 | if (revs->children.name) { |
72276a3e JH |
104 | struct commit_list *children; |
105 | ||
11c211fa | 106 | children = lookup_decoration(&revs->children, &commit->object); |
72276a3e | 107 | while (children) { |
f2fd0760 | 108 | printf(" %s", oid_to_hex(&children->item->object.oid)); |
72276a3e JH |
109 | children = children->next; |
110 | } | |
111 | } | |
11c211fa CC |
112 | show_decorations(revs, commit); |
113 | if (revs->commit_format == CMIT_FMT_ONELINE) | |
d87449c5 JH |
114 | putchar(' '); |
115 | else | |
116 | putchar('\n'); | |
117 | ||
8597ea3a | 118 | if (revs->verbose_header && get_cached_commit_buffer(commit, NULL)) { |
f285a2d7 | 119 | struct strbuf buf = STRBUF_INIT; |
dd2e794a TR |
120 | struct pretty_print_context ctx = {0}; |
121 | ctx.abbrev = revs->abbrev; | |
122 | ctx.date_mode = revs->date_mode; | |
f026c756 | 123 | ctx.date_mode_explicit = revs->date_mode_explicit; |
6bf13944 | 124 | ctx.fmt = revs->commit_format; |
ecaee805 | 125 | ctx.output_encoding = get_log_output_encoding(); |
d75dfb10 | 126 | ctx.color = revs->diffopt.use_color; |
6bf13944 | 127 | pretty_print_commit(&ctx, commit, &buf); |
660e113c JK |
128 | if (buf.len) { |
129 | if (revs->commit_format != CMIT_FMT_ONELINE) | |
130 | graph_show_oneline(revs->graph); | |
7fefda5c | 131 | |
660e113c | 132 | graph_show_commit_msg(revs->graph, stdout, &buf); |
7fefda5c | 133 | |
660e113c JK |
134 | /* |
135 | * Add a newline after the commit message. | |
136 | * | |
137 | * Usually, this newline produces a blank | |
138 | * padding line between entries, in which case | |
139 | * we need to add graph padding on this line. | |
140 | * | |
141 | * However, the commit message may not end in a | |
142 | * newline. In this case the newline simply | |
143 | * ends the last line of the commit message, | |
144 | * and we don't need any graph output. (This | |
145 | * always happens with CMIT_FMT_ONELINE, and it | |
146 | * happens with CMIT_FMT_USERFORMAT when the | |
147 | * format doesn't explicitly end in a newline.) | |
148 | */ | |
149 | if (buf.len && buf.buf[buf.len - 1] == '\n') | |
150 | graph_show_padding(revs->graph); | |
98985c69 | 151 | putchar(info->hdr_termination); |
7fefda5c | 152 | } else { |
660e113c JK |
153 | /* |
154 | * If the message buffer is empty, just show | |
155 | * the rest of the graph output for this | |
156 | * commit. | |
157 | */ | |
158 | if (graph_show_remainder(revs->graph)) | |
159 | putchar('\n'); | |
160 | if (revs->commit_format == CMIT_FMT_ONELINE) | |
161 | putchar('\n'); | |
7fefda5c | 162 | } |
674d1727 | 163 | strbuf_release(&buf); |
7fefda5c | 164 | } else { |
11c211fa | 165 | if (graph_show_remainder(revs->graph)) |
7fefda5c | 166 | putchar('\n'); |
7620d39f | 167 | } |
06f59e9f | 168 | maybe_flush_or_die(stdout, "stdout"); |
11c211fa | 169 | finish_commit(commit, data); |
27350891 SP |
170 | } |
171 | ||
11c211fa | 172 | static void finish_commit(struct commit *commit, void *data) |
27350891 | 173 | { |
cb115748 LT |
174 | if (commit->parents) { |
175 | free_commit_list(commit->parents); | |
176 | commit->parents = NULL; | |
177 | } | |
0fb370da | 178 | free_commit_buffer(commit); |
a3437b8c JS |
179 | } |
180 | ||
de1e67d0 | 181 | static void finish_object(struct object *obj, const char *name, void *cb_data) |
27350891 | 182 | { |
98993722 | 183 | struct rev_list_info *info = cb_data; |
f2fd0760 | 184 | if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid)) |
185 | die("missing blob object '%s'", oid_to_hex(&obj->oid)); | |
98993722 | 186 | if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT) |
c251c83d | 187 | parse_object(&obj->oid); |
27350891 SP |
188 | } |
189 | ||
de1e67d0 | 190 | static void show_object(struct object *obj, const char *name, void *cb_data) |
9de48752 | 191 | { |
cb8da705 | 192 | struct rev_list_info *info = cb_data; |
de1e67d0 | 193 | finish_object(obj, name, cb_data); |
434ea3cd | 194 | display_progress(progress, ++progress_counter); |
98993722 NTND |
195 | if (info->flags & REV_LIST_QUIET) |
196 | return; | |
de1e67d0 | 197 | show_object_with_name(stdout, obj, name); |
9de48752 LT |
198 | } |
199 | ||
8d1d8f83 JH |
200 | static void show_edge(struct commit *commit) |
201 | { | |
f2fd0760 | 202 | printf("-%s\n", oid_to_hex(&commit->object.oid)); |
8d1d8f83 JH |
203 | } |
204 | ||
38ef7507 | 205 | static void print_var_str(const char *var, const char *val) |
280e65cb | 206 | { |
38ef7507 | 207 | printf("%s='%s'\n", var, val); |
280e65cb CC |
208 | } |
209 | ||
38ef7507 | 210 | static void print_var_int(const char *var, int val) |
280e65cb | 211 | { |
38ef7507 | 212 | printf("%s=%d\n", var, val); |
280e65cb CC |
213 | } |
214 | ||
f1c92c63 | 215 | static int show_bisect_vars(struct rev_list_info *info, int reaches, int all) |
9996983c | 216 | { |
98993722 | 217 | int cnt, flags = info->flags; |
dc01505f | 218 | char hex[GIT_MAX_HEXSZ + 1] = ""; |
95188648 | 219 | struct commit_list *tried; |
d797257e | 220 | struct rev_info *revs = info->revs; |
9996983c | 221 | |
8ba8fe04 | 222 | if (!revs->commits) |
9996983c CC |
223 | return 1; |
224 | ||
9af3589e CC |
225 | revs->commits = filter_skipped(revs->commits, &tried, |
226 | flags & BISECT_SHOW_ALL, | |
227 | NULL, NULL); | |
95188648 | 228 | |
9996983c | 229 | /* |
7428d754 | 230 | * revs->commits can reach "reaches" commits among |
9996983c CC |
231 | * "all" commits. If it is good, then there are |
232 | * (all-reaches) commits left to be bisected. | |
233 | * On the other hand, if it is bad, then the set | |
234 | * to bisect is "reaches". | |
235 | * A bisect set of size N has (N-1) commits further | |
236 | * to test, as we already know one bad one. | |
237 | */ | |
238 | cnt = all - reaches; | |
239 | if (cnt < reaches) | |
240 | cnt = reaches; | |
6a17fad7 | 241 | |
95188648 | 242 | if (revs->commits) |
2490574d | 243 | oid_to_hex_r(hex, &revs->commits->item->object.oid); |
9996983c | 244 | |
37c4c38d | 245 | if (flags & BISECT_SHOW_ALL) { |
d797257e | 246 | traverse_commit_list(revs, show_commit, show_object, info); |
9996983c CC |
247 | printf("------\n"); |
248 | } | |
249 | ||
38ef7507 CC |
250 | print_var_str("bisect_rev", hex); |
251 | print_var_int("bisect_nr", cnt - 1); | |
252 | print_var_int("bisect_good", all - reaches - 1); | |
253 | print_var_int("bisect_bad", reaches - 1); | |
254 | print_var_int("bisect_all", all); | |
255 | print_var_int("bisect_steps", estimate_bisect_steps(all)); | |
9996983c CC |
256 | |
257 | return 0; | |
258 | } | |
259 | ||
aa32939f VM |
260 | static int show_object_fast( |
261 | const unsigned char *sha1, | |
262 | enum object_type type, | |
263 | int exclude, | |
264 | uint32_t name_hash, | |
265 | struct packed_git *found_pack, | |
266 | off_t found_offset) | |
267 | { | |
268 | fprintf(stdout, "%s\n", sha1_to_hex(sha1)); | |
269 | return 1; | |
270 | } | |
271 | ||
a633fca0 | 272 | int cmd_rev_list(int argc, const char **argv, const char *prefix) |
64745109 | 273 | { |
11c211fa | 274 | struct rev_info revs; |
d797257e | 275 | struct rev_list_info info; |
d9a83684 | 276 | int i; |
ff62d732 | 277 | int bisect_list = 0; |
457f08a0 | 278 | int bisect_show_vars = 0; |
50e62a8e | 279 | int bisect_find_all = 0; |
aa32939f | 280 | int use_bitmap_index = 0; |
434ea3cd | 281 | const char *show_progress = NULL; |
64745109 | 282 | |
5a88f97c JH |
283 | if (argc == 2 && !strcmp(argv[1], "-h")) |
284 | usage(rev_list_usage); | |
285 | ||
ef90d6d4 | 286 | git_config(git_default_config, NULL); |
a633fca0 | 287 | init_revisions(&revs, prefix); |
7337b138 | 288 | revs.abbrev = DEFAULT_ABBREV; |
7594c4b2 | 289 | revs.commit_format = CMIT_FMT_UNSPECIFIED; |
a4a88b2b | 290 | argc = setup_revisions(argc, argv, &revs, NULL); |
ae563542 | 291 | |
d797257e CC |
292 | memset(&info, 0, sizeof(info)); |
293 | info.revs = &revs; | |
ad3f9a71 LT |
294 | if (revs.bisect) |
295 | bisect_list = 1; | |
d797257e | 296 | |
98993722 NTND |
297 | if (DIFF_OPT_TST(&revs.diffopt, QUICK)) |
298 | info.flags |= REV_LIST_QUIET; | |
fcfda02b | 299 | for (i = 1 ; i < argc; i++) { |
cf484544 | 300 | const char *arg = argv[i]; |
fcfda02b | 301 | |
a6f68d47 | 302 | if (!strcmp(arg, "--header")) { |
7594c4b2 | 303 | revs.verbose_header = 1; |
9d97aa64 LT |
304 | continue; |
305 | } | |
dc68c4ff | 306 | if (!strcmp(arg, "--timestamp")) { |
d797257e | 307 | info.show_timestamp = 1; |
dc68c4ff JH |
308 | continue; |
309 | } | |
8b3a1e05 LT |
310 | if (!strcmp(arg, "--bisect")) { |
311 | bisect_list = 1; | |
312 | continue; | |
313 | } | |
50e62a8e CC |
314 | if (!strcmp(arg, "--bisect-all")) { |
315 | bisect_list = 1; | |
316 | bisect_find_all = 1; | |
98993722 | 317 | info.flags |= BISECT_SHOW_ALL; |
6e46cc0d | 318 | revs.show_decorations = 1; |
50e62a8e CC |
319 | continue; |
320 | } | |
457f08a0 JH |
321 | if (!strcmp(arg, "--bisect-vars")) { |
322 | bisect_list = 1; | |
323 | bisect_show_vars = 1; | |
324 | continue; | |
325 | } | |
aa32939f VM |
326 | if (!strcmp(arg, "--use-bitmap-index")) { |
327 | use_bitmap_index = 1; | |
328 | continue; | |
329 | } | |
330 | if (!strcmp(arg, "--test-bitmap")) { | |
331 | test_bitmap_walk(&revs); | |
332 | return 0; | |
333 | } | |
434ea3cd JK |
334 | if (skip_prefix(arg, "--progress=", &arg)) { |
335 | show_progress = arg; | |
336 | continue; | |
337 | } | |
ae563542 | 338 | usage(rev_list_usage); |
a6f68d47 | 339 | |
fcfda02b | 340 | } |
7594c4b2 JH |
341 | if (revs.commit_format != CMIT_FMT_UNSPECIFIED) { |
342 | /* The command line has a --pretty */ | |
d797257e | 343 | info.hdr_termination = '\n'; |
7594c4b2 | 344 | if (revs.commit_format == CMIT_FMT_ONELINE) |
d797257e | 345 | info.header_prefix = ""; |
7594c4b2 | 346 | else |
d797257e | 347 | info.header_prefix = "commit "; |
7594c4b2 | 348 | } |
db89665f JH |
349 | else if (revs.verbose_header) |
350 | /* Only --header was specified */ | |
351 | revs.commit_format = CMIT_FMT_RAW; | |
fcfda02b | 352 | |
7f97de5e | 353 | if ((!revs.commits && reflog_walk_empty(revs.reflog_info) && |
c01499ef | 354 | (!(revs.tag_objects || revs.tree_objects || revs.blob_objects) && |
0159ba32 JK |
355 | !revs.pending.nr) && |
356 | !revs.rev_input_given) || | |
8c1f0b44 | 357 | revs.diff) |
7b34c2fa LT |
358 | usage(rev_list_usage); |
359 | ||
2aea7a51 JK |
360 | if (revs.show_notes) |
361 | die(_("rev-list does not support display of notes")); | |
362 | ||
80235ba7 JH |
363 | save_commit_buffer = (revs.verbose_header || |
364 | revs.grep_filter.pattern_list || | |
365 | revs.grep_filter.header_list); | |
4e1dc640 JH |
366 | if (bisect_list) |
367 | revs.limited = 1; | |
9181ca2c | 368 | |
434ea3cd JK |
369 | if (show_progress) |
370 | progress = start_progress_delay(show_progress, 0, 0, 2); | |
371 | ||
c8a70d35 | 372 | if (use_bitmap_index && !revs.prune) { |
aa32939f VM |
373 | if (revs.count && !revs.left_right && !revs.cherry_mark) { |
374 | uint32_t commit_count; | |
5c9f9bf3 | 375 | int max_count = revs.max_count; |
aa32939f VM |
376 | if (!prepare_bitmap_walk(&revs)) { |
377 | count_bitmap_commit_list(&commit_count, NULL, NULL, NULL); | |
5c9f9bf3 JK |
378 | if (max_count >= 0 && max_count < commit_count) |
379 | commit_count = max_count; | |
aa32939f VM |
380 | printf("%d\n", commit_count); |
381 | return 0; | |
382 | } | |
fb85db84 JK |
383 | } else if (revs.max_count < 0 && |
384 | revs.tag_objects && revs.tree_objects && revs.blob_objects) { | |
aa32939f VM |
385 | if (!prepare_bitmap_walk(&revs)) { |
386 | traverse_bitmap_commit_list(&show_object_fast); | |
387 | return 0; | |
388 | } | |
389 | } | |
390 | } | |
391 | ||
3d51e1b5 MK |
392 | if (prepare_revision_walk(&revs)) |
393 | die("revision walk setup failed"); | |
a4a88b2b | 394 | if (revs.tree_objects) |
e76a5fb4 | 395 | mark_edges_uninteresting(&revs, show_edge); |
a4a88b2b | 396 | |
457f08a0 JH |
397 | if (bisect_list) { |
398 | int reaches = reaches, all = all; | |
399 | ||
50e62a8e CC |
400 | revs.commits = find_bisection(revs.commits, &reaches, &all, |
401 | bisect_find_all); | |
95188648 | 402 | |
9996983c | 403 | if (bisect_show_vars) |
13858e57 | 404 | return show_bisect_vars(&info, reaches, all); |
457f08a0 | 405 | } |
7b34c2fa | 406 | |
98993722 | 407 | traverse_commit_list(&revs, show_commit, show_object, &info); |
8906300f | 408 | |
434ea3cd JK |
409 | stop_progress(&progress); |
410 | ||
f69c5018 | 411 | if (revs.count) { |
b388e14b MG |
412 | if (revs.left_right && revs.cherry_mark) |
413 | printf("%d\t%d\t%d\n", revs.count_left, revs.count_right, revs.count_same); | |
414 | else if (revs.left_right) | |
f69c5018 | 415 | printf("%d\t%d\n", revs.count_left, revs.count_right); |
b388e14b MG |
416 | else if (revs.cherry_mark) |
417 | printf("%d\t%d\n", revs.count_left + revs.count_right, revs.count_same); | |
f69c5018 TR |
418 | else |
419 | printf("%d\n", revs.count_left + revs.count_right); | |
420 | } | |
421 | ||
64745109 LT |
422 | return 0; |
423 | } |