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

Re: [PATCH v4 10/10] list-objects-filter-options: make parser void

From
Matthew DeVore <matvore@comcast.net>
Date
Jun 27, 2019, 21:24 UTC
Message-ID
<20190627212457.GD54617@comcast.net>
In-Reply-To
<20190622004631.251573-1-jonathantanmy@google.com>
On Fri, Jun 21, 2019 at 05:46:31PM -0700, Jonathan Tan wrote:
Show 7 quoted lines
> > This function always returns 0, so make it return void instead.
> 
> And...patches 7-10 look straightforward and good to me.
> 
> In summary, I don't think any changes need to be made to all 10 patches
> other than textual ones (commit messages, documentation, and function
> names).

Great. I feel much better about the comments and commit messages now. I am about to send a roll-up (v5). Here is the interdiff which catches your comments and Dscho's comment about strbuf_addstr:

diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index d9c8da5b70..9e64832a5e 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -139,22 +139,21 @@ static int parse_combine_subfilter(
 static int parse_combine_filter(
 	struct list_objects_filter_options *filter_options,
 	const char *arg,
 	struct strbuf *errbuf)
 {
 	struct strbuf **subspecs = strbuf_split_str(arg, '+', 0);
 	size_t sub;
 	int result = 0;
 
 	if (!subspecs[0]) {
-		strbuf_addf(errbuf,
-			    _("expected something after combine:"));
+		strbuf_addstr(errbuf, _("expected something after combine:"));
 		result = 1;
 		goto cleanup;
 	}
 
 	for (sub = 0; subspecs[sub] && !result; sub++) {
 		if (subspecs[sub + 1]) {
 			/*
 			 * This is not the last subspec. Remove trailing "+" so
 			 * we can parse it.
 			 */
diff --git a/list-objects-filter.c b/list-objects-filter.c
index 6b99f707e4..d664264d65 100644
--- a/list-objects-filter.c
+++ b/list-objects-filter.c
@@ -38,23 +38,33 @@ struct filter {
 	enum list_objects_filter_result (*filter_object_fn)(
 		struct repository *r,
 		enum list_objects_filter_situation filter_situation,
 		struct object *obj,
 		const char *pathname,
 		const char *filename,
 		struct oidset *omits,
 		void *filter_data);
 
 	/*
-	 * Optional. If this function is supplied and the filter needs to
-	 * collect omits, then this function is called once before free_fn is
-	 * called.
+	 * Optional. If this function is supplied and the filter needs
+	 * to collect omits, then this function is called once before
+	 * free_fn is called.
+	 *
+	 * This is required because the following two conditions hold:
+	 *
+	 *   a. A tree filter can add and remove objects as an object
+	 *      graph is traversed.
+	 *   b. A combine filter's omit set is the union of all its
+	 *      subfilters, which may include tree: filters.
+	 *
+	 * As such, the omits sets must be separate sets, and can only
+	 * be unioned after the traversal is completed.
 	 */
 	void (*finalize_omits_fn)(struct oidset *omits, void *filter_data);
 
 	void (*free_fn)(void *filter_data);
 
 	void *filter_data;
 
 	/* If non-NULL, the filter collects a list of the omitted OIDs here. */
 	struct oidset *omits;
 };
@@ -485,54 +495,46 @@ static void filter_sparse_oid__init(
 	filter->filter_object_fn = filter_sparse;
 	filter->free_fn = filter_sparse_free;
 }
 
 /* A filter which only shows objects shown by all sub-filters. */
 struct combine_filter_data {
 	struct subfilter *sub;
 	size_t nr;
 };
 
-static int should_delegate(enum list_objects_filter_situation filter_situation,
-			   struct object *obj,
-			   struct subfilter *sub)
-{
-	if (!sub->is_skipping_tree)
-		return 1;
-	if (filter_situation == LOFS_END_TREE &&
-		oideq(&obj->oid, &sub->skip_tree)) {
-		sub->is_skipping_tree = 0;
-		return 1;
-	}
-	return 0;
-}
-
 static enum list_objects_filter_result process_subfilter(
 	struct repository *r,
 	enum list_objects_filter_situation filter_situation,
 	struct object *obj,
 	const char *pathname,
 	const char *filename,
 	struct subfilter *sub)
 {
 	enum list_objects_filter_result result;
 
 	/*
-	 * Check should_delegate before oidset_contains so that
-	 * is_skipping_tree gets unset even when the object is marked as seen.
-	 * As of this writing, no filter uses LOFR_MARK_SEEN on trees that also
-	 * uses LOFR_SKIP_TREE, so the ordering is only theoretically
-	 * important. Be cautious if you change the order of the below checks
-	 * and more filters have been added!
+	 * Check and update is_skipping_tree before oidset_contains so
+	 * that is_skipping_tree gets unset even when the object is
+	 * marked as seen.  As of this writing, no filter uses
+	 * LOFR_MARK_SEEN on trees that also uses LOFR_SKIP_TREE, so the
+	 * ordering is only theoretically important. Be cautious if you
+	 * change the order of the below checks and more filters have
+	 * been added!
 	 */
-	if (!should_delegate(filter_situation, obj, sub))
-		return LOFR_ZERO;
+	if (sub->is_skipping_tree) {
+		if (filter_situation == LOFS_END_TREE &&
+		    oideq(&obj->oid, &sub->skip_tree))
+			sub->is_skipping_tree = 0;
+		else
+			return LOFR_ZERO;
+	}
 	if (oidset_contains(&sub->seen, &obj->oid))
 		return LOFR_ZERO;
 
 	result = list_objects_filter__filter_object(
 		r, filter_situation, obj, pathname, filename, sub->filter);
 
 	if (result & LOFR_MARK_SEEN)
 		oidset_insert(&sub->seen, &obj->oid);
 
 	if (result & LOFR_SKIP_TREE) {
@@ -673,22 +675,23 @@ enum list_objects_filter_result list_objects_filter__filter_object(
 	const char *pathname,
 	const char *filename,
 	struct filter *filter)
 {
 	if (filter && (obj->flags & NOT_USER_GIVEN))
 		return filter->filter_object_fn(r, filter_situation, obj,
 						pathname, filename,
 						filter->omits,
 						filter->filter_data);
 	/*
-	 * No filter is active or user gave object explicitly. Choose default
-	 * behavior based on filter situation.
+	 * No filter is active or user gave object explicitly. In this case,
+	 * always show the object (except when LOFS_END_TREE, since this tree
+	 * had already been shown when LOFS_BEGIN_TREE).
 	 */
 	if (filter_situation == LOFS_END_TREE)
 		return 0;
 	return LOFR_MARK_SEEN | LOFR_DO_SHOW;
 }
 
 void list_objects_filter__free(struct filter *filter)
 {
 	if (!filter)
 		return;
diff --git a/list-objects-filter.h b/list-objects-filter.h
index 6908954266..cfd784e203 100644
--- a/list-objects-filter.h
+++ b/list-objects-filter.h
@@ -55,32 +55,41 @@ enum list_objects_filter_result {
 };
 
 enum list_objects_filter_situation {
 	LOFS_BEGIN_TREE,
 	LOFS_END_TREE,
 	LOFS_BLOB
 };
 
 struct filter;
 
-/* Constructor for the set of defined list-objects filters. */
+/*
+ * Constructor for the set of defined list-objects filters.
+ * The `omitted` set is optional. It is populated with objects that the
+ * filter excludes. This set should not be considered finalized until
+ * after list_objects_filter__free is called on the returned `struct
+ * filter *`.
+ */
 struct filter *list_objects_filter__init(
 	struct oidset *omitted,
 	struct list_objects_filter_options *filter_options);
 
 /*
  * Lets `filter` decide how to handle the `obj`. If `filter` is NULL, this
  * function behaves as expected if no filter is configured: all objects are
  * included.
  */
 enum list_objects_filter_result list_objects_filter__filter_object(
 	struct repository *r,
 	enum list_objects_filter_situation filter_situation,
 	struct object *obj,
 	const char *pathname,
 	const char *filename,
 	struct filter *filter);
 
-/* Destroys `filter`. Does nothing if `filter` is null. */
+/*
+ * Destroys `filter` and finalizes the `omitted` set, if present. Does
+ * nothing if `filter` is null.
+ */
 void list_objects_filter__free(struct filter *filter);
 
 #endif /* LIST_OBJECTS_FILTER_H */
Previous: Jonathan TanNext: Matthew DeVore
Message 59 of 74 in “Filter combination”
  1. 0/9 Filter combinationMatthew DeVore, Jun 1, 2019
  2. 1/9 list-objects-filter: make API easier to useMatthew DeVore, Jun 1, 2019
  3. 2/9 list-objects-filter: put omits set in filter structMatthew DeVore, Jun 1, 2019
  4. 3/9 list-objects-filter-options: always supply *errbufMatthew DeVore, Jun 1, 2019
  5. 4/9 list-objects-filter: implement composite filtersMatthew DeVore, Jun 1, 2019
  6. Jeff HostetlerJun 3, 2019
  7. Matthew DeVoreJun 6, 2019
  8. Jeff HostetlerJun 7, 2019
  9. 5/9 list-objects-filter-options: move error check upMatthew DeVore, Jun 1, 2019
  10. 6/9 list-objects-filter-options: make filter_spec a strbufMatthew DeVore, Jun 1, 2019
  11. Junio C HamanoJun 10, 2019
  12. Matthew DeVoreJun 11, 2019
  13. Junio C HamanoJun 11, 2019
  14. Matthew DeVoreJun 11, 2019
  15. Matthew DeVoreJun 11, 2019
  16. Junio C HamanoJun 11, 2019
  17. Matthew DeVoreJun 12, 2019
  18. Matthew DeVoreJun 12, 2019
  19. 7/9 list-objects-filter-options: allow mult. --filterMatthew DeVore, Jun 1, 2019
  20. 8/9 list-objects-filter-options: clean up use of ALLOC_GROWMatthew DeVore, Jun 1, 2019
  21. Jacob KellerJun 3, 2019
  22. Matthew DeVoreJun 3, 2019
  23. Jacob KellerJun 4, 2019
  24. 9/9 list-objects-filter-options: make parser voidMatthew DeVore, Jun 1, 2019
  25. Jeff HostetlerJun 3, 2019
  26. 00/10 Filter combinationMatthew DeVore, Jun 13, 2019
  27. 01/10 list-objects-filter: make API easier to useMatthew DeVore, Jun 13, 2019
  28. 02/10 list-objects-filter: put omits set in filter structMatthew DeVore, Jun 13, 2019
  29. 03/10 list-objects-filter-options: always supply *errbufMatthew DeVore, Jun 13, 2019
  30. 04/10 list-objects-filter: implement composite filtersMatthew DeVore, Jun 13, 2019
  31. 05/10 list-objects-filter-options: move error check upMatthew DeVore, Jun 13, 2019
  32. 06/10 list-objects-filter-options: make filter_spec a string_listMatthew DeVore, Jun 13, 2019
  33. 07/10 strbuf: give URL-encoding API a char predicate fnMatthew DeVore, Jun 13, 2019
  34. 08/10 list-objects-filter-options: allow mult. --filterMatthew DeVore, Jun 13, 2019
  35. 09/10 list-objects-filter-options: clean up use of ALLOC_GROWMatthew DeVore, Jun 13, 2019
  36. 10/10 list-objects-filter-options: make parser voidMatthew DeVore, Jun 13, 2019
  37. Junio C HamanoJun 14, 2019
  38. 00/10 Filter combinationMatthew DeVore, Jun 15, 2019
  39. 01/10 list-objects-filter: make API easier to useMatthew DeVore, Jun 15, 2019
  40. Jonathan TanJun 21, 2019
  41. Matthew DeVoreJun 27, 2019
  42. 02/10 list-objects-filter: put omits set in filter structMatthew DeVore, Jun 15, 2019
  43. 03/10 list-objects-filter-options: always supply *errbufMatthew DeVore, Jun 15, 2019
  44. 04/10 list-objects-filter: implement composite filtersMatthew DeVore, Jun 15, 2019
  45. Johannes SchindelinJun 18, 2019
  46. Matthew DeVoreJun 18, 2019
  47. Johannes SchindelinJun 21, 2019
  48. Jonathan TanJun 22, 2019
  49. Matthew DeVoreJun 27, 2019
  50. 05/10 list-objects-filter-options: move error check upMatthew DeVore, Jun 15, 2019
  51. 06/10 list-objects-filter-options: make filter_spec a string_listMatthew DeVore, Jun 15, 2019
  52. Jonathan TanJun 22, 2019
  53. Matthew DeVoreJun 27, 2019
  54. 07/10 strbuf: give URL-encoding API a char predicate fnMatthew DeVore, Jun 15, 2019
  55. 08/10 list-objects-filter-options: allow mult. --filterMatthew DeVore, Jun 15, 2019
  56. 09/10 list-objects-filter-options: clean up use of ALLOC_GROWMatthew DeVore, Jun 15, 2019
  57. 10/10 list-objects-filter-options: make parser voidMatthew DeVore, Jun 15, 2019
  58. Jonathan TanJun 22, 2019
  59. Matthew DeVoreJun 27, 2019
  60. Matthew DeVoreJun 27, 2019
  61. Junio C HamanoJun 18, 2019
  62. 00/10 Filter combinationMatthew DeVore, Jun 27, 2019
  63. 01/10 list-objects-filter: encapsulate filter componentsMatthew DeVore, Jun 27, 2019
  64. 03/10 list-objects-filter-options: always supply *errbufMatthew DeVore, Jun 27, 2019
  65. 02/10 list-objects-filter: put omits set in filter structMatthew DeVore, Jun 27, 2019
  66. 04/10 list-objects-filter: implement composite filtersMatthew DeVore, Jun 27, 2019
  67. 05/10 list-objects-filter-options: move error check upMatthew DeVore, Jun 27, 2019
  68. 06/10 list-objects-filter-options: make filter_spec a string_listMatthew DeVore, Jun 27, 2019
  69. 07/10 strbuf: give URL-encoding API a char predicate fnMatthew DeVore, Jun 27, 2019
  70. 08/10 list-objects-filter-options: allow mult. --filterMatthew DeVore, Jun 27, 2019
  71. 09/10 list-objects-filter-options: clean up use of ALLOC_GROWMatthew DeVore, Jun 27, 2019
  72. 10/10 list-objects-filter-options: make parser voidMatthew DeVore, Jun 27, 2019
  73. Junio C HamanoJun 28, 2019
  74. Jonathan TanJun 28, 2019

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.