git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/4] list-objects-filter: treat NULL filter_options as "disabled"

From
Taylor Blau <me@ttaylorr.com>
Date
May 4, 2020, 23:12 UTC
Message-ID
<bb7d99ee2582d60e2413df56cb2c3fb06c18de8e.1588633810.git.me@ttaylorr.com>
In-Reply-To
<cover.1588633810.git.me@ttaylorr.com>
From: Jeff King <peff@peff.net>

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>
---
 list-objects-filter.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 1e8d4e763d..0a3ef3cab3 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -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);
-- 
2.26.0.113.ge9739cdccc
Previous: Taylor BlauNext: Junio C Hamano
Message 2 of 12 in “pack-bitmap: use bitmaps for traversals with '--filter=tree:0'”
  1. 0/4 pack-bitmap: use bitmaps for traversals with '--filter=tree:0'Taylor Blau, May 4, 2020
  2. 1/4 list-objects-filter: treat NULL filter_options as "disabled"Taylor Blau, May 4, 2020
  3. Junio C HamanoMay 5, 2020
  4. 2/4 pack-bitmap.c: make object filtering functions genericTaylor Blau, May 4, 2020
  5. Junio C HamanoMay 5, 2020
  6. 3/4 pack-bitmap.c: support 'tree:0' filteringTaylor Blau, May 4, 2020
  7. Junio C HamanoMay 5, 2020
  8. Taylor BlauMay 5, 2020
  9. Junio C HamanoMay 5, 2020
  10. 4/4 pack-bitmap: pass object filter to fill-in traversalTaylor Blau, May 4, 2020
  11. Junio C HamanoMay 5, 2020
  12. Taylor BlauMay 5, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.