]> git.ipfire.org Git - thirdparty/git.git/commitdiff
entry: refactor how we remove items for delayed checkouts
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Jun 2024 06:38:20 +0000 (08:38 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:30:51 +0000 (10:30 -0700)
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>
entry.c

diff --git a/entry.c b/entry.c
index b8c257f6f9f2d88a69e1fe46e88d7b18ca85bd5f..f291d8eee6a8df2216c102efbd55995b3a6a6554 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -167,6 +167,11 @@ static int remove_available_paths(struct string_list_item *item, void *cb_data)
        return !available;
 }
 
+static int string_is_not_null(struct string_list_item *item, void *data UNUSED)
+{
+       return !!item->string;
+}
+
 int finish_delayed_checkout(struct checkout *state, int show_progress)
 {
        int errs = 0;
@@ -189,7 +194,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
                        if (!async_query_available_blobs(filter->string, &available_paths)) {
                                /* Filter reported an error */
                                errs = 1;
-                               filter->string = "";
+                               filter->string = NULL;
                                continue;
                        }
                        if (available_paths.nr <= 0) {
@@ -199,7 +204,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
                                 * filter from the list (see
                                 * "string_list_remove_empty_items" call below).
                                 */
-                               filter->string = "";
+                               filter->string = NULL;
                                continue;
                        }
 
@@ -225,7 +230,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
                                         * Do not ask the filter for available blobs,
                                         * again, as the filter is likely buggy.
                                         */
-                                       filter->string = "";
+                                       filter->string = NULL;
                                        continue;
                                }
                                ce = index_file_exists(state->istate, path->string,
@@ -239,7 +244,8 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
                                        errs = 1;
                        }
                }
-               string_list_remove_empty_items(&dco->filters, 0);
+
+               filter_string_list(&dco->filters, 0, string_is_not_null, NULL);
        }
        stop_progress(&progress);
        string_list_clear(&dco->filters, 0);