@matheusbsbs / matheus-bagliano / commits / 2a4646904a
Fork 0

rev-list --bisect: Fix "halfway" optimization.

If you have 5 commits in the set, commits that reach 2 or 3 commits are at halfway. If you have 6 commits, only commits that reach exactly 3 commits are at halfway. The earlier one is completely botched the math. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 23, 2007 at 00:40 UTC 2a4646904a3766abeca7741f15a481d79e97e9e7
1 file changed +26 -6
builtin-rev-list.c
+26 -6
@@ -237,6 +237,27 @@ static int count_interesting_parents(struct commit_list *elem)
237 return cnt;
238 }
239
240 +static inline int halfway(struct commit_list *p, int distance, int nr)
241 +{
242 + /*
243 + * Don't short-cut something we are not going to return!
244 + */
245 + if (revs.prune_fn && !(p->item->object.flags & TREECHANGE))
246 + return 0;
247 +
248 + /*
249 + * 2 and 3 are halfway of 5.
250 + * 3 is halfway of 6 but 2 and 4 are not.
251 + */
252 + distance *= 2;
253 + switch (distance - nr) {
254 + case -1: case 0: case 1:
255 + return 1;
256 + default:
257 + return 0;
258 + }
259 +}
260 +
261 static struct commit_list *find_bisection_2(struct commit_list *list,
262 int *reaches, int *all)
263 {
@@ -305,10 +326,9 @@ static struct commit_list *find_bisection_2(struct commit_list *list,
326 weight_set(p, distance);
327
328 /* Does it happen to be at exactly half-way? */
308 - distance *= 2;
309 - if (nr == distance || (nr+1) == distance) {
329 + if (halfway(p, distance, nr)) {
330 p->next = NULL;
311 - *reaches = weight(p);
331 + *reaches = distance;
332 free(weights);
333 return p;
334 }
@@ -330,10 +350,10 @@ static struct commit_list *find_bisection_2(struct commit_list *list,
350 counted++;
351
352 /* Does it happen to be at exactly half-way? */
333 - distance = weight(p) * 2;
334 - if (nr == distance || (nr+1) == distance) {
353 + distance = weight(p);
354 + if (halfway(p, distance, nr)) {
355 p->next = NULL;
336 - *reaches = weight(p);
356 + *reaches = distance;
357 free(weights);
358 return p;
359 }