list-objects: consolidate traverse_commit_list[_filtered]

Now that all consumers of traverse_commit_list_filtered() populate the 'filter' member of 'struct rev_info', we can drop that parameter from the method prototype to simplify things. In addition, the only thing different now between traverse_commit_list_filtered() and traverse_commit_list() is the presence of the 'omitted' parameter, which is only non-NULL for one caller. We can consolidate these two methods by having one call the other and use the simpler form everywhere the 'omitted' parameter would be NULL. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Mar 9, 2022 at 16:01 UTC 3e0370a8d2251742d583ce095072b7dcc34b3c01
5 files changed +29 -31
builtin/pack-objects.c
+3 -3
@@ -3778,9 +3778,9 @@ static void get_object_list(int ac, const char **av)
3778
3779 if (!fn_show_object)
3780 fn_show_object = show_object;
3781 - traverse_commit_list_filtered(&revs.filter, &revs,
3782 - show_commit, fn_show_object, NULL,
3783 - NULL);
3781 + traverse_commit_list(&revs,
3782 + show_commit, fn_show_object,
3783 + NULL);
3784
3785 if (unpack_unreachable_expiration) {
3786 revs.ignore_missing_links = 1;
builtin/rev-list.c
+1 -1
@@ -729,7 +729,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
729 oidset_init(&missing_objects, DEFAULT_OIDSET_SIZE);
730
731 traverse_commit_list_filtered(
732 - &revs.filter, &revs, show_commit, show_object, &info,
732 + &revs, show_commit, show_object, &info,
733 (arg_print_omitted ? &omitted_objects : NULL));
734
735 if (arg_print_omitted) {
list-objects.c
+12 -22
@@ -416,35 +416,25 @@ static void do_traverse(struct traversal_context *ctx)
416 strbuf_release(&csp);
417 }
418
419 -void traverse_commit_list(struct rev_info *revs,
420 - show_commit_fn show_commit,
421 - show_object_fn show_object,
422 - void *show_data)
423 -{
424 - struct traversal_context ctx;
425 - ctx.revs = revs;
426 - ctx.show_commit = show_commit;
427 - ctx.show_object = show_object;
428 - ctx.show_data = show_data;
429 - ctx.filter = NULL;
430 - do_traverse(&ctx);
431 -}
432 -
419 void traverse_commit_list_filtered(
434 - struct list_objects_filter_options *filter_options,
420 struct rev_info *revs,
421 show_commit_fn show_commit,
422 show_object_fn show_object,
423 void *show_data,
424 struct oidset *omitted)
425 {
441 - struct traversal_context ctx;
426 + struct traversal_context ctx = {
427 + .revs = revs,
428 + .show_object = show_object,
429 + .show_commit = show_commit,
430 + .show_data = show_data,
431 + };
432 +
433 + if (revs->filter.choice)
434 + ctx.filter = list_objects_filter__init(omitted, &revs->filter);
435
443 - ctx.revs = revs;
444 - ctx.show_object = show_object;
445 - ctx.show_commit = show_commit;
446 - ctx.show_data = show_data;
447 - ctx.filter = list_objects_filter__init(omitted, filter_options);
436 do_traverse(&ctx);
449 - list_objects_filter__free(ctx.filter);
437 +
438 + if (ctx.filter)
439 + list_objects_filter__free(ctx.filter);
440 }
list-objects.h
+10 -2
@@ -7,7 +7,6 @@ struct rev_info;
7
8 typedef void (*show_commit_fn)(struct commit *, void *);
9 typedef void (*show_object_fn)(struct object *, const char *, void *);
10 -void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, void *);
10
11 typedef void (*show_edge_fn)(struct commit *);
12 void mark_edges_uninteresting(struct rev_info *revs,
@@ -18,11 +17,20 @@ struct oidset;
17 struct list_objects_filter_options;
18
19 void traverse_commit_list_filtered(
21 - struct list_objects_filter_options *filter_options,
20 struct rev_info *revs,
21 show_commit_fn show_commit,
22 show_object_fn show_object,
23 void *show_data,
24 struct oidset *omitted);
25
26 +static inline void traverse_commit_list(
27 + struct rev_info *revs,
28 + show_commit_fn show_commit,
29 + show_object_fn show_object,
30 + void *show_data)
31 +{
32 + traverse_commit_list_filtered(revs, show_commit,
33 + show_object, show_data, NULL);
34 +}
35 +
36 #endif /* LIST_OBJECTS_H */
pack-bitmap.c
+3 -3
@@ -822,9 +822,9 @@ static struct bitmap *find_objects(struct bitmap_index *bitmap_git,
822 show_data.bitmap_git = bitmap_git;
823 show_data.base = base;
824
825 - traverse_commit_list_filtered(&revs->filter, revs,
826 - show_commit, show_object,
827 - &show_data, NULL);
825 + traverse_commit_list(revs,
826 + show_commit, show_object,
827 + &show_data);
828
829 revs->include_check = NULL;
830 revs->include_check_obj = NULL;