Skip to content

Commit ad464a4

Browse files
alipman88gitster
authored andcommitted
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 Also, rename the existing "flags" bitfield to "commit_flags", to explicitly differentiate it from the new "bisect_flags" bitfield. Based-on-patch-by: Harald Nordgren <[email protected]> Signed-off-by: Aaron Lipman <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e8861ff commit ad464a4

File tree

3 files changed

+49
-32
lines changed

3 files changed

+49
-32
lines changed

bisect.c

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ static inline void weight_set(struct commit_list *elem, int weight)
8989
**commit_weight_at(&commit_weight, elem->item) = weight;
9090
}
9191

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

9797
for (count = 0, p = commit->parents; p; p = p->next) {
9898
if (!(p->item->object.flags & UNINTERESTING))
9999
count++;
100-
if (first_parent_only)
100+
if (bisect_flags & FIND_BISECTION_FIRST_PARENT_ONLY)
101101
break;
102102
}
103103
return count;
@@ -137,7 +137,7 @@ static void show_list(const char *debug, int counted, int nr,
137137
for (p = list; p; p = p->next) {
138138
struct commit_list *pp;
139139
struct commit *commit = p->item;
140-
unsigned flags = commit->object.flags;
140+
unsigned commit_flags = commit->object.flags;
141141
enum object_type type;
142142
unsigned long size;
143143
char *buf = read_object_file(&commit->object.oid, &type,
@@ -146,9 +146,9 @@ static void show_list(const char *debug, int counted, int nr,
146146
int subject_len;
147147

148148
fprintf(stderr, "%c%c%c ",
149-
(flags & TREESAME) ? ' ' : 'T',
150-
(flags & UNINTERESTING) ? 'U' : ' ',
151-
(flags & COUNTED) ? 'C' : ' ');
149+
(commit_flags & TREESAME) ? ' ' : 'T',
150+
(commit_flags & UNINTERESTING) ? 'U' : ' ',
151+
(commit_flags & COUNTED) ? 'C' : ' ');
152152
if (*commit_weight_at(&commit_weight, p->item))
153153
fprintf(stderr, "%3d", weight(p));
154154
else
@@ -173,9 +173,9 @@ static struct commit_list *best_bisection(struct commit_list *list, int nr)
173173
best = list;
174174
for (p = list; p; p = p->next) {
175175
int distance;
176-
unsigned flags = p->item->object.flags;
176+
unsigned commit_flags = p->item->object.flags;
177177

178-
if (flags & TREESAME)
178+
if (commit_flags & TREESAME)
179179
continue;
180180
distance = weight(p);
181181
if (nr - distance < distance)
@@ -214,9 +214,9 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
214214

215215
for (p = list, cnt = 0; p; p = p->next) {
216216
int distance;
217-
unsigned flags = p->item->object.flags;
217+
unsigned commit_flags = p->item->object.flags;
218218

219-
if (flags & TREESAME)
219+
if (commit_flags & TREESAME)
220220
continue;
221221
distance = weight(p);
222222
if (nr - distance < distance)
@@ -261,7 +261,7 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
261261
*/
262262
static struct commit_list *do_find_bisection(struct commit_list *list,
263263
int nr, int *weights,
264-
int find_all, int first_parent_only)
264+
unsigned bisect_flags)
265265
{
266266
int n, counted;
267267
struct commit_list *p;
@@ -270,12 +270,12 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
270270

271271
for (n = 0, p = list; p; p = p->next) {
272272
struct commit *commit = p->item;
273-
unsigned flags = commit->object.flags;
273+
unsigned commit_flags = commit->object.flags;
274274

275275
*commit_weight_at(&commit_weight, p->item) = &weights[n++];
276-
switch (count_interesting_parents(commit, first_parent_only)) {
276+
switch (count_interesting_parents(commit, bisect_flags)) {
277277
case 0:
278-
if (!(flags & TREESAME)) {
278+
if (!(commit_flags & TREESAME)) {
279279
weight_set(p, 1);
280280
counted++;
281281
show_list("bisection 2 count one",
@@ -316,13 +316,13 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
316316
continue;
317317
if (weight(p) != -2)
318318
continue;
319-
if (first_parent_only)
319+
if (bisect_flags & FIND_BISECTION_FIRST_PARENT_ONLY)
320320
BUG("shouldn't be calling count-distance in fp mode");
321321
weight_set(p, count_distance(p));
322322
clear_distance(list);
323323

324324
/* Does it happen to be at exactly half-way? */
325-
if (!find_all && halfway(p, nr))
325+
if (!(bisect_flags & FIND_BISECTION_ALL) && halfway(p, nr))
326326
return p;
327327
counted++;
328328
}
@@ -332,14 +332,14 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
332332
while (counted < nr) {
333333
for (p = list; p; p = p->next) {
334334
struct commit_list *q;
335-
unsigned flags = p->item->object.flags;
335+
unsigned commit_flags = p->item->object.flags;
336336

337337
if (0 <= weight(p))
338338
continue;
339339

340340
for (q = p->item->parents;
341341
q;
342-
q = first_parent_only ? NULL : q->next) {
342+
q = bisect_flags & FIND_BISECTION_FIRST_PARENT_ONLY ? NULL : q->next) {
343343
if (q->item->object.flags & UNINTERESTING)
344344
continue;
345345
if (0 <= weight(q))
@@ -353,7 +353,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
353353
* add one for p itself if p is to be counted,
354354
* otherwise inherit it from q directly.
355355
*/
356-
if (!(flags & TREESAME)) {
356+
if (!(commit_flags & TREESAME)) {
357357
weight_set(p, weight(q)+1);
358358
counted++;
359359
show_list("bisection 2 count one",
@@ -363,21 +363,21 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
363363
weight_set(p, weight(q));
364364

365365
/* Does it happen to be at exactly half-way? */
366-
if (!find_all && halfway(p, nr))
366+
if (!(bisect_flags & FIND_BISECTION_ALL) && halfway(p, nr))
367367
return p;
368368
}
369369
}
370370

371371
show_list("bisection 2 counted all", counted, nr, list);
372372

373-
if (!find_all)
373+
if (!(bisect_flags & FIND_BISECTION_ALL))
374374
return best_bisection(list, nr);
375375
else
376376
return best_bisection_sorted(list, nr);
377377
}
378378

379379
void find_bisection(struct commit_list **commit_list, int *reaches,
380-
int *all, int find_all, int first_parent_only)
380+
int *all, unsigned bisect_flags)
381381
{
382382
int nr, on_list;
383383
struct commit_list *list, *p, *best, *next, *last;
@@ -393,16 +393,16 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
393393
for (nr = on_list = 0, last = NULL, p = *commit_list;
394394
p;
395395
p = next) {
396-
unsigned flags = p->item->object.flags;
396+
unsigned commit_flags = p->item->object.flags;
397397

398398
next = p->next;
399-
if (flags & UNINTERESTING) {
399+
if (commit_flags & UNINTERESTING) {
400400
free(p);
401401
continue;
402402
}
403403
p->next = last;
404404
last = p;
405-
if (!(flags & TREESAME))
405+
if (!(commit_flags & TREESAME))
406406
nr++;
407407
on_list++;
408408
}
@@ -413,9 +413,9 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
413413
weights = xcalloc(on_list, sizeof(*weights));
414414

415415
/* Do the real work of finding bisection commit. */
416-
best = do_find_bisection(list, nr, weights, find_all, first_parent_only);
416+
best = do_find_bisection(list, nr, weights, bisect_flags);
417417
if (best) {
418-
if (!find_all) {
418+
if (!(bisect_flags & FIND_BISECTION_ALL)) {
419419
list->item = best->item;
420420
free_commit_list(list->next);
421421
best = list;
@@ -1000,23 +1000,30 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
10001000
struct object_id *bisect_rev;
10011001
char *steps_msg;
10021002
int no_checkout = ref_exists("BISECT_HEAD");
1003-
int first_parent_only = file_exists(git_path_bisect_first_parent());
1003+
unsigned bisect_flags = 0;
10041004

10051005
read_bisect_terms(&term_bad, &term_good);
10061006
if (read_bisect_refs())
10071007
die(_("reading bisect refs failed"));
10081008

1009+
if (file_exists(git_path_bisect_first_parent()))
1010+
bisect_flags |= FIND_BISECTION_FIRST_PARENT_ONLY;
1011+
1012+
if (skipped_revs.nr)
1013+
bisect_flags |= FIND_BISECTION_ALL;
1014+
10091015
res = check_good_are_ancestors_of_bad(r, prefix, no_checkout);
10101016
if (res)
10111017
return res;
10121018

10131019
bisect_rev_setup(r, &revs, prefix, "%s", "^%s", 1);
1014-
revs.first_parent_only = first_parent_only;
1020+
1021+
revs.first_parent_only = !!(bisect_flags & FIND_BISECTION_FIRST_PARENT_ONLY);
10151022
revs.limited = 1;
10161023

10171024
bisect_common(&revs);
10181025

1019-
find_bisection(&revs.commits, &reaches, &all, !!skipped_revs.nr, first_parent_only);
1026+
find_bisection(&revs.commits, &reaches, &all, bisect_flags);
10201027
revs.commits = managed_skipped(revs.commits, &tried);
10211028

10221029
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 FIND_BISECTION_ALL (1u<<0)
27+
#define FIND_BISECTION_FIRST_PARENT_ONLY (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 |= FIND_BISECTION_ALL;
644+
645+
if (revs.first_parent_only)
646+
bisect_flags |= FIND_BISECTION_FIRST_PARENT_ONLY;
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)