@matheusbsbs / matheus-bagliano / commits / 9af3589e0e
Fork 0

bisect: add parameters to "filter_skipped"

because we will need to get more information from this function in some later patches. The new "int *count" parameter gives the number of commits left after the skipped commit have been filtered out. The new "int *skipped_first" parameter tells us if the first commit in the list has been skipped. Note that using this parameter also changes the behavior of the function if the first commit is indeed skipped. Because we assume that in this case we will want all the filtered commits, not just the first one, even if "show_all" is not set. So using a not NULL "skipped_first" parameter really means that we plan to choose to test another commit than the first non skipped one if the first commit in the list is skipped. That in turn means that, in case the first commit is skipped, we have to return a fully filtered list. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Jun 6, 2009 at 06:41 UTC 9af3589e0e42eb289dfdb8bb4031e5bec4923308
3 files changed +42 -6
bisect.c
+36 -4
@@ -521,14 +521,34 @@ static char *join_sha1_array_hex(struct sha1_array *array, char delim)
521 return strbuf_detach(&joined_hexs, NULL);
522 }
523
524 +/*
525 + * In this function, passing a not NULL skipped_first is very special.
526 + * It means that we want to know if the first commit in the list is
527 + * skipped because we will want to test a commit away from it if it is
528 + * indeed skipped.
529 + * So if the first commit is skipped, we cannot take the shortcut to
530 + * just "return list" when we find the first non skipped commit, we
531 + * have to return a fully filtered list.
532 + *
533 + * We use (*skipped_first == -1) to mean "it has been found that the
534 + * first commit is not skipped". In this case *skipped_first is set back
535 + * to 0 just before the function returns.
536 + */
537 struct commit_list *filter_skipped(struct commit_list *list,
538 struct commit_list **tried,
526 - int show_all)
539 + int show_all,
540 + int *count,
541 + int *skipped_first)
542 {
543 struct commit_list *filtered = NULL, **f = &filtered;
544
545 *tried = NULL;
546
547 + if (skipped_first)
548 + *skipped_first = 0;
549 + if (count)
550 + *count = 0;
551 +
552 if (!skipped_revs.sha1_nr)
553 return list;
554
@@ -537,19 +557,31 @@ struct commit_list *filter_skipped(struct commit_list *list,
557 list->next = NULL;
558 if (0 <= lookup_sha1_array(&skipped_revs,
559 list->item->object.sha1)) {
560 + if (skipped_first && !*skipped_first)
561 + *skipped_first = 1;
562 /* Move current to tried list */
563 *tried = list;
564 tried = &list->next;
565 } else {
544 - if (!show_all)
545 - return list;
566 + if (!show_all) {
567 + if (!skipped_first || !*skipped_first)
568 + return list;
569 + } else if (skipped_first && !*skipped_first) {
570 + /* This means we know it's not skipped */
571 + *skipped_first = -1;
572 + }
573 /* Move current to filtered list */
574 *f = list;
575 f = &list->next;
576 + if (count)
577 + (*count)++;
578 }
579 list = next;
580 }
581
582 + if (skipped_first && *skipped_first == -1)
583 + *skipped_first = 0;
584 +
585 return filtered;
586 }
587
@@ -865,7 +897,7 @@ int bisect_next_all(const char *prefix)
897
898 revs.commits = find_bisection(revs.commits, &reaches, &all,
899 !!skipped_revs.sha1_nr);
868 - revs.commits = filter_skipped(revs.commits, &tried, 0);
900 + revs.commits = filter_skipped(revs.commits, &tried, 0, NULL, NULL);
901
902 if (!revs.commits) {
903 /*
bisect.h
+3 -1
@@ -7,7 +7,9 @@ extern struct commit_list *find_bisection(struct commit_list *list,
7
8 extern struct commit_list *filter_skipped(struct commit_list *list,
9 struct commit_list **tried,
10 - int show_all);
10 + int show_all,
11 + int *count,
12 + int *skipped_first);
13
14 extern void print_commit_list(struct commit_list *list,
15 const char *format_cur,
builtin-rev-list.c
+3 -1
@@ -262,7 +262,9 @@ int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
262 if (!revs->commits && !(flags & BISECT_SHOW_TRIED))
263 return 1;
264
265 - revs->commits = filter_skipped(revs->commits, &tried, flags & BISECT_SHOW_ALL);
265 + revs->commits = filter_skipped(revs->commits, &tried,
266 + flags & BISECT_SHOW_ALL,
267 + NULL, NULL);
268
269 /*
270 * revs->commits can reach "reaches" commits among