@matheusbsbs / matheus-bagliano / commits / 77c11e064c
Fork 0

rev-list --bisect: Move some bisection code into best_bisection.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Sep 17, 2007 at 05:28 UTC 77c11e064c5daadeb42e79b7fc6b28857e9b6bb6
1 file changed +26 -17
builtin-rev-list.c
+26 -17
@@ -255,6 +255,30 @@ static void show_list(const char *debug, int counted, int nr,
255 }
256 #endif /* DEBUG_BISECT */
257
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 +
282 /*
283 * zero or positive weight is the number of interesting commits it can
284 * 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,
296 int nr, int *weights)
297 {
298 int n, counted, distance;
275 - struct commit_list *p, *best;
299 + struct commit_list *p;
300
301 counted = 0;
302
@@ -377,22 +401,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
401 show_list("bisection 2 counted all", counted, nr, list);
402
403 /* 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);
405 }
406
407 static struct commit_list *find_bisection(struct commit_list *list,