Skip to content

Commit 62d0b0d

Browse files
chriscoolgitster
authored andcommitted
bisect: when skipping, choose a commit away from a skipped commit
To do that a new function "apply_skip_ratio" is added and another function "managed_skipped" is created to wrap both "filter_skipped" and the previous one. In "managed_skipped" we detect when we should choose a commit away from a skipped one and then we automatically choose a skip ratio to pass to "apply_skip_ratio". The ratio is choosen so that it alternates between 1/5, 2/5 and 3/5. In "apply_skip_ratio", we ignore a given ratio of all the commits that could be tested. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9af3589 commit 62d0b0d

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

bisect.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,54 @@ struct commit_list *filter_skipped(struct commit_list *list,
585585
return filtered;
586586
}
587587

588+
static struct commit_list *apply_skip_ratio(struct commit_list *list,
589+
int count,
590+
int skip_num, int skip_denom)
591+
{
592+
int index, i;
593+
struct commit_list *cur, *previous;
594+
595+
cur = list;
596+
previous = NULL;
597+
index = count * skip_num / skip_denom;
598+
599+
for (i = 0; cur; cur = cur->next, i++) {
600+
if (i == index) {
601+
if (hashcmp(cur->item->object.sha1, current_bad_sha1))
602+
return cur;
603+
if (previous)
604+
return previous;
605+
return list;
606+
}
607+
previous = cur;
608+
}
609+
610+
return list;
611+
}
612+
613+
static struct commit_list *managed_skipped(struct commit_list *list,
614+
struct commit_list **tried)
615+
{
616+
int count, skipped_first;
617+
int skip_num, skip_denom;
618+
619+
*tried = NULL;
620+
621+
if (!skipped_revs.sha1_nr)
622+
return list;
623+
624+
list = filter_skipped(list, tried, 0, &count, &skipped_first);
625+
626+
if (!skipped_first)
627+
return list;
628+
629+
/* Use alternatively 1/5, 2/5 and 3/5 as skip ratio. */
630+
skip_num = count % 3 + 1;
631+
skip_denom = 5;
632+
633+
return apply_skip_ratio(list, count, skip_num, skip_denom);
634+
}
635+
588636
static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
589637
const char *bad_format, const char *good_format,
590638
int read_paths)
@@ -897,7 +945,7 @@ int bisect_next_all(const char *prefix)
897945

898946
revs.commits = find_bisection(revs.commits, &reaches, &all,
899947
!!skipped_revs.sha1_nr);
900-
revs.commits = filter_skipped(revs.commits, &tried, 0, NULL, NULL);
948+
revs.commits = managed_skipped(revs.commits, &tried);
901949

902950
if (!revs.commits) {
903951
/*

0 commit comments

Comments
 (0)