entry: refactor how we remove items for delayed checkouts

When finalizing a delayed checkout, we sort out several strings from the passed-in string list by first assigning the empty string to those filters and then calling `string_list_remove_empty_items()`. Assigning the empty string will cause compiler warnings though as the string is a `char *` once we enable `-Wwrite-strings`. Refactor the code to use a `NULL` pointer with `filter_string_list()` instead to avoid this warning. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 7, 2024 at 08:38 UTC b31607a3e03b2002c468c16bb71fcaf2d1846e09
1 file changed +10 -4
entry.c
+10 -4
@@ -167,6 +167,11 @@ static int remove_available_paths(struct string_list_item *item, void *cb_data)
167 return !available;
168 }
169
170 +static int string_is_not_null(struct string_list_item *item, void *data UNUSED)
171 +{
172 + return !!item->string;
173 +}
174 +
175 int finish_delayed_checkout(struct checkout *state, int show_progress)
176 {
177 int errs = 0;
@@ -189,7 +194,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
194 if (!async_query_available_blobs(filter->string, &available_paths)) {
195 /* Filter reported an error */
196 errs = 1;
192 - filter->string = "";
197 + filter->string = NULL;
198 continue;
199 }
200 if (available_paths.nr <= 0) {
@@ -199,7 +204,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
204 * filter from the list (see
205 * "string_list_remove_empty_items" call below).
206 */
202 - filter->string = "";
207 + filter->string = NULL;
208 continue;
209 }
210
@@ -225,7 +230,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
230 * Do not ask the filter for available blobs,
231 * again, as the filter is likely buggy.
232 */
228 - filter->string = "";
233 + filter->string = NULL;
234 continue;
235 }
236 ce = index_file_exists(state->istate, path->string,
@@ -239,7 +244,8 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
244 errs = 1;
245 }
246 }
242 - string_list_remove_empty_items(&dco->filters, 0);
247 +
248 + filter_string_list(&dco->filters, 0, string_is_not_null, NULL);
249 }
250 stop_progress(&progress);
251 string_list_clear(&dco->filters, 0);