Skip to content

Commit 9af3589

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e22278c commit 9af3589

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

bisect.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,34 @@ static char *join_sha1_array_hex(struct sha1_array *array, char delim)
521521
return strbuf_detach(&joined_hexs, NULL);
522522
}
523523

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+
*/
524537
struct commit_list *filter_skipped(struct commit_list *list,
525538
struct commit_list **tried,
526-
int show_all)
539+
int show_all,
540+
int *count,
541+
int *skipped_first)
527542
{
528543
struct commit_list *filtered = NULL, **f = &filtered;
529544

530545
*tried = NULL;
531546

547+
if (skipped_first)
548+
*skipped_first = 0;
549+
if (count)
550+
*count = 0;
551+
532552
if (!skipped_revs.sha1_nr)
533553
return list;
534554

@@ -537,19 +557,31 @@ struct commit_list *filter_skipped(struct commit_list *list,
537557
list->next = NULL;
538558
if (0 <= lookup_sha1_array(&skipped_revs,
539559
list->item->object.sha1)) {
560+
if (skipped_first && !*skipped_first)
561+
*skipped_first = 1;
540562
/* Move current to tried list */
541563
*tried = list;
542564
tried = &list->next;
543565
} 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+
}
546573
/* Move current to filtered list */
547574
*f = list;
548575
f = &list->next;
576+
if (count)
577+
(*count)++;
549578
}
550579
list = next;
551580
}
552581

582+
if (skipped_first && *skipped_first == -1)
583+
*skipped_first = 0;
584+
553585
return filtered;
554586
}
555587

@@ -865,7 +897,7 @@ int bisect_next_all(const char *prefix)
865897

866898
revs.commits = find_bisection(revs.commits, &reaches, &all,
867899
!!skipped_revs.sha1_nr);
868-
revs.commits = filter_skipped(revs.commits, &tried, 0);
900+
revs.commits = filter_skipped(revs.commits, &tried, 0, NULL, NULL);
869901

870902
if (!revs.commits) {
871903
/*

bisect.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ extern struct commit_list *find_bisection(struct commit_list *list,
77

88
extern struct commit_list *filter_skipped(struct commit_list *list,
99
struct commit_list **tried,
10-
int show_all);
10+
int show_all,
11+
int *count,
12+
int *skipped_first);
1113

1214
extern void print_commit_list(struct commit_list *list,
1315
const char *format_cur,

builtin-rev-list.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
262262
if (!revs->commits && !(flags & BISECT_SHOW_TRIED))
263263
return 1;
264264

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);
266268

267269
/*
268270
* revs->commits can reach "reaches" commits among

0 commit comments

Comments
 (0)