From patchwork Mon Dec 17 22:40:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10734375 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 32E1B6C5 for ; Mon, 17 Dec 2018 22:41:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2398A2A5B8 for ; Mon, 17 Dec 2018 22:41:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21D002A5C2; Mon, 17 Dec 2018 22:41:11 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 D68D72A5C3 for ; Mon, 17 Dec 2018 22:41:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731844AbeLQWlJ (ORCPT ); Mon, 17 Dec 2018 17:41:09 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45717 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727090AbeLQWlI (ORCPT ); Mon, 17 Dec 2018 17:41:08 -0500 Received: by mail-wr1-f66.google.com with SMTP id t6so13771872wrr.12 for ; Mon, 17 Dec 2018 14:41:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WmPR5RI9HWW3UWfWbpBrlr6Z1MuUnA7PG0jrOVzdn1s=; b=HGzo8GvAoAUhTdgJEQLCohVzSQfghrCWec5yVBf8Q14WHEfZc+mQPkfP72AMzCw78d Xv6A1oy1m5v7nYRI0fCrdHxBaXp0eJu0ERJHtx2mW1VQ1JOVu1JnhWWLEe8pv+G9mc5d Am4lx1NQfCjq5ijo0XwiPnkupU9UXdx8BdBe6AYCURs6fsdW1pnVg0pHKcZwgjjtkm6n 7vzsbOZwaQpsnkMw/DZXfHVxnXhOTs1jdz4/6PQUIKurcn13CqexZl3YfLGe8dFrtK3+ RpKn1mEqhYLsPbA160HYeLWopXXWZnCqmIgArQfWWQOrrAH68ZDduNYTjhArRRPpvlUl MaWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WmPR5RI9HWW3UWfWbpBrlr6Z1MuUnA7PG0jrOVzdn1s=; b=pk7AKuPwlwokZwmL9KPFJ1Z70dv/5CxgxByYybGg1ZOcY9bKyy3+I6QPRurTHDoTAa 1vYkwqPGnnnYaVgYzFyn3g7eicTtWXM24zMGDMIExz1HiuNhbeiQDZWv3SMv+VNFdlaq KcAtImToDseHuCk4MIthJMiB2qWGpuljBhy+VBo0aHqL+y3Pk5kGwX0I9uOf+U3AdHbQ oYBT1GL10dBiXMCy6uCkAwmsPwZRt+7jW28g5xq8J6pL5fcXGzp0YhvFTNm4LNPeX+M/ RDfn24sMgH+8Gzi36WDuTjiEbMy6BtRXJpz7gXz1SGAURDoPoyQuEqhajretD3a+UNTd R24Q== X-Gm-Message-State: AA+aEWYWuGOtxhtn58MnBny2JaYsdoKy9O/UvtaDRFjPbTyWh/F5Rv31 TWzrx6p3HQ7/azShO5p1Ku/1wdnV/ow= X-Google-Smtp-Source: AFSGD/XjGnzxtkKD90fUrCUIyzvUt5k/hrZVBx40ysEyi1FIBYMTePvFYvXJtoCWxgp2zcPZ0iKw6Q== X-Received: by 2002:adf:ef0d:: with SMTP id e13mr6787130wro.29.1545086466038; Mon, 17 Dec 2018 14:41:06 -0800 (PST) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c7sm2208199wre.64.2018.12.17.14.41.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Dec 2018 14:41:05 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Brandon Williams , Jonathan Tan , Josh Steadmon , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 1/4] serve: pass "config context" through to individual commands Date: Mon, 17 Dec 2018 23:40:51 +0100 Message-Id: <20181217224054.4376-2-avarab@gmail.com> X-Mailer: git-send-email 2.20.0.405.gbc1bbc6f85 In-Reply-To: <20181213155817.27666-1-avarab@gmail.com> References: <20181213155817.27666-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff King In protocol v2, instead of just running "upload-pack", we have a generic "serve" loop which runs command requests from the client. What used to be "upload-pack" is now generally split into two operations: "ls-refs" and "fetch". The latter knows it must respect uploadpack.* config, but the former is not actually specific to a fetch operation (we do not yet do v2 receive-pack, but eventually we may, and ls-refs would support both operations). However, ls-refs does need to know which operation we're performing, in order to read the correct config (e.g., uploadpack.hiderefs versus receive.hiderefs; we don't read _either_ right now, but this is the first step to fixing that). In the generic "git-serve" program, we don't have that information. But in the protocol as it is actually used by clients, the client still asks to run "git-upload-pack", and then issues an "ls-refs" from there. So we _do_ know at that point that "uploadpack" is the right config context. This patch teaches the protocol v2 "serve" code to pass that context through to the individual commands (a future patch will teach ls-refs to actually use it). Signed-off-by: Jeff King Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/upload-pack.c | 1 + ls-refs.c | 4 +++- ls-refs.h | 3 ++- serve.c | 9 +++++---- serve.h | 7 +++++++ upload-pack.c | 4 ++-- upload-pack.h | 4 ++-- 7 files changed, 22 insertions(+), 10 deletions(-) diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c index 42dc4da5a1f..67192cfa9e9 100644 --- a/builtin/upload-pack.c +++ b/builtin/upload-pack.c @@ -52,6 +52,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix) case protocol_v2: serve_opts.advertise_capabilities = opts.advertise_refs; serve_opts.stateless_rpc = opts.stateless_rpc; + serve_opts.config_context = "uploadpack"; serve(&serve_opts); break; case protocol_v1: diff --git a/ls-refs.c b/ls-refs.c index a06f12eca8d..e8e31475f06 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -69,7 +69,9 @@ static int send_ref(const char *refname, const struct object_id *oid, return 0; } -int ls_refs(struct repository *r, struct argv_array *keys, +int ls_refs(struct repository *r, + const char *config_section, + struct argv_array *keys, struct packet_reader *request) { struct ls_refs_data data; diff --git a/ls-refs.h b/ls-refs.h index b62877e8dad..da26fc9824d 100644 --- a/ls-refs.h +++ b/ls-refs.h @@ -4,7 +4,8 @@ struct repository; struct argv_array; struct packet_reader; -extern int ls_refs(struct repository *r, struct argv_array *keys, +extern int ls_refs(struct repository *r, const char *config_context, + struct argv_array *keys, struct packet_reader *request); #endif /* LS_REFS_H */ diff --git a/serve.c b/serve.c index bda085f09c8..70f89cf0d98 100644 --- a/serve.c +++ b/serve.c @@ -48,6 +48,7 @@ struct protocol_capability { * This field should be NULL for capabilities which are not commands. */ int (*command)(struct repository *r, + const char *config_context, struct argv_array *keys, struct packet_reader *request); }; @@ -158,7 +159,7 @@ enum request_state { PROCESS_REQUEST_DONE, }; -static int process_request(void) +static int process_request(struct serve_options *opts) { enum request_state state = PROCESS_REQUEST_KEYS; struct packet_reader reader; @@ -222,7 +223,7 @@ static int process_request(void) if (!command) die("no command requested"); - command->command(the_repository, &keys, &reader); + command->command(the_repository, opts->config_context, &keys, &reader); argv_array_clear(&keys); return 0; @@ -249,10 +250,10 @@ void serve(struct serve_options *options) * a single request/response exchange */ if (options->stateless_rpc) { - process_request(); + process_request(options); } else { for (;;) - if (process_request()) + if (process_request(options)) break; } } diff --git a/serve.h b/serve.h index fe65ba9f469..d527224cbb1 100644 --- a/serve.h +++ b/serve.h @@ -8,6 +8,13 @@ extern int has_capability(const struct argv_array *keys, const char *capability, struct serve_options { unsigned advertise_capabilities; unsigned stateless_rpc; + + /* + * Some operations may need to know the context when looking up config; + * e.g., set this to "uploadpack" to respect "uploadpack.hiderefs" (as + * opposed to "receive.hiderefs"). + */ + const char *config_context; }; #define SERVE_OPTIONS_INIT { 0 } extern void serve(struct serve_options *options); diff --git a/upload-pack.c b/upload-pack.c index 5e81f1ff24f..914bbb40bcd 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1413,8 +1413,8 @@ enum fetch_state { FETCH_DONE, }; -int upload_pack_v2(struct repository *r, struct argv_array *keys, - struct packet_reader *request) +int upload_pack_v2(struct repository *r, const char *config_context, + struct argv_array *keys, struct packet_reader *request) { enum fetch_state state = FETCH_PROCESS_ARGS; struct upload_pack_data data; diff --git a/upload-pack.h b/upload-pack.h index cab2178796a..2a9f51197c4 100644 --- a/upload-pack.h +++ b/upload-pack.h @@ -13,8 +13,8 @@ void upload_pack(struct upload_pack_options *options); struct repository; struct argv_array; struct packet_reader; -extern int upload_pack_v2(struct repository *r, struct argv_array *keys, - struct packet_reader *request); +extern int upload_pack_v2(struct repository *r, const char *config_context, + struct argv_array *keys, struct packet_reader *request); struct strbuf; extern int upload_pack_advertise(struct repository *r, From patchwork Mon Dec 17 22:40:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10734379 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 5F66C1399 for ; Mon, 17 Dec 2018 22:41:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 527282A5BE for ; Mon, 17 Dec 2018 22:41:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50AE22A57E; Mon, 17 Dec 2018 22:41: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 ECF652A57E for ; Mon, 17 Dec 2018 22:41:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731936AbeLQWlL (ORCPT ); Mon, 17 Dec 2018 17:41:11 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43534 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728174AbeLQWlJ (ORCPT ); Mon, 17 Dec 2018 17:41:09 -0500 Received: by mail-wr1-f67.google.com with SMTP id r10so13934307wrs.10 for ; Mon, 17 Dec 2018 14:41:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OJIJdNVYTbkpMxJjwk+oc86pN56sgdcljZ13MIhBGIE=; b=AKTSvvrVB7kjpHE0F14qLlPA1znA2MzOJcG3V6kXtoht69aVD1gPecdQvBbSPepqDB A0LqAtz2w5qTAxxEnR/fAMt7N58v7cfRdKTZhzqYp8v+ApgO11ubRkMRPtwEB279knql WJhy1E3f7O9PmzBIZ7W/sflVwz/MFwb5obo7gunIpRKFBDkSi0IL48s9X88Ft5KYMGLw mv9Frm0y+sbwW0IoZ5an3lstPmQnrQGbKqmJA2LL2nGlw5YYeK8voFJgIckNdjewLRnq EMtBvf0kDiG2C2X0ZbB6dARwA8BHeMuMJc9GxjV8myOfkfvDTN4XwDNjegaNA1OpB745 W8jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OJIJdNVYTbkpMxJjwk+oc86pN56sgdcljZ13MIhBGIE=; b=pQCg/y66uRolcnavnR3TAwI5p1Q1JqpcI5bCjKvdGhZNMotxykqaZByiMliOgZqfKJ h2sEnxKQX50o5+difYQMcIlswmiwiMIiSFkNv+xqM1CJ7Xiwb1don8f3jSQE09XQIa0Q DZfp459W+4TBve5aMnaO04rj5N2uNzn60DiQRMV5n7CJfAHfrrOdsxt/HCdhrACjLOaM hf2B+fBAnr5iyBz+RTlgyFYPfs55XuvCTRKa6upOKOgUD9G76Gmg1ACCq0RDJLJEnPTa V9JOYcdVwgABHphps2Y6l/wocMMPq0aPRL0eyZOXcQd0uNyL29qQY4TGGSMuPvoPj/AR M4tw== X-Gm-Message-State: AA+aEWbUpH3DGBGWU1i/IZtQNERhL3T1uVieIF8dKNr5BRkaJG0rpDLC hi+JMW9B3Ct52cP9A2ijRh2BEs5FSE0= X-Google-Smtp-Source: AFSGD/UwQrA2FbmsIrBsWuTqkldvgrMWVmL17G8Sy99k4rv3gvnR8mNA80g8BVbHdUiKufmUC1aSqw== X-Received: by 2002:a5d:494a:: with SMTP id r10mr12716083wrs.272.1545086467484; Mon, 17 Dec 2018 14:41:07 -0800 (PST) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c7sm2208199wre.64.2018.12.17.14.41.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Dec 2018 14:41:06 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Brandon Williams , Jonathan Tan , Josh Steadmon , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 2/4] parse_hide_refs_config: handle NULL section Date: Mon, 17 Dec 2018 23:40:52 +0100 Message-Id: <20181217224054.4376-3-avarab@gmail.com> X-Mailer: git-send-email 2.20.0.405.gbc1bbc6f85 In-Reply-To: <20181213155817.27666-1-avarab@gmail.com> References: <20181213155817.27666-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff King This helper function looks for config in two places: transfer.hiderefs, or $section.hiderefs, where $section is passed in by the caller (and is "uploadpack" or "receive", depending on the context). In preparation for callers which do not even have that context (namely the "git-serve" command), let's handle a NULL by looking only at transfer.hiderefs (as opposed to segfaulting). Signed-off-by: Jeff King Signed-off-by: Ævar Arnfjörð Bjarmason --- refs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/refs.c b/refs.c index f9936355cda..099e91d9cc0 100644 --- a/refs.c +++ b/refs.c @@ -1267,7 +1267,8 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti { const char *key; if (!strcmp("transfer.hiderefs", var) || - (!parse_config_key(var, section, NULL, NULL, &key) && + (section && + !parse_config_key(var, section, NULL, NULL, &key) && !strcmp(key, "hiderefs"))) { char *ref; int len; From patchwork Mon Dec 17 22:40:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10734377 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 89F866C5 for ; Mon, 17 Dec 2018 22:41:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DEDE2A5B6 for ; Mon, 17 Dec 2018 22:41:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BE4C2A569; Mon, 17 Dec 2018 22:41:13 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 F0E5D2A5B6 for ; Mon, 17 Dec 2018 22:41:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731942AbeLQWlM (ORCPT ); Mon, 17 Dec 2018 17:41:12 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41221 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727090AbeLQWlL (ORCPT ); Mon, 17 Dec 2018 17:41:11 -0500 Received: by mail-wr1-f66.google.com with SMTP id x10so13941834wrs.8 for ; Mon, 17 Dec 2018 14:41:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W+eI8+5x2DQP1nlfXq0Fwxy4352wgwMrXkHFjxfInBo=; b=npTt3k9VM/BCNBFDD9xjlmsBDaDBcS1SqBYe+3p9y+zQp++BmEhRs4vzKDm9aJjTlx /QWtJWKObHmZRvzql9N2uoQnv9UJaR2TUbOlz/DBp/4c6Drr5SfLd6CR0+k2pVNTf3Fc i8hH162jyZ3ZL5QhYh1xFB7CtQ+NzfKA0yW7GPrV5X1WJYc5UiX6iVGL8+91HaDIfwKW Zrp39XTQf5MqiaUZiQ34gMP9FpwP3nwcL0aYG/Axs8LAZCxewnaHKxLBrzWhs3gNqlVj Ww9ZBjNVTMiQRGwLFoBc3qok3gBwHRWpjbK0/+1fovuoJR1SXHksSuDMR/XdpHpmGJy8 JlnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W+eI8+5x2DQP1nlfXq0Fwxy4352wgwMrXkHFjxfInBo=; b=mPQaspD0QCrcI8SBKeQzSzJxz7D9m+1tkE5+2bOb+X2STEnveiVNj4LLVt9D+f8CAB OTcmJpPXvCRK39EdLSydSrw2vaNULwO3JBaZKbFXMLouuP/aOnHm0QXPBnxBk1Vqb3vT K0EKu8a4R0NtSDyBUxy1fY8B9JLzSEO1sZCo9IKnDpyy1GmuweLNMtng9C6DspTlfaE1 vlK+obWXmuX6EkEQJIMnfGCMwXk9kBjfrUU/WIO+cpZQBgSKxdvSPVNOKWr4ejRsMqLF rBlhwD2giuFH2AhSaZa7p76Tg7D5Zrr8Tnb9z6YpBIL9w4IfgdZgB6t4QO31e3RiiDpT SBHQ== X-Gm-Message-State: AA+aEWYBIiTbrqFVKtgh9wR2lu/4GhS2g/i2plqEP4Zgz2C7xRfsUCFe qmQKCV4PIol4/Rd4gzocnqVVc8VIPLo= X-Google-Smtp-Source: AFSGD/Wu1n42uaXTllCHLsmiHu0O3x9udi+CsD3Toa/XmozvvhdxfDkYBW8wAMvEcdhZyxDRgS5zpA== X-Received: by 2002:adf:f8cf:: with SMTP id f15mr12384905wrq.265.1545086468855; Mon, 17 Dec 2018 14:41:08 -0800 (PST) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c7sm2208199wre.64.2018.12.17.14.41.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Dec 2018 14:41:08 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Brandon Williams , Jonathan Tan , Josh Steadmon , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 3/4] upload-pack: support hidden refs with protocol v2 Date: Mon, 17 Dec 2018 23:40:53 +0100 Message-Id: <20181217224054.4376-4-avarab@gmail.com> X-Mailer: git-send-email 2.20.0.405.gbc1bbc6f85 In-Reply-To: <20181213155817.27666-1-avarab@gmail.com> References: <20181213155817.27666-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jeff King In the v2 protocol, upload-pack's advertisement has been moved to the "ls-refs" command. That command does not respect hidden-ref config (like transfer.hiderefs) at all, and advertises everything. While there are some features that are not supported in v2 (e.g., v2 always allows fetching any sha1 without respect to advertisements), the lack of this feature is not documented and is likely just a bug. Let's make it work, as otherwise upgrading a server to a v2-capable git will start exposing these refs that the repository admin has asked to remain hidden. Note that we depend on the config_context from the caller here to realize that we should respect uploadpack.hiderefs. When run from the "git-serve" tool, we won't have that context and will only respect transfer.hiderefs. This should be OK, as git-serve is not actually used for normal protocol operations. Note also that we don't need to worry about the "An attempt to update or delete a hidden ref by git push is rejected" feature of receive.hideRefs, see git-config(1). This is because there's no v2 push protocol yet. Signed-off-by: Jeff King Signed-off-by: Ævar Arnfjörð Bjarmason --- ls-refs.c | 12 ++++++++++++ t/t5512-ls-remote.sh | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/ls-refs.c b/ls-refs.c index e8e31475f06..8a8143338b4 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -5,6 +5,7 @@ #include "argv-array.h" #include "ls-refs.h" #include "pkt-line.h" +#include "config.h" /* * Check if one of the prefixes is a prefix of the ref. @@ -40,6 +41,9 @@ static int send_ref(const char *refname, const struct object_id *oid, const char *refname_nons = strip_namespace(refname); struct strbuf refline = STRBUF_INIT; + if (ref_is_hidden(refname_nons, refname)) + return 0; + if (!ref_match(&data->prefixes, refname)) return 0; @@ -69,6 +73,12 @@ static int send_ref(const char *refname, const struct object_id *oid, return 0; } +static int ls_refs_config(const char *var, const char *value, + void *config_context) +{ + return parse_hide_refs_config(var, value, config_context); +} + int ls_refs(struct repository *r, const char *config_section, struct argv_array *keys, @@ -78,6 +88,8 @@ int ls_refs(struct repository *r, memset(&data, 0, sizeof(data)); + git_config(ls_refs_config, (void *)config_section); + while (packet_reader_read(request) != PACKET_READ_FLUSH) { const char *arg = request->line; const char *out; diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh index 32e722db2ed..ca69636fd52 100755 --- a/t/t5512-ls-remote.sh +++ b/t/t5512-ls-remote.sh @@ -204,6 +204,12 @@ test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs' grep refs/tags/magic actual ' +test_expect_success 'protocol v2 supports hiderefs' ' + test_config uploadpack.hiderefs refs/tags && + git -c protocol.version=2 ls-remote . >actual && + ! grep refs/tags actual +' + test_expect_success 'ls-remote --symref' ' git fetch origin && cat >expect <<-EOF && From patchwork Mon Dec 17 22:40:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 10734381 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 6E9EE1399 for ; Mon, 17 Dec 2018 22:41:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 631BC2A56D for ; Mon, 17 Dec 2018 22:41:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 614602A578; Mon, 17 Dec 2018 22:41:15 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 E54A62A5D0 for ; Mon, 17 Dec 2018 22:41:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731954AbeLQWlO (ORCPT ); Mon, 17 Dec 2018 17:41:14 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46438 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731920AbeLQWlM (ORCPT ); Mon, 17 Dec 2018 17:41:12 -0500 Received: by mail-wr1-f67.google.com with SMTP id l9so13915053wrt.13 for ; Mon, 17 Dec 2018 14:41:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KNQtb2+1vOQUssOcxR3mDSr6t61IJRJOxzP6axGU2yE=; b=uXJ5rcQsZnBk6jjemfpnVeY95scyOrgRykxhE1tTT4XyiUZTK/HYkavpEM2vjxbLHe M2f3GuWmwuaONnDHW8qKN3Ok7wzPzkDek2aoZGnGWwAK1UIcrL+06tTfukzYrbRNxXDE x3uP8gMEg8cToYMPSo7UU0AfCrROZSvwOqsLoMqtycy6Wokxi5aMD1Hes+tbJEh4/oFy J5MTo0KgJc5Gd463eQexQZ6RPXD51eOzyLTPFKkB5S/1No0+9LwSY1aDIl7cSVJY+D2C l5i2MfKIn5+ghX+CEEgOuMU9CNKrQ7FvCKkpafDRdcOsv5XqzWE2vzt4QqqHD7QeL7pU 2Uzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KNQtb2+1vOQUssOcxR3mDSr6t61IJRJOxzP6axGU2yE=; b=SA87BvOssBJqb/ml6Ju6kSeHpZPIJ4Bhl7Ra2R0lHwHo3IukLRVDmOjOTSWhO2mj4A AngT2tykGRS4LmE37SdLO43087fUEjwFAzW5Sfh4e3+iywWNmzlnj/nmhuyftPESFH6D 5n+2vke3w7E9SuSlyzSB8MmOVuO9bzQawWY2M9ODLjxGlpfJk0cwRUAQtzk8JOB1nwN2 oHyMCVzXQCqpvjjpEKtFGoS3eaCkaxOO5PB4V3epa7Kp8yKzi9s1zstVSHJHXmbFGzU8 pninT7Qqo4T/54ew7pH6HSY67MVfCFSwZEvK+jKxulY7kfbzBOyWlka4c4hikrZxXb6F iezA== X-Gm-Message-State: AA+aEWYvgxuRGPsKXY9ctU9bCAfcu0/m949oXooAOmJCey5RcVvbT4if kvdj3mtcO3QBgh213DS6CY55+E+bd/w= X-Google-Smtp-Source: AFSGD/XMRmElDNn1aqZwAoaUYdu4ST6hbSVklSPQXCBRE/stynMGXsscEd6nPiU8IeTK0RqLbsTBKw== X-Received: by 2002:a5d:558a:: with SMTP id i10mr11770888wrv.287.1545086470178; Mon, 17 Dec 2018 14:41:10 -0800 (PST) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id c7sm2208199wre.64.2018.12.17.14.41.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Dec 2018 14:41:09 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Brandon Williams , Jonathan Tan , Josh Steadmon , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 4/4] fetch-pack: support protocol version 2 Date: Mon, 17 Dec 2018 23:40:54 +0100 Message-Id: <20181217224054.4376-5-avarab@gmail.com> X-Mailer: git-send-email 2.20.0.405.gbc1bbc6f85 In-Reply-To: <20181213155817.27666-1-avarab@gmail.com> References: <20181213155817.27666-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jonathan Tan When the scaffolding for protocol version 2 was initially added in 8f6982b4e1 ("protocol: introduce enum protocol_version value protocol_v2", 2018-03-14). As seen in: git log -p -G'support for protocol v2 not implemented yet' --full-diff --reverse v2.17.0..v2.20.0 Many of those scaffolding "die" placeholders were removed, but we hadn't gotten around to fetch-pack yet. The test here for "fetch refs from cmdline" is very minimal. There's much better coverage when running the entire test suite under the WIP GIT_TEST_PROTOCOL_VERSION=2 mode[1], we should ideally have better coverage without needing to invoke a special test mode. 1. https://public-inbox.org/git/20181213155817.27666-1-avarab@gmail.com/ Signed-off-by: Jonathan Tan Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/fetch-pack.c | 9 ++++++--- t/t5500-fetch-pack.sh | 22 +++++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index 63e69a58011..f6a513495ea 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -55,6 +55,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix) struct oid_array shallow = OID_ARRAY_INIT; struct string_list deepen_not = STRING_LIST_INIT_DUP; struct packet_reader reader; + enum protocol_version version; fetch_if_missing = 0; @@ -219,9 +220,11 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix) PACKET_READ_CHOMP_NEWLINE | PACKET_READ_GENTLE_ON_EOF); - switch (discover_version(&reader)) { + version = discover_version(&reader); + switch (version) { case protocol_v2: - die("support for protocol v2 not implemented yet"); + get_remote_refs(fd[1], &reader, &ref, 0, NULL, NULL); + break; case protocol_v1: case protocol_v0: get_remote_heads(&reader, &ref, 0, NULL, &shallow); @@ -231,7 +234,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix) } ref = fetch_pack(&args, fd, conn, ref, dest, sought, nr_sought, - &shallow, pack_lockfile_ptr, protocol_v0); + &shallow, pack_lockfile_ptr, version); if (pack_lockfile) { printf("lock %s\n", pack_lockfile); fflush(stdout); diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index 086f2c40f68..49c540b1e1d 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -439,15 +439,23 @@ test_expect_success 'setup tests for the --stdin parameter' ' ) >input.dup ' -test_expect_success 'fetch refs from cmdline' ' - ( - cd client && - git fetch-pack --no-progress .. $(cat ../input) - ) >output && - cut -d " " -f 2 actual && - test_cmp expect actual +test_expect_success 'setup fetch refs from cmdline v[12]' ' + cp -r client client1 && + cp -r client client2 ' +for version in '' 1 2 +do + test_expect_success "protocol.version=$version fetch refs from cmdline" " + ( + cd client$version && + GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. \$(cat ../input) + ) >output && + cut -d ' ' -f 2 actual && + test_cmp expect actual + " +done + test_expect_success 'fetch refs from stdin' ' ( cd client &&