From patchwork Wed Sep 12 05:35:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 10596721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5619113B8 for ; Wed, 12 Sep 2018 05:35:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 460BC2978A for ; Wed, 12 Sep 2018 05:35:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39C8B297C3; Wed, 12 Sep 2018 05:35:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D517A2978A for ; Wed, 12 Sep 2018 05:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726642AbeILKik (ORCPT ); Wed, 12 Sep 2018 06:38:40 -0400 Received: from mail-io0-f202.google.com ([209.85.223.202]:52673 "EHLO mail-io0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726412AbeILKik (ORCPT ); Wed, 12 Sep 2018 06:38:40 -0400 Received: by mail-io0-f202.google.com with SMTP id q20-v6so731852iod.19 for ; Tue, 11 Sep 2018 22:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=IHLxS4eMXxQw61VL6+yOdkd1SBJvUnvugKBMTIcGv8w=; b=eH+DRMldXEBkPSGYsQz/6tEEYFf+Cj4smYMFqIW+0/mu3Wz05BCk64cdA4qdAvMGBg NLthF+iyUahCp2DeqUGgXl731fSKGh4lMO+wTND1eQeHcelCgs5+C5JJVI52lnVHjwpb HZJ9SfoQj0WAdyQL5RhF1BrP888DYY6E8tuycWe8SrgIdFyt3xbYodr9l0nTTxJVUw19 Gz4Xnlq+OEeEv+KDj1bhelXx6zaTHgnMRPI+glqkyRDElgp+/BRRUiowHTJT1jmwVqsw k1k3nRugWbxfEz6yfFXDsGw7RG84O7cPYL5HpTLP5nj0vqNz26yLMkR9BDH58hUQsyPf iu7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=IHLxS4eMXxQw61VL6+yOdkd1SBJvUnvugKBMTIcGv8w=; b=GzC1j3Sn5UhMma2hfy+6QjKuyCASs64LFTX3lXCuWwjCrwV7GddCJRpYZPe0PaayH6 RvQz4ZPXUUX523/7JtGJUCBinrWRNlYTwlFRJ5nVSFhri6u70rmqaOgzQ4WlNMwkI2vK Upvd6PnSKFzUC5IHIKUb1AWUaZepcf9zJmmi/O5FHjZGA2lSmY/H2XZqhZ87ku0ybuTG kmEpW905OFKlkv2MVtCq4xcAfpWmO0G8Ft78/JPWpV0qXuJNmhdANbl2Q17Nq+kRpLpb E0U/fzKJuK4j+QrMDeQOl3dyZjMBbbEMx2qDXyzoKTx8ToFe4aFW8X6WNFBSAciv2QEr 6HcA== X-Gm-Message-State: APzg51Dqs/+RM0trx81YpTPx7Fk7RGaZh6M6lCLUR+9T7g69W3jEFUSH ie4hEuxnL8Ld4XDI9v/sJD0yswFtUBOMITdSIeR5n904TypuRJ3424rAmcrqzK/luZr7AGlP5oj OeIYy9bUdrwVGmq8H7K3jQ4389brVzlE2pC+pbAxkvX3wrkjqt+mMKItvqFnu51U= X-Google-Smtp-Source: ANB0VdYwtu6tYUjkZykPD3xCPCMwwQwxxncUq6i8rY2VC4QXiWpyQQnMaBOmqjfvXxAcmqJlNpH4Nxyz5vjCuA== X-Received: by 2002:a6b:de0e:: with SMTP id v14-v6mr127329iog.34.1536730549994; Tue, 11 Sep 2018 22:35:49 -0700 (PDT) Date: Tue, 11 Sep 2018 22:35:17 -0700 In-Reply-To: <20180912053519.31085-1-steadmon@google.com> Message-Id: <20180912053519.31085-2-steadmon@google.com> Mime-Version: 1.0 References: <20180912053519.31085-1-steadmon@google.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog Subject: [PATCH 1/3] archive: use packet_reader for communications From: Josh Steadmon To: git@vger.kernel.org Cc: jrnieder@gmail.com, gitster@pobox.com, l.s.r@web.de, sandals@crustytoothpaste.net, Josh Steadmon Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using packet_reader will simplify version detection and capability handling, which will make implementation of protocol v2 support in git-archive easier. Signed-off-by: Josh Steadmon Reviewed-by: Stefan Beller --- builtin/archive.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/builtin/archive.c b/builtin/archive.c index e74f67539..e54fc39ad 100644 --- a/builtin/archive.c +++ b/builtin/archive.c @@ -27,10 +27,11 @@ static int run_remote_archiver(int argc, const char **argv, const char *remote, const char *exec, const char *name_hint) { - char *buf; int fd[2], i, rv; struct transport *transport; struct remote *_remote; + struct packet_reader reader; + enum packet_read_status status; _remote = remote_get(remote); if (!_remote->url[0]) @@ -38,6 +39,8 @@ static int run_remote_archiver(int argc, const char **argv, transport = transport_get(_remote, _remote->url[0]); transport_connect(transport, "git-upload-archive", exec, fd); + packet_reader_init(&reader, fd[0], NULL, 0, PACKET_READ_CHOMP_NEWLINE); + /* * Inject a fake --format field at the beginning of the * arguments, with the format inferred from our output @@ -53,18 +56,20 @@ static int run_remote_archiver(int argc, const char **argv, packet_write_fmt(fd[1], "argument %s\n", argv[i]); packet_flush(fd[1]); - buf = packet_read_line(fd[0], NULL); - if (!buf) + status = packet_reader_read(&reader); + + if (status == PACKET_READ_FLUSH) die(_("git archive: expected ACK/NAK, got a flush packet")); - if (strcmp(buf, "ACK")) { - if (starts_with(buf, "NACK ")) - die(_("git archive: NACK %s"), buf + 5); - if (starts_with(buf, "ERR ")) - die(_("remote error: %s"), buf + 4); + if (strcmp(reader.buffer, "ACK")) { + if (starts_with(reader.buffer, "NACK ")) + die(_("git archive: NACK %s"), reader.buffer + 5); + if (starts_with(reader.buffer, "ERR ")) + die(_("remote error: %s"), reader.buffer + 4); die(_("git archive: protocol error")); } - if (packet_read_line(fd[0], NULL)) + status = packet_reader_read(&reader); + if (status != PACKET_READ_FLUSH) die(_("git archive: expected a flush")); /* Now, start reading from fd[0] and spit it out to stdout */ From patchwork Wed Sep 12 05:35:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 10596723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 272F813B8 for ; Wed, 12 Sep 2018 05:36:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 144AC2978A for ; Wed, 12 Sep 2018 05:36:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08A23297D8; Wed, 12 Sep 2018 05:36:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DFF62978A for ; Wed, 12 Sep 2018 05:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726906AbeILKiu (ORCPT ); Wed, 12 Sep 2018 06:38:50 -0400 Received: from mail-io0-f201.google.com ([209.85.223.201]:56647 "EHLO mail-io0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726712AbeILKiu (ORCPT ); Wed, 12 Sep 2018 06:38:50 -0400 Received: by mail-io0-f201.google.com with SMTP id o18-v6so709149ioh.23 for ; Tue, 11 Sep 2018 22:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=L5LVJHoAgnqJTAP9InpoukGIymju3Vxaq3r02Q8FMqk=; b=SkcyPxnZCDL9P4ku1FURz5Qz1owQQJ/snMlxK7pOyKPYoGO/hphQJXLKViY3bJZIOn g4NoXRrQM/F/cGjjI6XU00nQpvIsPNkW+YJhzWFrNjn+ViCGfe+UE16EzE8V+LKjebPX 0A/1uT99jTwOxVx/EhgwtdGVM9kxWI7062g1JWrQ4Tsdnr61atfKCZf0vU0onBsvua2f RcuMWPgP+Uvdk5YDDEh2wlHIZVl6fOfOTL523wBvaD2M6MQ8L7l4rDWA0iGnBU+/+Gt5 SDTdt/4KAYq14vqv4vi6Y/+o3GHWx/7MrLHB8yntLRBBRWzgfno30v2PRPXeBvV5d5fH MgwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=L5LVJHoAgnqJTAP9InpoukGIymju3Vxaq3r02Q8FMqk=; b=Zor7jMGAY5G6tLYyW7LWfqMV0jAkOvFbkzcsNcJs42NtRpkDl0GKmuwwW8TIKlYzu2 ZG9wMpp/wJjKzrhgv+xFpIOaqDwcPTP8i42vrc+2a+7wO6BKMHZ9kj8Ittt9BLZCR8S8 1rE6aqCwEs230JALwqM8zcGBfqCiWVo44I+fGfcXXtusOzTzG7kAzfdqWUlnHG470Wxk 4zpNB4zEsrB/G3lsqMsVMYUQoOlOrDjJCDUX7Hv0YFjrbJqxQacCpW2fmUo2JfDKURZK o9OaL4odMb3Ypkx75exzena5Em+1zfdaSh04LOisc67NPe48Zhh8UPqn5IWkM152zeBw cT2w== X-Gm-Message-State: APzg51DOpjRXyTjxZMJXjWCyV/9sKhtaImGrlzgCPIQQhEecBkNTju+Z b+BOI9a5bAcu5tAIksAFLVZv8KieQkGOE18MUj7yDvyf3zhCn3zbfEpuWHmY6X4dH6Dbe7kyd1P CiQc2NQpdgnfBpKvYl/V4aHTt6NeFqnAg01pyNGKecKB6m/Q6awX3SpXBChAg9Ys= X-Google-Smtp-Source: ANB0VdZQF5ubhyRSh5E0TYEZJ9xE1qRTCk1gWv+th/kgQpF2hUQFMOQ/EbWKdQR20TOHyQDLgXUvyJFeT7ohAA== X-Received: by 2002:a24:f902:: with SMTP id l2-v6mr411395ith.4.1536730559523; Tue, 11 Sep 2018 22:35:59 -0700 (PDT) Date: Tue, 11 Sep 2018 22:35:18 -0700 In-Reply-To: <20180912053519.31085-1-steadmon@google.com> Message-Id: <20180912053519.31085-3-steadmon@google.com> Mime-Version: 1.0 References: <20180912053519.31085-1-steadmon@google.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog Subject: [PATCH 2/3] archive: implement protocol v2 archive command From: Josh Steadmon To: git@vger.kernel.org Cc: jrnieder@gmail.com, gitster@pobox.com, l.s.r@web.de, sandals@crustytoothpaste.net, Josh Steadmon Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds a new archive command for protocol v2. The command expects arguments in the form "argument X" which are passed unmodified to git-upload-archive--writer. This command works over the file://, Git, and SSH transports. HTTP support will be added in a separate patch. Signed-off-by: Josh Steadmon --- builtin/archive.c | 45 +++++++++++++++++++++++++++------------- builtin/upload-archive.c | 44 ++++++++++++++++++++++++++++++++++++--- t/t5000-tar-tree.sh | 5 +++++ 3 files changed, 77 insertions(+), 17 deletions(-) diff --git a/builtin/archive.c b/builtin/archive.c index e54fc39ad..73831887d 100644 --- a/builtin/archive.c +++ b/builtin/archive.c @@ -5,9 +5,11 @@ #include "cache.h" #include "builtin.h" #include "archive.h" +#include "connect.h" #include "transport.h" #include "parse-options.h" #include "pkt-line.h" +#include "protocol.h" #include "sideband.h" static void create_output_file(const char *output_file) @@ -23,6 +25,13 @@ static void create_output_file(const char *output_file) } } +static int do_v2_command_and_cap(int out) +{ + packet_write_fmt(out, "command=archive\n"); + /* Capability list would go here, if we had any. */ + packet_delim(out); +} + static int run_remote_archiver(int argc, const char **argv, const char *remote, const char *exec, const char *name_hint) @@ -32,6 +41,7 @@ static int run_remote_archiver(int argc, const char **argv, struct remote *_remote; struct packet_reader reader; enum packet_read_status status; + enum protocol_version version; _remote = remote_get(remote); if (!_remote->url[0]) @@ -41,6 +51,11 @@ static int run_remote_archiver(int argc, const char **argv, packet_reader_init(&reader, fd[0], NULL, 0, PACKET_READ_CHOMP_NEWLINE); + version = discover_version(&reader); + + if (version == protocol_v2) + do_v2_command_and_cap(fd[1]); + /* * Inject a fake --format field at the beginning of the * arguments, with the format inferred from our output @@ -56,22 +71,24 @@ static int run_remote_archiver(int argc, const char **argv, packet_write_fmt(fd[1], "argument %s\n", argv[i]); packet_flush(fd[1]); - status = packet_reader_read(&reader); - - if (status == PACKET_READ_FLUSH) - die(_("git archive: expected ACK/NAK, got a flush packet")); - if (strcmp(reader.buffer, "ACK")) { - if (starts_with(reader.buffer, "NACK ")) - die(_("git archive: NACK %s"), reader.buffer + 5); - if (starts_with(reader.buffer, "ERR ")) - die(_("remote error: %s"), reader.buffer + 4); - die(_("git archive: protocol error")); + if (version == protocol_v0) { + status = packet_reader_read(&reader); + + if (status == PACKET_READ_FLUSH) + die(_("git archive: expected ACK/NAK, got a flush packet")); + if (strcmp(reader.buffer, "ACK")) { + if (starts_with(reader.buffer, "NACK ")) + die(_("git archive: NACK %s"), reader.buffer + 5); + if (starts_with(reader.buffer, "ERR ")) + die(_("remote error: %s"), reader.buffer + 4); + die(_("git archive: protocol error")); + } + + status = packet_reader_read(&reader); + if (status != PACKET_READ_FLUSH) + die(_("git archive: expected a flush")); } - status = packet_reader_read(&reader); - if (status != PACKET_READ_FLUSH) - die(_("git archive: expected a flush")); - /* Now, start reading from fd[0] and spit it out to stdout */ rv = recv_sideband("archive", fd[0], 1); rv |= transport_disconnect(transport); diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index 25d911635..534e8fd56 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -5,6 +5,7 @@ #include "builtin.h" #include "archive.h" #include "pkt-line.h" +#include "protocol.h" #include "sideband.h" #include "run-command.h" #include "argv-array.h" @@ -73,13 +74,53 @@ static ssize_t process_input(int child_fd, int band) return sz; } +static int handle_v2_command_and_cap(void) +{ + struct packet_reader reader; + enum packet_read_status status; + + packet_reader_init(&reader, 0, NULL, 0, PACKET_READ_CHOMP_NEWLINE); + + packet_write_fmt(1, "version 2\n"); + /* + * We don't currently send any capabilities, but maybe we could list + * supported archival formats? + */ + packet_flush(1); + + status = packet_reader_read(&reader); + if (status != PACKET_READ_NORMAL || + strcmp(reader.buffer, "command=archive")) + die(_("upload-archive: expected command=archive")); + while (status == PACKET_READ_NORMAL) { + /* We don't currently expect any client capabilities, but we + * should still read (and ignore) any that happen to get sent. + */ + status = packet_reader_read(&reader); + } + if (status != PACKET_READ_DELIM) + die(_("upload-archive: expected delim packet")); + + /* Let git-upload-archive--writer handle the arguments. */ + + return 0; +} + int cmd_upload_archive(int argc, const char **argv, const char *prefix) { struct child_process writer = { argv }; + enum protocol_version version = determine_protocol_version_server(); if (argc == 2 && !strcmp(argv[1], "-h")) usage(upload_archive_usage); + if (version == protocol_v2) + handle_v2_command_and_cap(); + else { + packet_write_fmt(1, "ACK\n"); + packet_flush(1); + } + /* * Set up sideband subprocess. * @@ -96,9 +137,6 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix) die("upload-archive: %s", strerror(err)); } - packet_write_fmt(1, "ACK\n"); - packet_flush(1); - while (1) { struct pollfd pfd[2]; diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 2a97b27b0..4be74d6e9 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -145,6 +145,11 @@ test_expect_success \ check_tar b +test_expect_success 'protocol v2 for remote' ' + GIT_PROTOCOL="version=2" git archive --remote=. HEAD >v2_remote.tar +' +check_tar v2_remote + test_expect_success 'git archive --prefix=prefix/' ' git archive --prefix=prefix/ HEAD >with_prefix.tar ' From patchwork Wed Sep 12 05:35:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 10596725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB87814E0 for ; Wed, 12 Sep 2018 05:36:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9AAE2978A for ; Wed, 12 Sep 2018 05:36:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDFD1297C3; Wed, 12 Sep 2018 05:36:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98D6E297C2 for ; Wed, 12 Sep 2018 05:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726919AbeILKix (ORCPT ); Wed, 12 Sep 2018 06:38:53 -0400 Received: from mail-qt0-f202.google.com ([209.85.216.202]:45571 "EHLO mail-qt0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726712AbeILKix (ORCPT ); Wed, 12 Sep 2018 06:38:53 -0400 Received: by mail-qt0-f202.google.com with SMTP id u45-v6so678468qte.12 for ; Tue, 11 Sep 2018 22:36:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=g4+TvSFNSNYoL0aBVKum343Cm1LNB1BVZsk1WdhawnA=; b=iRBKlzH3xJ8EZJve+O2N/X9j71c8B1w9mtE7R+Wl5xW4q33xO3LTrhCMfj3xbNuKv8 gHTuu7hITkrSj3Edl008LmYVAo+upjiwBiJ7bdIdJBEzxLDWwHF1Jrmzve3eRqSXc50Q ugP7+7WornSrMA8eUAXBbBgYalWSrHQ8+c4ryB1XYvBrcv4ZUe+gdWanr/N3ppfhV2ha 4jXwFbQkydGGl/cG4TTNAcgLSRVBDdpd0419MOrwOHqcili1m5XC1dR2/m7oPzL4LfLX VblhYmk5mnm01r/C2ThbJOuQHA+ALCtFPAyG/zKbL5U+lytjaGe+LLuPx0qCvTMbryvl dWXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=g4+TvSFNSNYoL0aBVKum343Cm1LNB1BVZsk1WdhawnA=; b=KjQHPLcwPjme3mKCkHlI7h3SqJ9h+cliXT77G58Ib+PWuVtIk+n+Z0KsmFPQpUZ/lL GHsQi2AKGXaeO06r2IBCRUxguN9ofS3zKtRZosiZgwK6/LntUbkH9Ke+FoigsZvJuwNf IsZAZzuR+JXCmdm+lL+sDxG1Z0zSJaJ0fQeky7x7l7SQM7xPJTci61dLtU5yprPFn1Q6 4WM0ItwqJGJwmRwGZkFXY1jAEOrFAjZ/Gry/2zB/qkvk7ypzeqMy0tcwAG+/HVfq3QK0 TZEQafJFnExMD/T71SNPu63509vWcoc69hvfLa1VETw4WgeR4MBrRE7MgjGDZlNIlivR O7ww== X-Gm-Message-State: APzg51A2n5DiTAdKtKtdrl6aFvNjOQfy0G2B7OxI09ObNMB+nrGsaOpV WRbz0wbzQeUqOevkRbO+RXyeB/BD3MJj5AQs/zEXKtrlIGP/Exg4PqAI5BZKNbu/u84YhH9Eca7 E5dkPhQyhBPKwQ5sSubnXecVEzdWYbOFKgYtrIYCRWLEVdxmhu3TFcBCYECOKUsU= X-Google-Smtp-Source: ANB0VdZGsRxMMAyVWXsiyqKbLpwD0HdBrsr/Q+6J5n1JR9nAZxoVqaAv6sZnl4CCthj4pFokFWgftUEtCwAKhg== X-Received: by 2002:a0c:86d7:: with SMTP id 23-v6mr60875qvg.44.1536730562953; Tue, 11 Sep 2018 22:36:02 -0700 (PDT) Date: Tue, 11 Sep 2018 22:35:19 -0700 In-Reply-To: <20180912053519.31085-1-steadmon@google.com> Message-Id: <20180912053519.31085-4-steadmon@google.com> Mime-Version: 1.0 References: <20180912053519.31085-1-steadmon@google.com> X-Mailer: git-send-email 2.19.0.397.gdd90340f6a-goog Subject: [PATCH 3/3] archive: allow archive over HTTP(S) with proto v2 From: Josh Steadmon To: git@vger.kernel.org Cc: jrnieder@gmail.com, gitster@pobox.com, l.s.r@web.de, sandals@crustytoothpaste.net, Josh Steadmon Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Josh Steadmon --- builtin/archive.c | 8 +++++++- http-backend.c | 10 +++++++++- transport-helper.c | 5 +++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/builtin/archive.c b/builtin/archive.c index 73831887d..5fa75b3f7 100644 --- a/builtin/archive.c +++ b/builtin/archive.c @@ -87,7 +87,13 @@ static int run_remote_archiver(int argc, const char **argv, status = packet_reader_read(&reader); if (status != PACKET_READ_FLUSH) die(_("git archive: expected a flush")); - } + } else if (version == protocol_v2 && + starts_with(transport->url, "http")) + /* + * Commands over HTTP require two requests, so there's an + * additional server response to parse. + */ + discover_version(&reader); /* Now, start reading from fd[0] and spit it out to stdout */ rv = recv_sideband("archive", fd[0], 1); diff --git a/http-backend.c b/http-backend.c index 458642ef7..d62d583c7 100644 --- a/http-backend.c +++ b/http-backend.c @@ -32,6 +32,7 @@ struct rpc_service { static struct rpc_service rpc_service[] = { { "upload-pack", "uploadpack", 1, 1 }, { "receive-pack", "receivepack", 0, -1 }, + { "upload-archive", "uploadarchive", 1, 1 }, }; static struct string_list *get_parameters(void) @@ -637,6 +638,12 @@ static void service_rpc(struct strbuf *hdr, char *service_name) struct rpc_service *svc = select_service(hdr, service_name); struct strbuf buf = STRBUF_INIT; + if (!strcmp(service_name, "git-upload-archive")) { + /* git-upload-archive doesn't need --stateless-rpc */ + argv[1] = "."; + argv[2] = NULL; + } + strbuf_reset(&buf); strbuf_addf(&buf, "application/x-git-%s-request", svc->name); check_content_type(hdr, buf.buf); @@ -713,7 +720,8 @@ static struct service_cmd { {"GET", "/objects/pack/pack-[0-9a-f]{40}\\.idx$", get_idx_file}, {"POST", "/git-upload-pack$", service_rpc}, - {"POST", "/git-receive-pack$", service_rpc} + {"POST", "/git-receive-pack$", service_rpc}, + {"POST", "/git-upload-archive$", service_rpc}, }; static int bad_request(struct strbuf *hdr, const struct service_cmd *c) diff --git a/transport-helper.c b/transport-helper.c index 143ca008c..b4b96fc89 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -605,7 +605,8 @@ static int process_connect_service(struct transport *transport, ret = run_connect(transport, &cmdbuf); } else if (data->stateless_connect && (get_protocol_version_config() == protocol_v2) && - !strcmp("git-upload-pack", name)) { + (!strcmp("git-upload-pack", name) || + !strcmp("git-upload-archive", name))) { strbuf_addf(&cmdbuf, "stateless-connect %s\n", name); ret = run_connect(transport, &cmdbuf); if (ret) @@ -639,7 +640,7 @@ static int connect_helper(struct transport *transport, const char *name, /* Get_helper so connect is inited. */ get_helper(transport); - if (!data->connect) + if (!data->connect && !data->stateless_connect) die(_("operation not supported by protocol")); if (!process_connect_service(transport, name, exec))