]> git.ipfire.org Git - thirdparty/git.git/commitdiff
list-objects-filter: treat NULL filter_options as "disabled"
authorJeff King <peff@peff.net>
Mon, 4 May 2020 23:12:27 +0000 (17:12 -0600)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 May 2020 04:57:58 +0000 (21:57 -0700)
In most callers, we have an actual list_objects_filter_options struct,
and if no filtering is desired its "choice" element will be
LOFC_DISABLED. However, some code may have only a pointer to such a
struct which may be NULL (because _their_ callers didn't care about
filtering, either). Rather than forcing them to handle this explicitly
like:

  if (filter_options)
          traverse_commit_list_filtered(filter_options, revs,
                                show_commit, show_object,
show_data, NULL);
  else
          traverse_commit_list(revs, show_commit, show_object,
                             show_data);

let's just treat a NULL filter_options the same as LOFC_DISABLED. We
only need a small change, since that option struct is converted into a
real filter only in the "init" function.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
list-objects-filter.c

index 1e8d4e763da07377263086d252d1228004971383..0a3ef3cab3ac31abb679a18f048798e7e4ac54ea 100644 (file)
@@ -663,6 +663,9 @@ struct filter *list_objects_filter__init(
 
        assert((sizeof(s_filters) / sizeof(s_filters[0])) == LOFC__COUNT);
 
+       if (!filter_options)
+               return NULL;
+
        if (filter_options->choice >= LOFC__COUNT)
                BUG("invalid list-objects filter choice: %d",
                    filter_options->choice);