http-backend: new rpc-service for git-upload-archive
Add new rpc-service "upload-archive" in http-backend to add server side support for remote archive over HTTP/HTTPS protocols. Also add new test cases in t5003. In the test case "archive remote http repository", git-archive exits with a non-0 exit code even though we create the archive correctly. It will be fixed in a later commit. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jiang Xin committed
Jan 21, 2024 at 21:15 UTC
24f275ab33cd06f399a87a8384443e74da5f3545
2 files changed
+44
-3
http-backend.c
+10
-3
@@ -38,6 +38,7 @@ struct rpc_service {
38
static struct rpc_service rpc_service[] = {
39
{ "upload-pack", "uploadpack", 1, 1 },
40
{ "receive-pack", "receivepack", 0, -1 },
41
+ { "upload-archive", "uploadarchive", 0, -1 },
42
};
43
44
static struct string_list *get_parameters(void)
@@ -639,10 +640,15 @@ static void check_content_type(struct strbuf *hdr, const char *accepted_type)
640
641
static void service_rpc(struct strbuf *hdr, char *service_name)
642
{
642
- const char *argv[] = {NULL, "--stateless-rpc", ".", NULL};
643
+ struct strvec argv = STRVEC_INIT;
644
struct rpc_service *svc = select_service(hdr, service_name);
645
struct strbuf buf = STRBUF_INIT;
646
647
+ strvec_push(&argv, svc->name);
648
+ if (strcmp(service_name, "git-upload-archive"))
649
+ strvec_push(&argv, "--stateless-rpc");
650
+ strvec_push(&argv, ".");
651
+
652
strbuf_reset(&buf);
653
strbuf_addf(&buf, "application/x-git-%s-request", svc->name);
654
check_content_type(hdr, buf.buf);
@@ -655,9 +661,9 @@ static void service_rpc(struct strbuf *hdr, char *service_name)
661
662
end_headers(hdr);
663
658
- argv[0] = svc->name;
659
- run_service(argv, svc->buffer_input);
664
+ run_service(argv.v, svc->buffer_input);
665
strbuf_release(&buf);
666
+ strvec_clear(&argv);
667
}
668
669
static int dead;
@@ -723,6 +729,7 @@ static struct service_cmd {
729
{"GET", "/objects/pack/pack-[0-9a-f]{64}\\.idx$", get_idx_file},
730
731
{"POST", "/git-upload-pack$", service_rpc},
732
+ {"POST", "/git-upload-archive$", service_rpc},
733
{"POST", "/git-receive-pack$", service_rpc}
734
};
735
t/t5003-archive-zip.sh
+34
@@ -239,4 +239,38 @@ check_zip with_untracked2
239
check_added with_untracked2 untracked one/untracked
240
check_added with_untracked2 untracked two/untracked
241
242
+# Test remote archive over HTTP protocol.
243
+#
244
+# Note: this should be the last part of this test suite, because
245
+# by including lib-httpd.sh, the test may end early if httpd tests
246
+# should not be run.
247
+#
248
+. "$TEST_DIRECTORY"/lib-httpd.sh
249
+start_httpd
250
+
251
+test_expect_success "setup for HTTP protocol" '
252
+ cp -R bare.git "$HTTPD_DOCUMENT_ROOT_PATH/bare.git" &&
253
+ git -C "$HTTPD_DOCUMENT_ROOT_PATH/bare.git" \
254
+ config http.uploadpack true &&
255
+ set_askpass user@host pass@host
256
+'
257
+
258
+setup_askpass_helper
259
+
260
+test_expect_success 'remote archive does not work with protocol v1' '
261
+ test_must_fail git -c protocol.version=1 archive \
262
+ --remote="$HTTPD_URL/auth/smart/bare.git" \
263
+ --output=remote-http.zip HEAD >actual 2>&1 &&
264
+ cat >expect <<-EOF &&
265
+ fatal: can${SQ}t connect to subservice git-upload-archive
266
+ EOF
267
+ test_cmp expect actual
268
+'
269
+
270
+test_expect_success 'archive remote http repository' '
271
+ test_must_fail git archive --remote="$HTTPD_URL/auth/smart/bare.git" \
272
+ --output=remote-http.zip HEAD &&
273
+ test_cmp_bin d.zip remote-http.zip
274
+'
275
+
276
test_done