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