]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: do not override partial clone filter
authorJonathan Tan <jonathantanmy@google.com>
Mon, 28 Sep 2020 22:26:38 +0000 (15:26 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Sep 2020 23:11:59 +0000 (16:11 -0700)
When a fetch with the --filter argument is made, the configured default
filter is set even if one already exists. This change was made in
5e46139376 ("builtin/fetch: remove unique promisor remote limitation",
2019-06-25) - in particular, changing from:

 * If this is the FIRST partial-fetch request, we enable partial
 * on this repo and remember the given filter-spec as the default
 * for subsequent fetches to this remote.

to:

 * If this is a partial-fetch request, we enable partial on
 * this repo if not already enabled and remember the given
 * filter-spec as the default for subsequent fetches to this
 * remote.

(The given filter-spec is "remembered" even if there is already an
existing one.)

This is problematic whenever a lazy fetch is made, because lazy fetches
are made using "git fetch --filter=blob:none", but this will also happen
if the user invokes "git fetch --filter=<filter>" manually. Therefore,
restore the behavior prior to 5e46139376, which writes a filter-spec
only if the current fetch request is the first partial-fetch one (for
that remote).

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
list-objects-filter-options.c
t/t5601-clone.sh

index c555836937564ddc7551a163fde9ef449c1784eb..97930f8201e452a5e30a6ffc7339de944bcf2b49 100644 (file)
@@ -1677,7 +1677,7 @@ static inline void fetch_one_setup_partial(struct remote *remote)
         * If this is a partial-fetch request, we enable partial on
         * this repo if not already enabled and remember the given
         * filter-spec as the default for subsequent fetches to this
-        * remote.
+        * remote if there is currently no default filter-spec.
         */
        if (filter_options.choice) {
                partial_clone_register(remote->name, &filter_options);
index b66314560ac957d722985ad935ecb7fb49663b85..defd3dfd101f414c5708dc576ff4b7fac8a058a3 100644 (file)
@@ -344,11 +344,19 @@ void partial_clone_register(
        const char *remote,
        struct list_objects_filter_options *filter_options)
 {
+       struct promisor_remote *promisor_remote;
        char *cfg_name;
        char *filter_name;
 
        /* Check if it is already registered */
-       if (!promisor_remote_find(remote)) {
+       if ((promisor_remote = promisor_remote_find(remote))) {
+               if (promisor_remote->partial_clone_filter)
+                       /*
+                        * Remote is already registered and a filter is already
+                        * set, so we don't need to do anything here.
+                        */
+                       return;
+       } else {
                if (upgrade_repository_format(1) < 0)
                        die(_("unable to upgrade repository format to support partial clone"));
 
index 15fb64c18d860e582542c0ae225897b9b22e89d0..4631f019fe3e9f4f7a7a7c0c0f7b2b0341d49032 100755 (executable)
@@ -669,7 +669,8 @@ test_expect_success 'partial clone' '
 
 test_expect_success 'partial clone with -o' '
        partial_clone_server server &&
-       git clone -o blah --filter=blob:limit=0 "file://$(pwd)/server" client
+       git clone -o blah --filter=blob:limit=0 "file://$(pwd)/server" client &&
+       test_cmp_config -C client "blob:limit=0" --get-all remote.blah.partialclonefilter
 '
 
 test_expect_success 'partial clone: warn if server does not support object filtering' '