@matheusbsbs / matheus-bagliano / commits / ad464a4e84
Fork 0

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 <haraldnordgren@gmail.com> Signed-off-by: Aaron Lipman <alipman88@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Aaron Lipman committed Aug 7, 2020 at 17:58 UTC ad464a4e84b502fdfd4671f1c443060c7e87113f
3 files changed +49 -32
bisect.c
+37 -30
@@ -89,7 +89,7 @@ static inline void weight_set(struct commit_list *elem, int weight)
89 **commit_weight_at(&commit_weight, elem->item) = weight;
90 }
91
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)
93 {
94 struct commit_list *p;
95 int count;
@@ -97,7 +97,7 @@ static int count_interesting_parents(struct commit *commit, int first_parent_onl
97 for (count = 0, p = commit->parents; p; p = p->next) {
98 if (!(p->item->object.flags & UNINTERESTING))
99 count++;
100 - if (first_parent_only)
100 + if (bisect_flags & FIND_BISECTION_FIRST_PARENT_ONLY)
101 break;
102 }
103 return count;
@@ -137,7 +137,7 @@ static void show_list(const char *debug, int counted, int nr,
137 for (p = list; p; p = p->next) {
138 struct commit_list *pp;
139 struct commit *commit = p->item;
140 - unsigned flags = commit->object.flags;
140 + unsigned commit_flags = commit->object.flags;
141 enum object_type type;
142 unsigned long size;
143 char *buf = read_object_file(&commit->object.oid, &type,
@@ -146,9 +146,9 @@ static void show_list(const char *debug, int counted, int nr,
146 int subject_len;
147
148 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' : ' ');
152 if (*commit_weight_at(&commit_weight, p->item))
153 fprintf(stderr, "%3d", weight(p));
154 else
@@ -173,9 +173,9 @@ static struct commit_list *best_bisection(struct commit_list *list, int nr)
173 best = list;
174 for (p = list; p; p = p->next) {
175 int distance;
176 - unsigned flags = p->item->object.flags;
176 + unsigned commit_flags = p->item->object.flags;
177
178 - if (flags & TREESAME)
178 + if (commit_flags & TREESAME)
179 continue;
180 distance = weight(p);
181 if (nr - distance < distance)
@@ -214,9 +214,9 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
214
215 for (p = list, cnt = 0; p; p = p->next) {
216 int distance;
217 - unsigned flags = p->item->object.flags;
217 + unsigned commit_flags = p->item->object.flags;
218
219 - if (flags & TREESAME)
219 + if (commit_flags & TREESAME)
220 continue;
221 distance = weight(p);
222 if (nr - distance < distance)
@@ -261,7 +261,7 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
261 */
262 static struct commit_list *do_find_bisection(struct commit_list *list,
263 int nr, int *weights,
264 - int find_all, int first_parent_only)
264 + unsigned bisect_flags)
265 {
266 int n, counted;
267 struct commit_list *p;
@@ -270,12 +270,12 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
270
271 for (n = 0, p = list; p; p = p->next) {
272 struct commit *commit = p->item;
273 - unsigned flags = commit->object.flags;
273 + unsigned commit_flags = commit->object.flags;
274
275 *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)) {
277 case 0:
278 - if (!(flags & TREESAME)) {
278 + if (!(commit_flags & TREESAME)) {
279 weight_set(p, 1);
280 counted++;
281 show_list("bisection 2 count one",
@@ -316,13 +316,13 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
316 continue;
317 if (weight(p) != -2)
318 continue;
319 - if (first_parent_only)
319 + if (bisect_flags & FIND_BISECTION_FIRST_PARENT_ONLY)
320 BUG("shouldn't be calling count-distance in fp mode");
321 weight_set(p, count_distance(p));
322 clear_distance(list);
323
324 /* 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))
326 return p;
327 counted++;
328 }
@@ -332,14 +332,14 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
332 while (counted < nr) {
333 for (p = list; p; p = p->next) {
334 struct commit_list *q;
335 - unsigned flags = p->item->object.flags;
335 + unsigned commit_flags = p->item->object.flags;
336
337 if (0 <= weight(p))
338 continue;
339
340 for (q = p->item->parents;
341 q;
342 - q = first_parent_only ? NULL : q->next) {
342 + q = bisect_flags & FIND_BISECTION_FIRST_PARENT_ONLY ? NULL : q->next) {
343 if (q->item->object.flags & UNINTERESTING)
344 continue;
345 if (0 <= weight(q))
@@ -353,7 +353,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
353 * add one for p itself if p is to be counted,
354 * otherwise inherit it from q directly.
355 */
356 - if (!(flags & TREESAME)) {
356 + if (!(commit_flags & TREESAME)) {
357 weight_set(p, weight(q)+1);
358 counted++;
359 show_list("bisection 2 count one",
@@ -363,21 +363,21 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
363 weight_set(p, weight(q));
364
365 /* 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))
367 return p;
368 }
369 }
370
371 show_list("bisection 2 counted all", counted, nr, list);
372
373 - if (!find_all)
373 + if (!(bisect_flags & FIND_BISECTION_ALL))
374 return best_bisection(list, nr);
375 else
376 return best_bisection_sorted(list, nr);
377 }
378
379 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)
381 {
382 int nr, on_list;
383 struct commit_list *list, *p, *best, *next, *last;
@@ -393,16 +393,16 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
393 for (nr = on_list = 0, last = NULL, p = *commit_list;
394 p;
395 p = next) {
396 - unsigned flags = p->item->object.flags;
396 + unsigned commit_flags = p->item->object.flags;
397
398 next = p->next;
399 - if (flags & UNINTERESTING) {
399 + if (commit_flags & UNINTERESTING) {
400 free(p);
401 continue;
402 }
403 p->next = last;
404 last = p;
405 - if (!(flags & TREESAME))
405 + if (!(commit_flags & TREESAME))
406 nr++;
407 on_list++;
408 }
@@ -413,9 +413,9 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
413 weights = xcalloc(on_list, sizeof(*weights));
414
415 /* 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);
417 if (best) {
418 - if (!find_all) {
418 + if (!(bisect_flags & FIND_BISECTION_ALL)) {
419 list->item = best->item;
420 free_commit_list(list->next);
421 best = list;
@@ -1000,23 +1000,30 @@ enum bisect_error bisect_next_all(struct repository *r, const char *prefix)
1000 struct object_id *bisect_rev;
1001 char *steps_msg;
1002 int no_checkout = ref_exists("BISECT_HEAD");
1003 - int first_parent_only = file_exists(git_path_bisect_first_parent());
1003 + unsigned bisect_flags = 0;
1004
1005 read_bisect_terms(&term_bad, &term_good);
1006 if (read_bisect_refs())
1007 die(_("reading bisect refs failed"));
1008
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 +
1015 res = check_good_are_ancestors_of_bad(r, prefix, no_checkout);
1016 if (res)
1017 return res;
1018
1019 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);
1022 revs.limited = 1;
1023
1024 bisect_common(&revs);
1025
1019 - find_bisection(&revs.commits, &reaches, &all, !!skipped_revs.nr, first_parent_only);
1026 + find_bisection(&revs.commits, &reaches, &all, bisect_flags);
1027 revs.commits = managed_skipped(revs.commits, &tried);
1028
1029 if (!revs.commits) {
bisect.h
+4 -1
@@ -12,7 +12,7 @@ struct repository;
12 * best commit, as chosen by `find_all`.
13 */
14 void find_bisection(struct commit_list **list, int *reaches, int *all,
15 - int find_all, int first_parent_only);
15 + unsigned bisect_flags);
16
17 struct commit_list *filter_skipped(struct commit_list *list,
18 struct commit_list **tried,
@@ -23,6 +23,9 @@ struct commit_list *filter_skipped(struct commit_list *list,
23 #define BISECT_SHOW_ALL (1<<0)
24 #define REV_LIST_QUIET (1<<1)
25
26 +#define FIND_BISECTION_ALL (1u<<0)
27 +#define FIND_BISECTION_FIRST_PARENT_ONLY (1u<<1)
28 +
29 struct rev_list_info {
30 struct rev_info *revs;
31 int flags;
builtin/rev-list.c
+8 -1
@@ -637,8 +637,15 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
637
638 if (bisect_list) {
639 int reaches, all;
640 + unsigned bisect_flags = 0;
641
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);
649
650 if (bisect_show_vars)
651 return show_bisect_vars(&info, reaches, all);