Skip to content

Commit b21a55f

Browse files
chriscoolgitster
authored andcommitted
promisor-remote: parse remote.*.partialclonefilter
This makes it possible to specify a different partial clone filter for each promisor remote. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6b4f57e commit b21a55f

8 files changed

+40
-17
lines changed

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,7 @@ static inline void fetch_one_setup_partial(struct remote *remote)
14911491
* the config.
14921492
*/
14931493
if (!filter_options.choice)
1494-
partial_clone_get_default_filter_spec(&filter_options);
1494+
partial_clone_get_default_filter_spec(&filter_options, remote->name);
14951495
return;
14961496
}
14971497

list-objects-filter-options.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ static int gently_parse_list_objects_filter(
3030
{
3131
const char *v0;
3232

33+
if (!arg)
34+
return 0;
35+
3336
if (filter_options->choice) {
3437
if (errbuf) {
3538
strbuf_addstr(
@@ -146,6 +149,7 @@ void partial_clone_register(
146149
const struct list_objects_filter_options *filter_options)
147150
{
148151
char *cfg_name;
152+
char *filter_name;
149153

150154
/* Check if it is already registered */
151155
if (!promisor_remote_find(remote)) {
@@ -160,27 +164,26 @@ void partial_clone_register(
160164
/*
161165
* Record the initial filter-spec in the config as
162166
* the default for subsequent fetches from this remote.
163-
*
164-
* TODO: record it into remote.<name>.partialclonefilter
165167
*/
166-
core_partial_clone_filter_default =
167-
xstrdup(filter_options->filter_spec);
168-
git_config_set("core.partialclonefilter",
169-
core_partial_clone_filter_default);
168+
filter_name = xstrfmt("remote.%s.partialclonefilter", remote);
169+
git_config_set(filter_name, filter_options->filter_spec);
170+
free(filter_name);
170171

171172
/* Make sure the config info are reset */
172173
promisor_remote_reinit();
173174
}
174175

175176
void partial_clone_get_default_filter_spec(
176-
struct list_objects_filter_options *filter_options)
177+
struct list_objects_filter_options *filter_options,
178+
const char *remote)
177179
{
180+
struct promisor_remote *promisor = promisor_remote_find(remote);
181+
178182
/*
179183
* Parse default value, but silently ignore it if it is invalid.
180184
*/
181-
if (!core_partial_clone_filter_default)
182-
return;
183-
gently_parse_list_objects_filter(filter_options,
184-
core_partial_clone_filter_default,
185-
NULL);
185+
if (promisor)
186+
gently_parse_list_objects_filter(filter_options,
187+
promisor->partial_clone_filter,
188+
NULL);
186189
}

list-objects-filter-options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void partial_clone_register(
8989
const char *remote,
9090
const struct list_objects_filter_options *filter_options);
9191
void partial_clone_get_default_filter_spec(
92-
struct list_objects_filter_options *filter_options);
92+
struct list_objects_filter_options *filter_options,
93+
const char *remote);
9394

9495
#endif /* LIST_OBJECTS_FILTER_OPTIONS_H */

promisor-remote.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ static int promisor_remote_config(const char *var, const char *value, void *data
7575
free(remote_name);
7676
return 0;
7777
}
78+
if (!strcmp(subkey, "partialclonefilter")) {
79+
struct promisor_remote *r;
80+
char *remote_name = xmemdupz(name, namelen);
81+
82+
r = promisor_remote_lookup(remote_name, NULL);
83+
if (!r)
84+
r = promisor_remote_new(remote_name);
85+
86+
free(remote_name);
87+
88+
if (!r)
89+
return 0;
90+
91+
return git_config_string(&r->partial_clone_filter, var, value);
92+
}
7893

7994
return 0;
8095
}

promisor-remote.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ struct object_id;
55

66
/*
77
* Promisor remote linked list
8-
* Its information come from remote.XXX config entries.
8+
*
9+
* Information in its fields come from remote.XXX config entries or
10+
* from extensions.partialclone or core.partialclonefilter.
911
*/
1012
struct promisor_remote {
1113
struct promisor_remote *next;
14+
const char *partial_clone_filter;
1215
const char name[FLEX_ARRAY];
1316
};
1417

t/t0410-partial-clone.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ promise_and_delete () {
2626
test_expect_success 'extensions.partialclone without filter' '
2727
test_create_repo server &&
2828
git clone --filter="blob:none" "file://$(pwd)/server" client &&
29-
git -C client config --unset core.partialclonefilter &&
29+
git -C client config --unset remote.origin.partialclonefilter &&
3030
git -C client fetch origin
3131
'
3232

t/t5601-clone.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ partial_clone () {
654654

655655
# Ensure that unneeded blobs are not inadvertently fetched.
656656
test_config -C client remote.origin.promisor "false" &&
657+
git -C client config --unset remote.origin.partialclonefilter &&
657658
test_must_fail git -C client cat-file -e "$HASH1" &&
658659

659660
# But this blob was fetched, because clone performs an initial checkout

t/t5616-partial-clone.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test_expect_success 'do partial clone 1' '
4343
test_cmp expect_1.oids observed.oids &&
4444
test "$(git -C pc1 config --local core.repositoryformatversion)" = "1" &&
4545
test "$(git -C pc1 config --local remote.origin.promisor)" = "true" &&
46-
test "$(git -C pc1 config --local core.partialclonefilter)" = "blob:none"
46+
test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none"
4747
'
4848

4949
# checkout master to force dynamic object fetch of blobs at HEAD.

0 commit comments

Comments
 (0)