remote-curl: supports git-upload-archive service

Add new service (git-upload-archive) support in remote-curl, so we can support remote archive over HTTP/HTTPS protocols. Differences between git-upload-archive and other services: 1. The git-archive program does not expect to see protocol version and capabilities when connecting to remote-helper, so do not send them in remote-curl for the git-upload-archive service. 2. We need to detect protocol version by calling discover_refs(). Fallback to use the git-upload-pack service (which, like git-upload-archive, is a read-only operation) to discover protocol version. 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 23b7d59a82ce39c0e08a4052de3be9ffbccd99b9
1 file changed +11 -3
remote-curl.c
+11 -3
@@ -1447,8 +1447,14 @@ static int stateless_connect(const char *service_name)
1447 * establish a stateless connection, otherwise we need to tell the
1448 * client to fallback to using other transport helper functions to
1449 * complete their request.
1450 + *
1451 + * The "git-upload-archive" service is a read-only operation. Fallback
1452 + * to use "git-upload-pack" service to discover protocol version.
1453 */
1451 - discover = discover_refs(service_name, 0);
1454 + if (!strcmp(service_name, "git-upload-archive"))
1455 + discover = discover_refs("git-upload-pack", 0);
1456 + else
1457 + discover = discover_refs(service_name, 0);
1458 if (discover->version != protocol_v2) {
1459 printf("fallback\n");
1460 fflush(stdout);
@@ -1486,9 +1492,11 @@ static int stateless_connect(const char *service_name)
1492
1493 /*
1494 * Dump the capability listing that we got from the server earlier
1489 - * during the info/refs request.
1495 + * during the info/refs request. This does not work with the
1496 + * "git-upload-archive" service.
1497 */
1491 - write_or_die(rpc.in, discover->buf, discover->len);
1498 + if (strcmp(service_name, "git-upload-archive"))
1499 + write_or_die(rpc.in, discover->buf, discover->len);
1500
1501 /* Until we see EOF keep sending POSTs */
1502 while (1) {