Skip to content

Commit ce0cbad

Browse files
chriscoolgitster
authored andcommitted
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>
1 parent 9346b4e commit ce0cbad

File tree

1 file changed

+48
-42
lines changed

1 file changed

+48
-42
lines changed

builtin-rev-list.c

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -268,39 +268,12 @@ static void show_list(const char *debug, int counted, int nr,
268268
* unknown. After running count_distance() first, they will get zero
269269
* or positive distance.
270270
*/
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)
274273
{
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;
289276

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));
304277
counted = 0;
305278

306279
for (n = 0, p = list; p; p = p->next) {
@@ -357,12 +330,8 @@ static struct commit_list *find_bisection(struct commit_list *list,
357330
weight_set(p, distance);
358331

359332
/* 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))
364334
return p;
365-
}
366335
counted++;
367336
}
368337

@@ -400,12 +369,8 @@ static struct commit_list *find_bisection(struct commit_list *list,
400369

401370
/* Does it happen to be at exactly half-way? */
402371
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))
407373
return p;
408-
}
409374
}
410375
}
411376

@@ -425,12 +390,53 @@ static struct commit_list *find_bisection(struct commit_list *list,
425390
if (distance > counted) {
426391
best = p;
427392
counted = distance;
428-
*reaches = weight(p);
429393
}
430394
}
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+
431434
if (best)
432435
best->next = NULL;
436+
437+
*reaches = weight(best);
433438
free(weights);
439+
434440
return best;
435441
}
436442

0 commit comments

Comments
 (0)