Skip to content

Commit a82fa7b

Browse files
committed
Merge branch 'jk/upload-pack-v2-capability-cleanup'
The upload-pack program, when talking over v2, accepted the packfile-uris protocol extension from the client, even if it did not advertise the capability, which has been corrected. * jk/upload-pack-v2-capability-cleanup: upload-pack: only accept packfile-uris if we advertised it upload-pack: use existing config mechanism for advertisement upload-pack: centralize setup of sideband-all config upload-pack: use repository struct to get config
2 parents 56d6084 + a922bfa commit a82fa7b

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

t/t5702-protocol-v2.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,25 @@ test_expect_success 'archive with custom path does not request v2' '
778778
! grep ^GIT_PROTOCOL env.trace
779779
'
780780

781+
test_expect_success 'reject client packfile-uris if not advertised' '
782+
{
783+
packetize command=fetch &&
784+
packetize object-format=$(test_oid algo) &&
785+
printf 0001 &&
786+
packetize packfile-uris https &&
787+
packetize done &&
788+
printf 0000
789+
} >input &&
790+
test_must_fail env GIT_PROTOCOL=version=2 \
791+
git upload-pack client <input &&
792+
test_must_fail env GIT_PROTOCOL=version=2 \
793+
git -c uploadpack.blobpackfileuri \
794+
upload-pack client <input &&
795+
GIT_PROTOCOL=version=2 \
796+
git -c uploadpack.blobpackfileuri=anything \
797+
upload-pack client <input
798+
'
799+
781800
# Test protocol v2 with 'http://' transport
782801
#
783802
. "$TEST_DIRECTORY"/lib-httpd.sh

upload-pack.c

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct upload_pack_data {
114114
unsigned allow_ref_in_want : 1; /* v2 only */
115115
unsigned allow_sideband_all : 1; /* v2 only */
116116
unsigned seen_haves : 1; /* v2 only */
117+
unsigned allow_packfile_uris : 1; /* v2 only */
117118
unsigned advertise_sid : 1;
118119
unsigned sent_capabilities : 1;
119120
};
@@ -1363,6 +1364,9 @@ static int upload_pack_config(const char *var, const char *value,
13631364
data->allow_ref_in_want = git_config_bool(var, value);
13641365
} else if (!strcmp("uploadpack.allowsidebandall", var)) {
13651366
data->allow_sideband_all = git_config_bool(var, value);
1367+
} else if (!strcmp("uploadpack.blobpackfileuri", var)) {
1368+
if (value)
1369+
data->allow_packfile_uris = 1;
13661370
} else if (!strcmp("core.precomposeunicode", var)) {
13671371
precomposed_unicode = git_config_bool(var, value);
13681372
} else if (!strcmp("transfer.advertisesid", var)) {
@@ -1386,10 +1390,13 @@ static int upload_pack_protected_config(const char *var, const char *value,
13861390
return 0;
13871391
}
13881392

1389-
static void get_upload_pack_config(struct upload_pack_data *data)
1393+
static void get_upload_pack_config(struct repository *r,
1394+
struct upload_pack_data *data)
13901395
{
1391-
git_config(upload_pack_config, data);
1396+
repo_config(r, upload_pack_config, data);
13921397
git_protected_config(upload_pack_protected_config, data);
1398+
1399+
data->allow_sideband_all |= git_env_bool("GIT_TEST_SIDEBAND_ALL", 0);
13931400
}
13941401

13951402
void upload_pack(const int advertise_refs, const int stateless_rpc,
@@ -1399,7 +1406,7 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
13991406
struct upload_pack_data data;
14001407

14011408
upload_pack_data_init(&data);
1402-
get_upload_pack_config(&data);
1409+
get_upload_pack_config(the_repository, &data);
14031410

14041411
data.stateless_rpc = stateless_rpc;
14051412
data.timeout = timeout;
@@ -1641,14 +1648,14 @@ static void process_args(struct packet_reader *request,
16411648
continue;
16421649
}
16431650

1644-
if ((git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
1645-
data->allow_sideband_all) &&
1651+
if (data->allow_sideband_all &&
16461652
!strcmp(arg, "sideband-all")) {
16471653
data->writer.use_sideband = 1;
16481654
continue;
16491655
}
16501656

1651-
if (skip_prefix(arg, "packfile-uris ", &p)) {
1657+
if (data->allow_packfile_uris &&
1658+
skip_prefix(arg, "packfile-uris ", &p)) {
16521659
if (data->uri_protocols.nr)
16531660
send_err_and_die(data,
16541661
"multiple packfile-uris lines forbidden");
@@ -1754,7 +1761,7 @@ enum fetch_state {
17541761
FETCH_DONE,
17551762
};
17561763

1757-
int upload_pack_v2(struct repository *r UNUSED, struct packet_reader *request)
1764+
int upload_pack_v2(struct repository *r, struct packet_reader *request)
17581765
{
17591766
enum fetch_state state = FETCH_PROCESS_ARGS;
17601767
struct upload_pack_data data;
@@ -1763,7 +1770,7 @@ int upload_pack_v2(struct repository *r UNUSED, struct packet_reader *request)
17631770

17641771
upload_pack_data_init(&data);
17651772
data.use_sideband = LARGE_PACKET_MAX;
1766-
get_upload_pack_config(&data);
1773+
get_upload_pack_config(r, &data);
17671774

17681775
while (state != FETCH_DONE) {
17691776
switch (state) {
@@ -1822,41 +1829,28 @@ int upload_pack_v2(struct repository *r UNUSED, struct packet_reader *request)
18221829
int upload_pack_advertise(struct repository *r,
18231830
struct strbuf *value)
18241831
{
1825-
if (value) {
1826-
int allow_filter_value;
1827-
int allow_ref_in_want;
1828-
int allow_sideband_all_value;
1829-
char *str = NULL;
1832+
struct upload_pack_data data;
1833+
1834+
upload_pack_data_init(&data);
1835+
get_upload_pack_config(r, &data);
18301836

1837+
if (value) {
18311838
strbuf_addstr(value, "shallow wait-for-done");
18321839

1833-
if (!repo_config_get_bool(r,
1834-
"uploadpack.allowfilter",
1835-
&allow_filter_value) &&
1836-
allow_filter_value)
1840+
if (data.allow_filter)
18371841
strbuf_addstr(value, " filter");
18381842

1839-
if (!repo_config_get_bool(r,
1840-
"uploadpack.allowrefinwant",
1841-
&allow_ref_in_want) &&
1842-
allow_ref_in_want)
1843+
if (data.allow_ref_in_want)
18431844
strbuf_addstr(value, " ref-in-want");
18441845

1845-
if (git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
1846-
(!repo_config_get_bool(r,
1847-
"uploadpack.allowsidebandall",
1848-
&allow_sideband_all_value) &&
1849-
allow_sideband_all_value))
1846+
if (data.allow_sideband_all)
18501847
strbuf_addstr(value, " sideband-all");
18511848

1852-
if (!repo_config_get_string(r,
1853-
"uploadpack.blobpackfileuri",
1854-
&str) &&
1855-
str) {
1849+
if (data.allow_packfile_uris)
18561850
strbuf_addstr(value, " packfile-uris");
1857-
free(str);
1858-
}
18591851
}
18601852

1853+
upload_pack_data_clear(&data);
1854+
18611855
return 1;
18621856
}

0 commit comments

Comments
 (0)