Skip to content

Commit 24d707f

Browse files
Martin Ågrengitster
authored andcommitted
bisect: change calling-convention of find_bisection()
This function takes a commit list and returns a commit list. The returned list is built by modifying the original list. Thus the caller should not use the original list again (and after the next commit fixes a memory leak, it must not). Change the function signature so that it takes a **list and has void return type. That should make it harder to misuse this function. While we're here, document this function. Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb5918a commit 24d707f

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

bisect.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,21 +360,20 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
360360
return best_bisection_sorted(list, nr);
361361
}
362362

363-
struct commit_list *find_bisection(struct commit_list *list,
364-
int *reaches, int *all,
365-
int find_all)
363+
void find_bisection(struct commit_list **commit_list, int *reaches,
364+
int *all, int find_all)
366365
{
367366
int nr, on_list;
368-
struct commit_list *p, *best, *next, *last;
367+
struct commit_list *list, *p, *best, *next, *last;
369368
int *weights;
370369

371-
show_list("bisection 2 entry", 0, 0, list);
370+
show_list("bisection 2 entry", 0, 0, *commit_list);
372371

373372
/*
374373
* Count the number of total and tree-changing items on the
375374
* list, while reversing the list.
376375
*/
377-
for (nr = on_list = 0, last = NULL, p = list;
376+
for (nr = on_list = 0, last = NULL, p = *commit_list;
378377
p;
379378
p = next) {
380379
unsigned flags = p->item->object.flags;
@@ -402,7 +401,7 @@ struct commit_list *find_bisection(struct commit_list *list,
402401
*reaches = weight(best);
403402
}
404403
free(weights);
405-
return best;
404+
*commit_list = best;
406405
}
407406

408407
static int register_ref(const char *refname, const struct object_id *oid,
@@ -954,8 +953,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
954953

955954
bisect_common(&revs);
956955

957-
revs.commits = find_bisection(revs.commits, &reaches, &all,
958-
!!skipped_revs.nr);
956+
find_bisection(&revs.commits, &reaches, &all, !!skipped_revs.nr);
959957
revs.commits = managed_skipped(revs.commits, &tried);
960958

961959
if (!revs.commits) {

bisect.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#ifndef BISECT_H
22
#define BISECT_H
33

4-
extern struct commit_list *find_bisection(struct commit_list *list,
5-
int *reaches, int *all,
6-
int find_all);
4+
/*
5+
* Find bisection. If something is found, `reaches` will be the number of
6+
* commits that the best commit reaches. `all` will be the count of
7+
* non-SAMETREE commits. If nothing is found, `list` will be NULL.
8+
* Otherwise, it will be either all non-SAMETREE commits or the single
9+
* best commit, as chosen by `find_all`.
10+
*/
11+
extern void find_bisection(struct commit_list **list, int *reaches, int *all,
12+
int find_all);
713

814
extern struct commit_list *filter_skipped(struct commit_list *list,
915
struct commit_list **tried,

builtin/rev-list.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
397397
if (bisect_list) {
398398
int reaches = reaches, all = all;
399399

400-
revs.commits = find_bisection(revs.commits, &reaches, &all,
401-
bisect_find_all);
400+
find_bisection(&revs.commits, &reaches, &all, bisect_find_all);
402401

403402
if (bisect_show_vars)
404403
return show_bisect_vars(&info, reaches, all);

0 commit comments

Comments
 (0)