Skip to content

Commit 24f275a

Browse files
jiangxingitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jiang Xin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5c85836 commit 24f275a

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

http-backend.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ struct rpc_service {
3838
static struct rpc_service rpc_service[] = {
3939
{ "upload-pack", "uploadpack", 1, 1 },
4040
{ "receive-pack", "receivepack", 0, -1 },
41+
{ "upload-archive", "uploadarchive", 0, -1 },
4142
};
4243

4344
static struct string_list *get_parameters(void)
@@ -639,10 +640,15 @@ static void check_content_type(struct strbuf *hdr, const char *accepted_type)
639640

640641
static void service_rpc(struct strbuf *hdr, char *service_name)
641642
{
642-
const char *argv[] = {NULL, "--stateless-rpc", ".", NULL};
643+
struct strvec argv = STRVEC_INIT;
643644
struct rpc_service *svc = select_service(hdr, service_name);
644645
struct strbuf buf = STRBUF_INIT;
645646

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+
646652
strbuf_reset(&buf);
647653
strbuf_addf(&buf, "application/x-git-%s-request", svc->name);
648654
check_content_type(hdr, buf.buf);
@@ -655,9 +661,9 @@ static void service_rpc(struct strbuf *hdr, char *service_name)
655661

656662
end_headers(hdr);
657663

658-
argv[0] = svc->name;
659-
run_service(argv, svc->buffer_input);
664+
run_service(argv.v, svc->buffer_input);
660665
strbuf_release(&buf);
666+
strvec_clear(&argv);
661667
}
662668

663669
static int dead;
@@ -723,6 +729,7 @@ static struct service_cmd {
723729
{"GET", "/objects/pack/pack-[0-9a-f]{64}\\.idx$", get_idx_file},
724730

725731
{"POST", "/git-upload-pack$", service_rpc},
732+
{"POST", "/git-upload-archive$", service_rpc},
726733
{"POST", "/git-receive-pack$", service_rpc}
727734
};
728735

t/t5003-archive-zip.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,38 @@ check_zip with_untracked2
239239
check_added with_untracked2 untracked one/untracked
240240
check_added with_untracked2 untracked two/untracked
241241

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+
242276
test_done

0 commit comments

Comments
 (0)