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 <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Ågren committed Nov 5, 2017 at 21:24 UTC 24d707f636f01d41f708a010f255dd46a8fce08c
3 files changed +17 -14
bisect.c
+7 -9
@@ -360,21 +360,20 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
360 return best_bisection_sorted(list, nr);
361 }
362
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)
365 {
366 int nr, on_list;
368 - struct commit_list *p, *best, *next, *last;
367 + struct commit_list *list, *p, *best, *next, *last;
368 int *weights;
369
371 - show_list("bisection 2 entry", 0, 0, list);
370 + show_list("bisection 2 entry", 0, 0, *commit_list);
371
372 /*
373 * Count the number of total and tree-changing items on the
374 * list, while reversing the list.
375 */
377 - for (nr = on_list = 0, last = NULL, p = list;
376 + for (nr = on_list = 0, last = NULL, p = *commit_list;
377 p;
378 p = next) {
379 unsigned flags = p->item->object.flags;
@@ -402,7 +401,7 @@ struct commit_list *find_bisection(struct commit_list *list,
401 *reaches = weight(best);
402 }
403 free(weights);
405 - return best;
404 + *commit_list = best;
405 }
406
407 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)
953
954 bisect_common(&revs);
955
957 - revs.commits = find_bisection(revs.commits, &reaches, &all,
958 - !!skipped_revs.nr);
956 + find_bisection(&revs.commits, &reaches, &all, !!skipped_revs.nr);
957 revs.commits = managed_skipped(revs.commits, &tried);
958
959 if (!revs.commits) {
bisect.h
+9 -3
@@ -1,9 +1,15 @@
1 #ifndef BISECT_H
2 #define BISECT_H
3
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);
13
14 extern struct commit_list *filter_skipped(struct commit_list *list,
15 struct commit_list **tried,
builtin/rev-list.c
+1 -2
@@ -397,8 +397,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
397 if (bisect_list) {
398 int reaches = reaches, all = all;
399
400 - revs.commits = find_bisection(revs.commits, &reaches, &all,
401 - bisect_find_all);
400 + find_bisection(&revs.commits, &reaches, &all, bisect_find_all);
401
402 if (bisect_show_vars)
403 return show_bisect_vars(&info, reaches, all);