diff mbox series

[2/2] fetch: do not override partial clone filter

Message ID 070a717aabbac31ae44567dbe54a325029f9931f.1600743698.git.jonathantanmy@google.com (mailing list archive)
State Superseded
Headers show
Series Fix overriding of partial clone filter when lazy-fetching | expand

Commit Message

Jonathan Tan Sept. 22, 2020, 3:03 a.m. UTC
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>
---
 builtin/fetch.c               |  2 +-
 list-objects-filter-options.c | 10 +++++++++-
 t/t5601-clone.sh              |  5 +++++
 3 files changed, 15 insertions(+), 2 deletions(-)

Comments

Junio C Hamano Sept. 22, 2020, 5:46 a.m. UTC | #1
Jonathan Tan <jonathantanmy@google.com> writes:

> +test_expect_success 'ensure that filter is written to config' '
> +	FILTER=$(git -C client config --get remote.blah.partialclonefilter) &&
> +	test "$FILTER" == "blob:limit=0"

I'll do s/==/=/ locally because otherwise the test-lint-shell-syntax
will choke on this line.  No need to resend only this line.

Thanks.

> +'
> +
>  test_expect_success 'partial clone: warn if server does not support object filtering' '
>  	rm -rf server client &&
>  	test_create_repo server &&
Derrick Stolee Sept. 22, 2020, 11:35 a.m. UTC | #2
On 9/22/2020 1:46 AM, Junio C Hamano wrote:
> Jonathan Tan <jonathantanmy@google.com> writes:
> 
>> +test_expect_success 'ensure that filter is written to config' '
>> +	FILTER=$(git -C client config --get remote.blah.partialclonefilter) &&
>> +	test "$FILTER" == "blob:limit=0"
> 
> I'll do s/==/=/ locally because otherwise the test-lint-shell-syntax
> will choke on this line.  No need to resend only this line.

Wouldn't "test_cmp_config" be a better here? It seems like
this is testing the "git clone" behavior of the previous test,
so it could be added to that test instead.

Thanks,
-Stolee
Junio C Hamano Sept. 22, 2020, 3:51 p.m. UTC | #3
Derrick Stolee <stolee@gmail.com> writes:

> On 9/22/2020 1:46 AM, Junio C Hamano wrote:
>> Jonathan Tan <jonathantanmy@google.com> writes:
>> 
>>> +test_expect_success 'ensure that filter is written to config' '
>>> +	FILTER=$(git -C client config --get remote.blah.partialclonefilter) &&
>>> +	test "$FILTER" == "blob:limit=0"
>> 
>> I'll do s/==/=/ locally because otherwise the test-lint-shell-syntax
>> will choke on this line.  No need to resend only this line.
>
> Wouldn't "test_cmp_config" be a better here? It seems like
> this is testing the "git clone" behavior of the previous test,
> so it could be added to that test instead.

TIL that one ;-) "git config --get" gives only a single instance,
but in this particular case, shouldn't we be verifying not just that
the expected one is found, but it is the only one, with "--get-all"?

FWIW, many uses of that test helper may want to be tightened the
same way.  In short, unless we are testing the last-one-wins
behaviour, and especially when we are interested in what changes our
tested operation makes to the config file's contents, we should be
using "--get-all" instead of the default "--get", I suspect.

Thanks.
diff mbox series

Patch

diff --git a/builtin/fetch.c b/builtin/fetch.c
index a6d3268661..752148eec5 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -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);
diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c
index b66314560a..defd3dfd10 100644
--- a/list-objects-filter-options.c
+++ b/list-objects-filter-options.c
@@ -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"));
 
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 15fb64c18d..7c5cf5a2ec 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -672,6 +672,11 @@  test_expect_success 'partial clone with -o' '
 	git clone -o blah --filter=blob:limit=0 "file://$(pwd)/server" client
 '
 
+test_expect_success 'ensure that filter is written to config' '
+	FILTER=$(git -C client config --get remote.blah.partialclonefilter) &&
+	test "$FILTER" == "blob:limit=0"
+'
+
 test_expect_success 'partial clone: warn if server does not support object filtering' '
 	rm -rf server client &&
 	test_create_repo server &&