rev-list --bisect: Move finding bisection into do_find_bisection.
This factorises some code and make a big function smaller. 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
ce0cbad7727457854d631a6314d9aee7c837cb65
1 file changed
+48
-42
builtin-rev-list.c
+48
-42
@@ -268,39 +268,12 @@ static void show_list(const char *debug, int counted, int nr,
268
* unknown. After running count_distance() first, they will get zero
269
* or positive distance.
270
*/
271
-
272
-static struct commit_list *find_bisection(struct commit_list *list,
273
- int *reaches, int *all)
271
+static struct commit_list *do_find_bisection(struct commit_list *list,
272
+ int nr, int *weights)
273
{
275
- int n, nr, on_list, counted, distance;
276
- struct commit_list *p, *best, *next, *last;
277
- int *weights;
278
-
279
- show_list("bisection 2 entry", 0, 0, list);
280
-
281
- /*
282
- * Count the number of total and tree-changing items on the
283
- * list, while reversing the list.
284
- */
285
- for (nr = on_list = 0, last = NULL, p = list;
286
- p;
287
- p = next) {
288
- unsigned flags = p->item->object.flags;
274
+ int n, counted, distance;
275
+ struct commit_list *p, *best;
276
290
- next = p->next;
291
- if (flags & UNINTERESTING)
292
- continue;
293
- p->next = last;
294
- last = p;
295
- if (!revs.prune_fn || (flags & TREECHANGE))
296
- nr++;
297
- on_list++;
298
- }
299
- list = last;
300
- show_list("bisection 2 sorted", 0, nr, list);
301
-
302
- *all = nr;
303
- weights = xcalloc(on_list, sizeof(*weights));
277
counted = 0;
278
279
for (n = 0, p = list; p; p = p->next) {
@@ -357,12 +330,8 @@ static struct commit_list *find_bisection(struct commit_list *list,
330
weight_set(p, distance);
331
332
/* Does it happen to be at exactly half-way? */
360
- if (halfway(p, distance, nr)) {
361
- p->next = NULL;
362
- *reaches = distance;
363
- free(weights);
333
+ if (halfway(p, distance, nr))
334
return p;
365
- }
335
counted++;
336
}
337
@@ -400,12 +369,8 @@ static struct commit_list *find_bisection(struct commit_list *list,
369
370
/* Does it happen to be at exactly half-way? */
371
distance = weight(p);
403
- if (halfway(p, distance, nr)) {
404
- p->next = NULL;
405
- *reaches = distance;
406
- free(weights);
372
+ if (halfway(p, distance, nr))
373
return p;
408
- }
374
}
375
}
376
@@ -425,12 +390,53 @@ static struct commit_list *find_bisection(struct commit_list *list,
390
if (distance > counted) {
391
best = p;
392
counted = distance;
428
- *reaches = weight(p);
393
}
394
}
395
+ return best;
396
+}
397
+
398
+static struct commit_list *find_bisection(struct commit_list *list,
399
+ int *reaches, int *all)
400
+{
401
+ int nr, on_list;
402
+ struct commit_list *p, *best, *next, *last;
403
+ int *weights;
404
+
405
+ show_list("bisection 2 entry", 0, 0, list);
406
+
407
+ /*
408
+ * Count the number of total and tree-changing items on the
409
+ * list, while reversing the list.
410
+ */
411
+ for (nr = on_list = 0, last = NULL, p = list;
412
+ p;
413
+ p = next) {
414
+ unsigned flags = p->item->object.flags;
415
+
416
+ next = p->next;
417
+ if (flags & UNINTERESTING)
418
+ continue;
419
+ p->next = last;
420
+ last = p;
421
+ if (!revs.prune_fn || (flags & TREECHANGE))
422
+ nr++;
423
+ on_list++;
424
+ }
425
+ list = last;
426
+ show_list("bisection 2 sorted", 0, nr, list);
427
+
428
+ *all = nr;
429
+ weights = xcalloc(on_list, sizeof(*weights));
430
+
431
+ /* Do the real work of finding bisection commit. */
432
+ best = do_find_bisection(list, nr, weights);
433
+
434
if (best)
435
best->next = NULL;
436
+
437
+ *reaches = weight(best);
438
free(weights);
439
+
440
return best;
441
}
442