Skip to content

Commit 06436e9

Browse files
committed
bisect: combine args passed to find_bisection()
Now that find_bisection() accepts multiple boolean arguments, these may be combined into a single unsigned integer in order to declutter some of the code in bisect.c Signed-off-by: Aaron Lipman <alipman88@gmail.com> Based-on-patch-by: Harald Nordgren <haraldnordgren@gmail.com>
1 parent 91cc036 commit 06436e9

3 files changed

Lines changed: 37 additions & 20 deletions

File tree

bisect.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static const char *term_good;
3737
* We care just barely enough to avoid recursing for
3838
* non-merge entries.
3939
*/
40-
static int count_distance(struct commit_list *entry, int first_parent_only)
40+
static int count_distance(struct commit_list *entry, unsigned bisect_flags)
4141
{
4242
int nr = 0;
4343

@@ -52,10 +52,10 @@ static int count_distance(struct commit_list *entry, int first_parent_only)
5252
commit->object.flags |= COUNTED;
5353
p = commit->parents;
5454
entry = p;
55-
if (p && !first_parent_only) {
55+
if (p && !(bisect_flags & BISECT_FIRST_PARENT)) {
5656
p = p->next;
5757
while (p) {
58-
nr += count_distance(p, first_parent_only);
58+
nr += count_distance(p, bisect_flags);
5959
p = p->next;
6060
}
6161
}
@@ -88,15 +88,15 @@ static inline void weight_set(struct commit_list *elem, int weight)
8888
**commit_weight_at(&commit_weight, elem->item) = weight;
8989
}
9090

91-
static int count_interesting_parents(struct commit *commit, int first_parent_only)
91+
static int count_interesting_parents(struct commit *commit, unsigned bisect_flags)
9292
{
9393
struct commit_list *p;
9494
int count;
9595

9696
for (count = 0, p = commit->parents; p; p = p->next) {
9797
if (!(p->item->object.flags & UNINTERESTING))
9898
count++;
99-
if (first_parent_only)
99+
if (bisect_flags & BISECT_FIRST_PARENT)
100100
break;
101101
}
102102
return count;
@@ -260,7 +260,7 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
260260
*/
261261
static struct commit_list *do_find_bisection(struct commit_list *list,
262262
int nr, int *weights,
263-
int find_all, int first_parent_only)
263+
unsigned bisect_flags)
264264
{
265265
int n, counted;
266266
struct commit_list *p;
@@ -272,7 +272,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
272272
unsigned flags = commit->object.flags;
273273

274274
*commit_weight_at(&commit_weight, p->item) = &weights[n++];
275-
switch (count_interesting_parents(commit, first_parent_only)) {
275+
switch (count_interesting_parents(commit, bisect_flags)) {
276276
case 0:
277277
if (!(flags & TREESAME)) {
278278
weight_set(p, 1);
@@ -315,11 +315,11 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
315315
continue;
316316
if (weight(p) != -2)
317317
continue;
318-
weight_set(p, count_distance(p, first_parent_only));
318+
weight_set(p, count_distance(p, bisect_flags));
319319
clear_distance(list);
320320

321321
/* Does it happen to be at exactly half-way? */
322-
if (!find_all && halfway(p, nr))
322+
if (!(bisect_flags & BISECT_FIND_ALL) && halfway(p, nr))
323323
return p;
324324
counted++;
325325
}
@@ -342,7 +342,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
342342
for (q = p->item->parents; q; q = q->next) {
343343
if (!(q->item->object.flags & UNINTERESTING) && 0 <= weight(q)) {
344344
break;
345-
} else if (first_parent_only) {
345+
} else if (bisect_flags & BISECT_FIRST_PARENT) {
346346
q = NULL;
347347
break;
348348
}
@@ -365,21 +365,21 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
365365
weight_set(p, weight(q));
366366

367367
/* Does it happen to be at exactly half-way? */
368-
if (!find_all && halfway(p, nr))
368+
if (!(bisect_flags & BISECT_FIND_ALL) && halfway(p, nr))
369369
return p;
370370
}
371371
}
372372

373373
show_list("bisection 2 counted all", counted, nr, list);
374374

375-
if (!find_all)
375+
if (!(bisect_flags & BISECT_FIND_ALL))
376376
return best_bisection(list, nr);
377377
else
378378
return best_bisection_sorted(list, nr);
379379
}
380380

381381
void find_bisection(struct commit_list **commit_list, int *reaches,
382-
int *all, int find_all, int first_parent_only)
382+
int *all, unsigned bisect_flags)
383383
{
384384
int nr, on_list;
385385
struct commit_list *list, *p, *best, *next, *last;
@@ -415,9 +415,9 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
415415
weights = xcalloc(on_list, sizeof(*weights));
416416

417417
/* Do the real work of finding bisection commit. */
418-
best = do_find_bisection(list, nr, weights, find_all, first_parent_only);
418+
best = do_find_bisection(list, nr, weights, bisect_flags);
419419
if (best) {
420-
if (!find_all) {
420+
if (!(bisect_flags & BISECT_FIND_ALL)) {
421421
list->item = best->item;
422422
free_commit_list(list->next);
423423
best = list;
@@ -1007,23 +1007,30 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix, int
10071007
enum bisect_error res = BISECT_OK;
10081008
struct object_id *bisect_rev;
10091009
char *steps_msg;
1010-
int first_parent_only = read_first_parent_option();
1010+
unsigned bisect_flags = 0;
10111011

10121012
read_bisect_terms(&term_bad, &term_good);
10131013
if (read_bisect_refs())
10141014
die(_("reading bisect refs failed"));
10151015

1016+
if (read_first_parent_option())
1017+
bisect_flags |= BISECT_FIRST_PARENT;
1018+
1019+
if (!!skipped_revs.nr)
1020+
bisect_flags |= BISECT_FIND_ALL;
1021+
10161022
res = check_good_are_ancestors_of_bad(r, prefix, no_checkout);
10171023
if (res)
10181024
return res;
10191025

10201026
bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
1021-
revs.first_parent_only = first_parent_only;
1027+
1028+
revs.first_parent_only = !!(bisect_flags & BISECT_FIRST_PARENT);
10221029
revs.limited = 1;
10231030

10241031
bisect_common(&revs);
10251032

1026-
find_bisection(&revs.commits, &reaches, &all, !!skipped_revs.nr, first_parent_only);
1033+
find_bisection(&revs.commits, &reaches, &all, bisect_flags);
10271034
revs.commits = managed_skipped(revs.commits, &tried);
10281035

10291036
if (!revs.commits) {

bisect.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct repository;
1212
* best commit, as chosen by `find_all`.
1313
*/
1414
void find_bisection(struct commit_list **list, int *reaches, int *all,
15-
int find_all, int first_parent_only);
15+
unsigned bisect_flags);
1616

1717
struct commit_list *filter_skipped(struct commit_list *list,
1818
struct commit_list **tried,
@@ -23,6 +23,9 @@ struct commit_list *filter_skipped(struct commit_list *list,
2323
#define BISECT_SHOW_ALL (1<<0)
2424
#define REV_LIST_QUIET (1<<1)
2525

26+
#define BISECT_FIND_ALL (1u<<0)
27+
#define BISECT_FIRST_PARENT (1u<<1)
28+
2629
struct rev_list_info {
2730
struct rev_info *revs;
2831
int flags;

builtin/rev-list.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,15 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
637637

638638
if (bisect_list) {
639639
int reaches, all;
640+
unsigned bisect_flags = 0;
640641

641-
find_bisection(&revs.commits, &reaches, &all, bisect_find_all, revs.first_parent_only);
642+
if (bisect_find_all)
643+
bisect_flags |= BISECT_FIND_ALL;
644+
645+
if (revs.first_parent_only)
646+
bisect_flags |= BISECT_FIRST_PARENT;
647+
648+
find_bisection(&revs.commits, &reaches, &all, bisect_flags);
642649

643650
if (bisect_show_vars)
644651
return show_bisect_vars(&info, reaches, all);

0 commit comments

Comments
 (0)