@matheusbsbs / matheus-bagliano / commits / 50e62a8e70
Fork 0

rev-list: implement --bisect-all

This is Junio's patch with some stuff to make --bisect-all compatible with --bisect-vars. This option makes it possible to see all the potential bisection points. The best ones are displayed first. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Christian Couder committed Oct 22, 2007 at 07:47 UTC 50e62a8e703b78fbe59d5f98b1bb36464570a815
3 files changed +88 -15
builtin-rev-list.c
+86 -14
@@ -9,6 +9,7 @@
9 #include "revision.h"
10 #include "list-objects.h"
11 #include "builtin.h"
12 +#include "log-tree.h"
13
14 /* bits #0-15 in revision.h */
15
@@ -38,7 +39,8 @@ static const char rev_list_usage[] =
39 " --left-right\n"
40 " special purpose:\n"
41 " --bisect\n"
41 -" --bisect-vars"
42 +" --bisect-vars\n"
43 +" --bisect-all"
44 ;
45
46 static struct rev_info revs;
@@ -74,6 +76,7 @@ static void show_commit(struct commit *commit)
76 parents = parents->next;
77 }
78 }
79 + show_decorations(commit);
80 if (revs.commit_format == CMIT_FMT_ONELINE)
81 putchar(' ');
82 else
@@ -278,6 +281,57 @@ static struct commit_list *best_bisection(struct commit_list *list, int nr)
281 return best;
282 }
283
284 +struct commit_dist {
285 + struct commit *commit;
286 + int distance;
287 +};
288 +
289 +static int compare_commit_dist(const void *a_, const void *b_)
290 +{
291 + struct commit_dist *a, *b;
292 +
293 + a = (struct commit_dist *)a_;
294 + b = (struct commit_dist *)b_;
295 + if (a->distance != b->distance)
296 + return b->distance - a->distance; /* desc sort */
297 + return hashcmp(a->commit->object.sha1, b->commit->object.sha1);
298 +}
299 +
300 +static struct commit_list *best_bisection_sorted(struct commit_list *list, int nr)
301 +{
302 + struct commit_list *p;
303 + struct commit_dist *array = xcalloc(nr, sizeof(*array));
304 + int cnt, i;
305 +
306 + for (p = list, cnt = 0; p; p = p->next) {
307 + int distance;
308 + unsigned flags = p->item->object.flags;
309 +
310 + if (revs.prune_fn && !(flags & TREECHANGE))
311 + continue;
312 + distance = weight(p);
313 + if (nr - distance < distance)
314 + distance = nr - distance;
315 + array[cnt].commit = p->item;
316 + array[cnt].distance = distance;
317 + cnt++;
318 + }
319 + qsort(array, cnt, sizeof(*array), compare_commit_dist);
320 + for (p = list, i = 0; i < cnt; i++) {
321 + struct name_decoration *r = xmalloc(sizeof(*r) + 100);
322 + struct object *obj = &(array[i].commit->object);
323 +
324 + sprintf(r->name, "dist=%d", array[i].distance);
325 + r->next = add_decoration(&name_decoration, obj, r);
326 + p->item = array[i].commit;
327 + p = p->next;
328 + }
329 + if (p)
330 + p->next = NULL;
331 + free(array);
332 + return list;
333 +}
334 +
335 /*
336 * zero or positive weight is the number of interesting commits it can
337 * reach, including itself. Especially, weight = 0 means it does not
@@ -292,7 +346,8 @@ static struct commit_list *best_bisection(struct commit_list *list, int nr)
346 * or positive distance.
347 */
348 static struct commit_list *do_find_bisection(struct commit_list *list,
295 - int nr, int *weights)
349 + int nr, int *weights,
350 + int find_all)
351 {
352 int n, counted;
353 struct commit_list *p;
@@ -351,7 +406,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
406 clear_distance(list);
407
408 /* Does it happen to be at exactly half-way? */
354 - if (halfway(p, nr))
409 + if (!find_all && halfway(p, nr))
410 return p;
411 counted++;
412 }
@@ -389,19 +444,22 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
444 weight_set(p, weight(q));
445
446 /* Does it happen to be at exactly half-way? */
392 - if (halfway(p, nr))
447 + if (!find_all && halfway(p, nr))
448 return p;
449 }
450 }
451
452 show_list("bisection 2 counted all", counted, nr, list);
453
399 - /* Then find the best one */
400 - return best_bisection(list, nr);
454 + if (!find_all)
455 + return best_bisection(list, nr);
456 + else
457 + return best_bisection_sorted(list, nr);
458 }
459
460 static struct commit_list *find_bisection(struct commit_list *list,
404 - int *reaches, int *all)
461 + int *reaches, int *all,
462 + int find_all)
463 {
464 int nr, on_list;
465 struct commit_list *p, *best, *next, *last;
@@ -434,14 +492,13 @@ static struct commit_list *find_bisection(struct commit_list *list,
492 weights = xcalloc(on_list, sizeof(*weights));
493
494 /* Do the real work of finding bisection commit. */
437 - best = do_find_bisection(list, nr, weights);
438 -
495 + best = do_find_bisection(list, nr, weights, find_all);
496 if (best) {
440 - best->next = NULL;
497 + if (!find_all)
498 + best->next = NULL;
499 *reaches = weight(best);
500 }
501 free(weights);
444 -
502 return best;
503 }
504
@@ -468,6 +525,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
525 int i;
526 int read_from_stdin = 0;
527 int bisect_show_vars = 0;
528 + int bisect_find_all = 0;
529
530 git_config(git_default_config);
531 init_revisions(&revs, prefix);
@@ -490,6 +548,11 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
548 bisect_list = 1;
549 continue;
550 }
551 + if (!strcmp(arg, "--bisect-all")) {
552 + bisect_list = 1;
553 + bisect_find_all = 1;
554 + continue;
555 + }
556 if (!strcmp(arg, "--bisect-vars")) {
557 bisect_list = 1;
558 bisect_show_vars = 1;
@@ -536,9 +599,11 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
599 if (bisect_list) {
600 int reaches = reaches, all = all;
601
539 - revs.commits = find_bisection(revs.commits, &reaches, &all);
602 + revs.commits = find_bisection(revs.commits, &reaches, &all,
603 + bisect_find_all);
604 if (bisect_show_vars) {
605 int cnt;
606 + char hex[41];
607 if (!revs.commits)
608 return 1;
609 /*
@@ -550,15 +615,22 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
615 * A bisect set of size N has (N-1) commits further
616 * to test, as we already know one bad one.
617 */
553 - cnt = all-reaches;
618 + cnt = all - reaches;
619 if (cnt < reaches)
620 cnt = reaches;
621 + strcpy(hex, sha1_to_hex(revs.commits->item->object.sha1));
622 +
623 + if (bisect_find_all) {
624 + traverse_commit_list(&revs, show_commit, show_object);
625 + printf("------\n");
626 + }
627 +
628 printf("bisect_rev=%s\n"
629 "bisect_nr=%d\n"
630 "bisect_good=%d\n"
631 "bisect_bad=%d\n"
632 "bisect_all=%d\n",
561 - sha1_to_hex(revs.commits->item->object.sha1),
633 + hex,
634 cnt - 1,
635 all - reaches - 1,
636 reaches - 1,
log-tree.c
+1 -1
@@ -15,7 +15,7 @@ static void show_parents(struct commit *commit, int abbrev)
15 }
16 }
17
18 -static void show_decorations(struct commit *commit)
18 +void show_decorations(struct commit *commit)
19 {
20 const char *prefix;
21 struct name_decoration *decoration;
log-tree.h
+1
@@ -12,5 +12,6 @@ int log_tree_diff_flush(struct rev_info *);
12 int log_tree_commit(struct rev_info *, struct commit *);
13 int log_tree_opt_parse(struct rev_info *, const char **, int);
14 void show_log(struct rev_info *opt, const char *sep);
15 +void show_decorations(struct commit *commit);
16
17 #endif