]>
Commit | Line | Data |
---|---|---|
64745109 | 1 | #include "cache.h" |
e091eb93 | 2 | #include "refs.h" |
36f8d174 | 3 | #include "tag.h" |
64745109 | 4 | #include "commit.h" |
9de48752 LT |
5 | #include "tree.h" |
6 | #include "blob.h" | |
1b0c7174 | 7 | #include "tree-walk.h" |
c4e05b1a | 8 | #include "diff.h" |
ae563542 | 9 | #include "revision.h" |
c64ed70d | 10 | #include "list-objects.h" |
5fb61b8d | 11 | #include "builtin.h" |
50e62a8e | 12 | #include "log-tree.h" |
7fefda5c | 13 | #include "graph.h" |
ae563542 | 14 | |
1b65a5aa | 15 | /* bits #0-15 in revision.h */ |
64745109 | 16 | |
1b65a5aa | 17 | #define COUNTED (1u<<16) |
8906300f | 18 | |
a6f68d47 | 19 | static const char rev_list_usage[] = |
1b1dd23f | 20 | "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n" |
69e0c256 JH |
21 | " limiting output:\n" |
22 | " --max-count=nr\n" | |
23 | " --max-age=epoch\n" | |
24 | " --min-age=epoch\n" | |
25 | " --sparse\n" | |
26 | " --no-merges\n" | |
93b74bca | 27 | " --remove-empty\n" |
69e0c256 | 28 | " --all\n" |
a5aa930d UKK |
29 | " --branches\n" |
30 | " --tags\n" | |
31 | " --remotes\n" | |
42cabc34 | 32 | " --stdin\n" |
27350891 | 33 | " --quiet\n" |
69e0c256 | 34 | " ordering output:\n" |
69e0c256 | 35 | " --topo-order\n" |
4c8725f1 | 36 | " --date-order\n" |
7ccd3667 | 37 | " --reverse\n" |
69e0c256 JH |
38 | " formatting output:\n" |
39 | " --parents\n" | |
72276a3e | 40 | " --children\n" |
c6496575 | 41 | " --objects | --objects-edge\n" |
69e0c256 JH |
42 | " --unpacked\n" |
43 | " --header | --pretty\n" | |
9da5c2f0 | 44 | " --abbrev=nr | --no-abbrev\n" |
5c51c985 | 45 | " --abbrev-commit\n" |
b24bace5 | 46 | " --left-right\n" |
69e0c256 | 47 | " special purpose:\n" |
457f08a0 | 48 | " --bisect\n" |
50e62a8e CC |
49 | " --bisect-vars\n" |
50 | " --bisect-all" | |
69e0c256 | 51 | ; |
a6f68d47 | 52 | |
5fb61b8d | 53 | static struct rev_info revs; |
ae563542 | 54 | |
96f1e58f DR |
55 | static int bisect_list; |
56 | static int show_timestamp; | |
57 | static int hdr_termination; | |
91539833 | 58 | static const char *header_prefix; |
e646de0d | 59 | |
27350891 | 60 | static void finish_commit(struct commit *commit); |
81f2bb1f LT |
61 | static void show_commit(struct commit *commit) |
62 | { | |
7fefda5c AS |
63 | graph_show_commit(revs.graph); |
64 | ||
dc68c4ff JH |
65 | if (show_timestamp) |
66 | printf("%lu ", commit->date); | |
91539833 LT |
67 | if (header_prefix) |
68 | fputs(header_prefix, stdout); | |
7528f27d AS |
69 | |
70 | if (!revs.graph) { | |
71 | if (commit->object.flags & BOUNDARY) | |
72 | putchar('-'); | |
73 | else if (commit->object.flags & UNINTERESTING) | |
74 | putchar('^'); | |
75 | else if (revs.left_right) { | |
76 | if (commit->object.flags & SYMMETRIC_LEFT) | |
77 | putchar('<'); | |
78 | else | |
79 | putchar('>'); | |
80 | } | |
577ed5c2 | 81 | } |
7594c4b2 JH |
82 | if (revs.abbrev_commit && revs.abbrev) |
83 | fputs(find_unique_abbrev(commit->object.sha1, revs.abbrev), | |
84 | stdout); | |
5c51c985 JH |
85 | else |
86 | fputs(sha1_to_hex(commit->object.sha1), stdout); | |
885cf808 | 87 | if (revs.print_parents) { |
81f2bb1f LT |
88 | struct commit_list *parents = commit->parents; |
89 | while (parents) { | |
1ed84157 | 90 | printf(" %s", sha1_to_hex(parents->item->object.sha1)); |
81f2bb1f LT |
91 | parents = parents->next; |
92 | } | |
93 | } | |
72276a3e JH |
94 | if (revs.children.name) { |
95 | struct commit_list *children; | |
96 | ||
97 | children = lookup_decoration(&revs.children, &commit->object); | |
98 | while (children) { | |
99 | printf(" %s", sha1_to_hex(children->item->object.sha1)); | |
100 | children = children->next; | |
101 | } | |
102 | } | |
0f3a290b | 103 | show_decorations(&revs, commit); |
7594c4b2 | 104 | if (revs.commit_format == CMIT_FMT_ONELINE) |
d87449c5 JH |
105 | putchar(' '); |
106 | else | |
107 | putchar('\n'); | |
108 | ||
3131b713 | 109 | if (revs.verbose_header && commit->buffer) { |
f285a2d7 | 110 | struct strbuf buf = STRBUF_INIT; |
674d1727 | 111 | pretty_print_commit(revs.commit_format, commit, |
4593fb84 JH |
112 | &buf, revs.abbrev, NULL, NULL, |
113 | revs.date_mode, 0); | |
7fefda5c AS |
114 | if (revs.graph) { |
115 | if (buf.len) { | |
116 | if (revs.commit_format != CMIT_FMT_ONELINE) | |
117 | graph_show_oneline(revs.graph); | |
118 | ||
119 | graph_show_commit_msg(revs.graph, &buf); | |
120 | ||
121 | /* | |
122 | * Add a newline after the commit message. | |
123 | * | |
124 | * Usually, this newline produces a blank | |
125 | * padding line between entries, in which case | |
126 | * we need to add graph padding on this line. | |
127 | * | |
128 | * However, the commit message may not end in a | |
129 | * newline. In this case the newline simply | |
130 | * ends the last line of the commit message, | |
131 | * and we don't need any graph output. (This | |
132 | * always happens with CMIT_FMT_ONELINE, and it | |
133 | * happens with CMIT_FMT_USERFORMAT when the | |
134 | * format doesn't explicitly end in a newline.) | |
135 | */ | |
136 | if (buf.len && buf.buf[buf.len - 1] == '\n') | |
137 | graph_show_padding(revs.graph); | |
138 | putchar('\n'); | |
139 | } else { | |
140 | /* | |
141 | * If the message buffer is empty, just show | |
142 | * the rest of the graph output for this | |
143 | * commit. | |
144 | */ | |
145 | if (graph_show_remainder(revs.graph)) | |
146 | putchar('\n'); | |
147 | } | |
148 | } else { | |
149 | if (buf.len) | |
150 | printf("%s%c", buf.buf, hdr_termination); | |
151 | } | |
674d1727 | 152 | strbuf_release(&buf); |
7fefda5c AS |
153 | } else { |
154 | if (graph_show_remainder(revs.graph)) | |
155 | putchar('\n'); | |
7620d39f | 156 | } |
06f59e9f | 157 | maybe_flush_or_die(stdout, "stdout"); |
27350891 SP |
158 | finish_commit(commit); |
159 | } | |
160 | ||
161 | static void finish_commit(struct commit *commit) | |
162 | { | |
cb115748 LT |
163 | if (commit->parents) { |
164 | free_commit_list(commit->parents); | |
165 | commit->parents = NULL; | |
166 | } | |
4cac42b1 JH |
167 | free(commit->buffer); |
168 | commit->buffer = NULL; | |
a3437b8c JS |
169 | } |
170 | ||
27350891 SP |
171 | static void finish_object(struct object_array_entry *p) |
172 | { | |
173 | if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1)) | |
174 | die("missing blob object '%s'", sha1_to_hex(p->item->sha1)); | |
175 | } | |
176 | ||
c64ed70d | 177 | static void show_object(struct object_array_entry *p) |
9de48752 | 178 | { |
c64ed70d | 179 | /* An object with name "foo\n0000000..." can be used to |
f18d244a | 180 | * confuse downstream "git pack-objects" very badly. |
c64ed70d JH |
181 | */ |
182 | const char *ep = strchr(p->name, '\n'); | |
b9849a1a | 183 | |
27350891 | 184 | finish_object(p); |
c64ed70d JH |
185 | if (ep) { |
186 | printf("%s %.*s\n", sha1_to_hex(p->item->sha1), | |
187 | (int) (ep - p->name), | |
188 | p->name); | |
9de48752 | 189 | } |
c64ed70d JH |
190 | else |
191 | printf("%s %s\n", sha1_to_hex(p->item->sha1), p->name); | |
9de48752 LT |
192 | } |
193 | ||
8d1d8f83 JH |
194 | static void show_edge(struct commit *commit) |
195 | { | |
196 | printf("-%s\n", sha1_to_hex(commit->object.sha1)); | |
197 | } | |
198 | ||
8b3a1e05 LT |
199 | /* |
200 | * This is a truly stupid algorithm, but it's only | |
201 | * used for bisection, and we just don't care enough. | |
202 | * | |
203 | * We care just barely enough to avoid recursing for | |
204 | * non-merge entries. | |
205 | */ | |
206 | static int count_distance(struct commit_list *entry) | |
207 | { | |
208 | int nr = 0; | |
209 | ||
210 | while (entry) { | |
211 | struct commit *commit = entry->item; | |
212 | struct commit_list *p; | |
213 | ||
214 | if (commit->object.flags & (UNINTERESTING | COUNTED)) | |
215 | break; | |
7dc0fe3b | 216 | if (!(commit->object.flags & TREESAME)) |
b3cfd939 | 217 | nr++; |
8b3a1e05 LT |
218 | commit->object.flags |= COUNTED; |
219 | p = commit->parents; | |
220 | entry = p; | |
221 | if (p) { | |
222 | p = p->next; | |
223 | while (p) { | |
224 | nr += count_distance(p); | |
225 | p = p->next; | |
226 | } | |
227 | } | |
228 | } | |
b3cfd939 | 229 | |
8b3a1e05 LT |
230 | return nr; |
231 | } | |
232 | ||
3d958064 | 233 | static void clear_distance(struct commit_list *list) |
8b3a1e05 LT |
234 | { |
235 | while (list) { | |
236 | struct commit *commit = list->item; | |
237 | commit->object.flags &= ~COUNTED; | |
238 | list = list->next; | |
239 | } | |
240 | } | |
241 | ||
1daa09d9 | 242 | #define DEBUG_BISECT 0 |
1c4fea3a JH |
243 | |
244 | static inline int weight(struct commit_list *elem) | |
245 | { | |
246 | return *((int*)(elem->item->util)); | |
247 | } | |
248 | ||
249 | static inline void weight_set(struct commit_list *elem, int weight) | |
250 | { | |
251 | *((int*)(elem->item->util)) = weight; | |
252 | } | |
253 | ||
1daa09d9 | 254 | static int count_interesting_parents(struct commit *commit) |
1c4fea3a | 255 | { |
1daa09d9 JH |
256 | struct commit_list *p; |
257 | int count; | |
258 | ||
259 | for (count = 0, p = commit->parents; p; p = p->next) { | |
260 | if (p->item->object.flags & UNINTERESTING) | |
261 | continue; | |
262 | count++; | |
1c4fea3a | 263 | } |
1daa09d9 | 264 | return count; |
1c4fea3a JH |
265 | } |
266 | ||
53271411 | 267 | static inline int halfway(struct commit_list *p, int nr) |
2a464690 JH |
268 | { |
269 | /* | |
270 | * Don't short-cut something we are not going to return! | |
271 | */ | |
7dc0fe3b | 272 | if (p->item->object.flags & TREESAME) |
2a464690 | 273 | return 0; |
1daa09d9 JH |
274 | if (DEBUG_BISECT) |
275 | return 0; | |
2a464690 JH |
276 | /* |
277 | * 2 and 3 are halfway of 5. | |
278 | * 3 is halfway of 6 but 2 and 4 are not. | |
279 | */ | |
53271411 | 280 | switch (2 * weight(p) - nr) { |
2a464690 JH |
281 | case -1: case 0: case 1: |
282 | return 1; | |
283 | default: | |
284 | return 0; | |
285 | } | |
286 | } | |
287 | ||
1daa09d9 JH |
288 | #if !DEBUG_BISECT |
289 | #define show_list(a,b,c,d) do { ; } while (0) | |
290 | #else | |
291 | static void show_list(const char *debug, int counted, int nr, | |
292 | struct commit_list *list) | |
1c4fea3a | 293 | { |
1daa09d9 JH |
294 | struct commit_list *p; |
295 | ||
296 | fprintf(stderr, "%s (%d/%d)\n", debug, counted, nr); | |
297 | ||
298 | for (p = list; p; p = p->next) { | |
299 | struct commit_list *pp; | |
300 | struct commit *commit = p->item; | |
301 | unsigned flags = commit->object.flags; | |
302 | enum object_type type; | |
303 | unsigned long size; | |
304 | char *buf = read_sha1_file(commit->object.sha1, &type, &size); | |
305 | char *ep, *sp; | |
306 | ||
307 | fprintf(stderr, "%c%c%c ", | |
7dc0fe3b | 308 | (flags & TREESAME) ? ' ' : 'T', |
1daa09d9 JH |
309 | (flags & UNINTERESTING) ? 'U' : ' ', |
310 | (flags & COUNTED) ? 'C' : ' '); | |
311 | if (commit->util) | |
312 | fprintf(stderr, "%3d", weight(p)); | |
313 | else | |
314 | fprintf(stderr, "---"); | |
315 | fprintf(stderr, " %.*s", 8, sha1_to_hex(commit->object.sha1)); | |
316 | for (pp = commit->parents; pp; pp = pp->next) | |
317 | fprintf(stderr, " %.*s", 8, | |
318 | sha1_to_hex(pp->item->object.sha1)); | |
319 | ||
320 | sp = strstr(buf, "\n\n"); | |
321 | if (sp) { | |
322 | sp += 2; | |
323 | for (ep = sp; *ep && *ep != '\n'; ep++) | |
324 | ; | |
325 | fprintf(stderr, " %.*s", (int)(ep - sp), sp); | |
326 | } | |
327 | fprintf(stderr, "\n"); | |
328 | } | |
329 | } | |
330 | #endif /* DEBUG_BISECT */ | |
331 | ||
77c11e06 CC |
332 | static struct commit_list *best_bisection(struct commit_list *list, int nr) |
333 | { | |
334 | struct commit_list *p, *best; | |
335 | int best_distance = -1; | |
336 | ||
337 | best = list; | |
338 | for (p = list; p; p = p->next) { | |
339 | int distance; | |
340 | unsigned flags = p->item->object.flags; | |
341 | ||
7dc0fe3b | 342 | if (flags & TREESAME) |
77c11e06 CC |
343 | continue; |
344 | distance = weight(p); | |
345 | if (nr - distance < distance) | |
346 | distance = nr - distance; | |
347 | if (distance > best_distance) { | |
348 | best = p; | |
349 | best_distance = distance; | |
350 | } | |
351 | } | |
352 | ||
353 | return best; | |
354 | } | |
355 | ||
50e62a8e CC |
356 | struct commit_dist { |
357 | struct commit *commit; | |
358 | int distance; | |
359 | }; | |
360 | ||
361 | static int compare_commit_dist(const void *a_, const void *b_) | |
362 | { | |
363 | struct commit_dist *a, *b; | |
364 | ||
365 | a = (struct commit_dist *)a_; | |
366 | b = (struct commit_dist *)b_; | |
367 | if (a->distance != b->distance) | |
368 | return b->distance - a->distance; /* desc sort */ | |
369 | return hashcmp(a->commit->object.sha1, b->commit->object.sha1); | |
370 | } | |
371 | ||
372 | static struct commit_list *best_bisection_sorted(struct commit_list *list, int nr) | |
373 | { | |
374 | struct commit_list *p; | |
375 | struct commit_dist *array = xcalloc(nr, sizeof(*array)); | |
376 | int cnt, i; | |
377 | ||
378 | for (p = list, cnt = 0; p; p = p->next) { | |
379 | int distance; | |
380 | unsigned flags = p->item->object.flags; | |
381 | ||
7dc0fe3b | 382 | if (flags & TREESAME) |
50e62a8e CC |
383 | continue; |
384 | distance = weight(p); | |
385 | if (nr - distance < distance) | |
386 | distance = nr - distance; | |
387 | array[cnt].commit = p->item; | |
388 | array[cnt].distance = distance; | |
389 | cnt++; | |
390 | } | |
391 | qsort(array, cnt, sizeof(*array), compare_commit_dist); | |
392 | for (p = list, i = 0; i < cnt; i++) { | |
393 | struct name_decoration *r = xmalloc(sizeof(*r) + 100); | |
394 | struct object *obj = &(array[i].commit->object); | |
395 | ||
396 | sprintf(r->name, "dist=%d", array[i].distance); | |
397 | r->next = add_decoration(&name_decoration, obj, r); | |
398 | p->item = array[i].commit; | |
399 | p = p->next; | |
400 | } | |
401 | if (p) | |
402 | p->next = NULL; | |
403 | free(array); | |
404 | return list; | |
405 | } | |
406 | ||
1daa09d9 JH |
407 | /* |
408 | * zero or positive weight is the number of interesting commits it can | |
409 | * reach, including itself. Especially, weight = 0 means it does not | |
410 | * reach any tree-changing commits (e.g. just above uninteresting one | |
411 | * but traversal is with pathspec). | |
412 | * | |
413 | * weight = -1 means it has one parent and its distance is yet to | |
414 | * be computed. | |
415 | * | |
416 | * weight = -2 means it has more than one parent and its distance is | |
417 | * unknown. After running count_distance() first, they will get zero | |
418 | * or positive distance. | |
419 | */ | |
ce0cbad7 | 420 | static struct commit_list *do_find_bisection(struct commit_list *list, |
50e62a8e CC |
421 | int nr, int *weights, |
422 | int find_all) | |
1daa09d9 | 423 | { |
53271411 | 424 | int n, counted; |
77c11e06 | 425 | struct commit_list *p; |
1daa09d9 | 426 | |
1c4fea3a JH |
427 | counted = 0; |
428 | ||
429 | for (n = 0, p = list; p; p = p->next) { | |
1daa09d9 JH |
430 | struct commit *commit = p->item; |
431 | unsigned flags = commit->object.flags; | |
432 | ||
433 | p->item->util = &weights[n++]; | |
434 | switch (count_interesting_parents(commit)) { | |
435 | case 0: | |
7dc0fe3b | 436 | if (!(flags & TREESAME)) { |
1c4fea3a JH |
437 | weight_set(p, 1); |
438 | counted++; | |
1daa09d9 JH |
439 | show_list("bisection 2 count one", |
440 | counted, nr, list); | |
1c4fea3a | 441 | } |
1daa09d9 JH |
442 | /* |
443 | * otherwise, it is known not to reach any | |
444 | * tree-changing commit and gets weight 0. | |
445 | */ | |
446 | break; | |
447 | case 1: | |
448 | weight_set(p, -1); | |
449 | break; | |
450 | default: | |
451 | weight_set(p, -2); | |
452 | break; | |
1c4fea3a JH |
453 | } |
454 | } | |
455 | ||
1daa09d9 JH |
456 | show_list("bisection 2 initialize", counted, nr, list); |
457 | ||
1c4fea3a JH |
458 | /* |
459 | * If you have only one parent in the resulting set | |
460 | * then you can reach one commit more than that parent | |
461 | * can reach. So we do not have to run the expensive | |
462 | * count_distance() for single strand of pearls. | |
463 | * | |
464 | * However, if you have more than one parents, you cannot | |
465 | * just add their distance and one for yourself, since | |
466 | * they usually reach the same ancestor and you would | |
467 | * end up counting them twice that way. | |
468 | * | |
469 | * So we will first count distance of merges the usual | |
470 | * way, and then fill the blanks using cheaper algorithm. | |
471 | */ | |
472 | for (p = list; p; p = p->next) { | |
1daa09d9 | 473 | if (p->item->object.flags & UNINTERESTING) |
1c4fea3a | 474 | continue; |
53271411 | 475 | if (weight(p) != -2) |
1c4fea3a | 476 | continue; |
53271411 | 477 | weight_set(p, count_distance(p)); |
1daa09d9 | 478 | clear_distance(list); |
1c4fea3a JH |
479 | |
480 | /* Does it happen to be at exactly half-way? */ | |
50e62a8e | 481 | if (!find_all && halfway(p, nr)) |
1c4fea3a | 482 | return p; |
1c4fea3a JH |
483 | counted++; |
484 | } | |
485 | ||
1daa09d9 JH |
486 | show_list("bisection 2 count_distance", counted, nr, list); |
487 | ||
1c4fea3a JH |
488 | while (counted < nr) { |
489 | for (p = list; p; p = p->next) { | |
490 | struct commit_list *q; | |
1daa09d9 | 491 | unsigned flags = p->item->object.flags; |
1c4fea3a | 492 | |
1daa09d9 | 493 | if (0 <= weight(p)) |
1c4fea3a | 494 | continue; |
1daa09d9 JH |
495 | for (q = p->item->parents; q; q = q->next) { |
496 | if (q->item->object.flags & UNINTERESTING) | |
497 | continue; | |
498 | if (0 <= weight(q)) | |
1c4fea3a | 499 | break; |
1daa09d9 | 500 | } |
1c4fea3a JH |
501 | if (!q) |
502 | continue; | |
1daa09d9 JH |
503 | |
504 | /* | |
505 | * weight for p is unknown but q is known. | |
506 | * add one for p itself if p is to be counted, | |
507 | * otherwise inherit it from q directly. | |
508 | */ | |
7dc0fe3b | 509 | if (!(flags & TREESAME)) { |
1daa09d9 JH |
510 | weight_set(p, weight(q)+1); |
511 | counted++; | |
512 | show_list("bisection 2 count one", | |
513 | counted, nr, list); | |
514 | } | |
515 | else | |
516 | weight_set(p, weight(q)); | |
1c4fea3a JH |
517 | |
518 | /* Does it happen to be at exactly half-way? */ | |
50e62a8e | 519 | if (!find_all && halfway(p, nr)) |
1c4fea3a | 520 | return p; |
1c4fea3a JH |
521 | } |
522 | } | |
523 | ||
1daa09d9 JH |
524 | show_list("bisection 2 counted all", counted, nr, list); |
525 | ||
50e62a8e CC |
526 | if (!find_all) |
527 | return best_bisection(list, nr); | |
528 | else | |
529 | return best_bisection_sorted(list, nr); | |
ce0cbad7 CC |
530 | } |
531 | ||
532 | static struct commit_list *find_bisection(struct commit_list *list, | |
50e62a8e CC |
533 | int *reaches, int *all, |
534 | int find_all) | |
ce0cbad7 CC |
535 | { |
536 | int nr, on_list; | |
537 | struct commit_list *p, *best, *next, *last; | |
538 | int *weights; | |
539 | ||
540 | show_list("bisection 2 entry", 0, 0, list); | |
541 | ||
542 | /* | |
543 | * Count the number of total and tree-changing items on the | |
544 | * list, while reversing the list. | |
545 | */ | |
546 | for (nr = on_list = 0, last = NULL, p = list; | |
547 | p; | |
548 | p = next) { | |
549 | unsigned flags = p->item->object.flags; | |
550 | ||
551 | next = p->next; | |
552 | if (flags & UNINTERESTING) | |
553 | continue; | |
554 | p->next = last; | |
555 | last = p; | |
7dc0fe3b | 556 | if (!(flags & TREESAME)) |
ce0cbad7 CC |
557 | nr++; |
558 | on_list++; | |
559 | } | |
560 | list = last; | |
561 | show_list("bisection 2 sorted", 0, nr, list); | |
562 | ||
563 | *all = nr; | |
564 | weights = xcalloc(on_list, sizeof(*weights)); | |
565 | ||
566 | /* Do the real work of finding bisection commit. */ | |
50e62a8e | 567 | best = do_find_bisection(list, nr, weights, find_all); |
17ed1580 | 568 | if (best) { |
50e62a8e CC |
569 | if (!find_all) |
570 | best->next = NULL; | |
17ed1580 CC |
571 | *reaches = weight(best); |
572 | } | |
1c4fea3a JH |
573 | free(weights); |
574 | return best; | |
575 | } | |
576 | ||
a633fca0 | 577 | int cmd_rev_list(int argc, const char **argv, const char *prefix) |
64745109 | 578 | { |
ae563542 | 579 | struct commit_list *list; |
d9a83684 | 580 | int i; |
42cabc34 | 581 | int read_from_stdin = 0; |
457f08a0 | 582 | int bisect_show_vars = 0; |
50e62a8e | 583 | int bisect_find_all = 0; |
27350891 | 584 | int quiet = 0; |
64745109 | 585 | |
ef90d6d4 | 586 | git_config(git_default_config, NULL); |
a633fca0 | 587 | init_revisions(&revs, prefix); |
7594c4b2 JH |
588 | revs.abbrev = 0; |
589 | revs.commit_format = CMIT_FMT_UNSPECIFIED; | |
a4a88b2b | 590 | argc = setup_revisions(argc, argv, &revs, NULL); |
ae563542 | 591 | |
d85fe389 | 592 | quiet = DIFF_OPT_TST(&revs.diffopt, QUIET); |
fcfda02b | 593 | for (i = 1 ; i < argc; i++) { |
cf484544 | 594 | const char *arg = argv[i]; |
fcfda02b | 595 | |
a6f68d47 | 596 | if (!strcmp(arg, "--header")) { |
7594c4b2 | 597 | revs.verbose_header = 1; |
9d97aa64 LT |
598 | continue; |
599 | } | |
dc68c4ff JH |
600 | if (!strcmp(arg, "--timestamp")) { |
601 | show_timestamp = 1; | |
602 | continue; | |
603 | } | |
8b3a1e05 LT |
604 | if (!strcmp(arg, "--bisect")) { |
605 | bisect_list = 1; | |
606 | continue; | |
607 | } | |
50e62a8e CC |
608 | if (!strcmp(arg, "--bisect-all")) { |
609 | bisect_list = 1; | |
610 | bisect_find_all = 1; | |
611 | continue; | |
612 | } | |
457f08a0 JH |
613 | if (!strcmp(arg, "--bisect-vars")) { |
614 | bisect_list = 1; | |
615 | bisect_show_vars = 1; | |
616 | continue; | |
617 | } | |
42cabc34 JH |
618 | if (!strcmp(arg, "--stdin")) { |
619 | if (read_from_stdin++) | |
620 | die("--stdin given twice?"); | |
621 | read_revisions_from_stdin(&revs); | |
622 | continue; | |
623 | } | |
ae563542 | 624 | usage(rev_list_usage); |
a6f68d47 | 625 | |
fcfda02b | 626 | } |
7594c4b2 JH |
627 | if (revs.commit_format != CMIT_FMT_UNSPECIFIED) { |
628 | /* The command line has a --pretty */ | |
629 | hdr_termination = '\n'; | |
630 | if (revs.commit_format == CMIT_FMT_ONELINE) | |
91539833 | 631 | header_prefix = ""; |
7594c4b2 | 632 | else |
91539833 | 633 | header_prefix = "commit "; |
7594c4b2 | 634 | } |
db89665f JH |
635 | else if (revs.verbose_header) |
636 | /* Only --header was specified */ | |
637 | revs.commit_format = CMIT_FMT_RAW; | |
fcfda02b | 638 | |
ae563542 | 639 | list = revs.commits; |
ae563542 | 640 | |
8c1f0b44 JH |
641 | if ((!list && |
642 | (!(revs.tag_objects||revs.tree_objects||revs.blob_objects) && | |
1f1e895f | 643 | !revs.pending.nr)) || |
8c1f0b44 | 644 | revs.diff) |
7b34c2fa LT |
645 | usage(rev_list_usage); |
646 | ||
0843acfd JK |
647 | save_commit_buffer = revs.verbose_header || |
648 | revs.grep_filter.pattern_list; | |
4e1dc640 JH |
649 | if (bisect_list) |
650 | revs.limited = 1; | |
9181ca2c | 651 | |
3d51e1b5 MK |
652 | if (prepare_revision_walk(&revs)) |
653 | die("revision walk setup failed"); | |
a4a88b2b | 654 | if (revs.tree_objects) |
8d1d8f83 | 655 | mark_edges_uninteresting(revs.commits, &revs, show_edge); |
a4a88b2b | 656 | |
457f08a0 JH |
657 | if (bisect_list) { |
658 | int reaches = reaches, all = all; | |
659 | ||
50e62a8e CC |
660 | revs.commits = find_bisection(revs.commits, &reaches, &all, |
661 | bisect_find_all); | |
457f08a0 JH |
662 | if (bisect_show_vars) { |
663 | int cnt; | |
50e62a8e | 664 | char hex[41]; |
457f08a0 JH |
665 | if (!revs.commits) |
666 | return 1; | |
667 | /* | |
668 | * revs.commits can reach "reaches" commits among | |
669 | * "all" commits. If it is good, then there are | |
670 | * (all-reaches) commits left to be bisected. | |
671 | * On the other hand, if it is bad, then the set | |
672 | * to bisect is "reaches". | |
673 | * A bisect set of size N has (N-1) commits further | |
674 | * to test, as we already know one bad one. | |
675 | */ | |
50e62a8e | 676 | cnt = all - reaches; |
457f08a0 JH |
677 | if (cnt < reaches) |
678 | cnt = reaches; | |
50e62a8e CC |
679 | strcpy(hex, sha1_to_hex(revs.commits->item->object.sha1)); |
680 | ||
681 | if (bisect_find_all) { | |
682 | traverse_commit_list(&revs, show_commit, show_object); | |
683 | printf("------\n"); | |
684 | } | |
685 | ||
457f08a0 JH |
686 | printf("bisect_rev=%s\n" |
687 | "bisect_nr=%d\n" | |
688 | "bisect_good=%d\n" | |
689 | "bisect_bad=%d\n" | |
690 | "bisect_all=%d\n", | |
50e62a8e | 691 | hex, |
457f08a0 JH |
692 | cnt - 1, |
693 | all - reaches - 1, | |
694 | reaches - 1, | |
695 | all); | |
696 | return 0; | |
697 | } | |
698 | } | |
7b34c2fa | 699 | |
27350891 SP |
700 | traverse_commit_list(&revs, |
701 | quiet ? finish_commit : show_commit, | |
702 | quiet ? finish_object : show_object); | |
8906300f | 703 | |
64745109 LT |
704 | return 0; |
705 | } |