Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-11-26 02:24:52 +0300
committerJunio C Hamano <gitster@pobox.com>2020-11-26 02:24:52 +0300
commit2557c1183a6c6025bc0dd6ebd84354064bb398ec (patch)
treed5d59c46c932cf33c40929d6962d636ce24a799c /bisect.c
parentfd6445a0b8346d0dea6482af682f2116229f6436 (diff)
parent0afcea70b18b0edc38e2e1b89d36737c9e93d6a3 (diff)
Merge branch 'sg/bisect-approximately-halfway'
"git bisect start/next" in a large span of history spends a lot of time trying to come up with exactly the half-way point; this can be optimized by stopping when we see a commit that is close enough to the half-way point. * sg/bisect-approximately-halfway: bisect: loosen halfway() check for a large number of commits
Diffstat (limited to 'bisect.c')
-rw-r--r--bisect.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/bisect.c b/bisect.c
index 58bc9c73a4..d8c2c8f7a7 100644
--- a/bisect.c
+++ b/bisect.c
@@ -103,8 +103,10 @@ static int count_interesting_parents(struct commit *commit, unsigned bisect_flag
return count;
}
-static inline int halfway(struct commit_list *p, int nr)
+static inline int approx_halfway(struct commit_list *p, int nr)
{
+ int diff;
+
/*
* Don't short-cut something we are not going to return!
*/
@@ -113,13 +115,22 @@ static inline int halfway(struct commit_list *p, int nr)
if (DEBUG_BISECT)
return 0;
/*
- * 2 and 3 are halfway of 5.
+ * For small number of commits 2 and 3 are halfway of 5, and
* 3 is halfway of 6 but 2 and 4 are not.
*/
- switch (2 * weight(p) - nr) {
+ diff = 2 * weight(p) - nr;
+ switch (diff) {
case -1: case 0: case 1:
return 1;
default:
+ /*
+ * For large number of commits we are not so strict, it's
+ * good enough if it's within ~0.1% of the halfway point,
+ * e.g. 5000 is exactly halfway of 10000, but we consider
+ * the values [4996, 5004] as halfway as well.
+ */
+ if (abs(diff) < nr / 1024)
+ return 1;
return 0;
}
}
@@ -321,8 +332,9 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
weight_set(p, count_distance(p));
clear_distance(list);
- /* Does it happen to be at exactly half-way? */
- if (!(bisect_flags & FIND_BISECTION_ALL) && halfway(p, nr))
+ /* Does it happen to be at half-way? */
+ if (!(bisect_flags & FIND_BISECTION_ALL) &&
+ approx_halfway(p, nr))
return p;
counted++;
}
@@ -362,8 +374,9 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
else
weight_set(p, weight(q));
- /* Does it happen to be at exactly half-way? */
- if (!(bisect_flags & FIND_BISECTION_ALL) && halfway(p, nr))
+ /* Does it happen to be at half-way? */
+ if (!(bisect_flags & FIND_BISECTION_ALL) &&
+ approx_halfway(p, nr))
return p;
}
}