@@ -255,6 +255,30 @@ static void show_list(const char *debug, int counted, int nr,
255255}
256256#endif /* DEBUG_BISECT */
257257
258+ static struct commit_list * best_bisection (struct commit_list * list , int nr )
259+ {
260+ struct commit_list * p , * best ;
261+ int best_distance = -1 ;
262+
263+ best = list ;
264+ for (p = list ; p ; p = p -> next ) {
265+ int distance ;
266+ unsigned flags = p -> item -> object .flags ;
267+
268+ if (revs .prune_fn && !(flags & TREECHANGE ))
269+ continue ;
270+ distance = weight (p );
271+ if (nr - distance < distance )
272+ distance = nr - distance ;
273+ if (distance > best_distance ) {
274+ best = p ;
275+ best_distance = distance ;
276+ }
277+ }
278+
279+ return best ;
280+ }
281+
258282/*
259283 * zero or positive weight is the number of interesting commits it can
260284 * reach, including itself. Especially, weight = 0 means it does not
@@ -272,7 +296,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
272296 int nr , int * weights )
273297{
274298 int n , counted , distance ;
275- struct commit_list * p , * best ;
299+ struct commit_list * p ;
276300
277301 counted = 0 ;
278302
@@ -377,22 +401,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
377401 show_list ("bisection 2 counted all" , counted , nr , list );
378402
379403 /* Then find the best one */
380- counted = -1 ;
381- best = list ;
382- for (p = list ; p ; p = p -> next ) {
383- unsigned flags = p -> item -> object .flags ;
384-
385- if (revs .prune_fn && !(flags & TREECHANGE ))
386- continue ;
387- distance = weight (p );
388- if (nr - distance < distance )
389- distance = nr - distance ;
390- if (distance > counted ) {
391- best = p ;
392- counted = distance ;
393- }
394- }
395- return best ;
404+ return best_bisection (list , nr );
396405}
397406
398407static struct commit_list * find_bisection (struct commit_list * list ,
0 commit comments