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