From patchwork Wed Jul 21 23:40:02 2021 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: 12392515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35C79C6377C for ; Wed, 21 Jul 2021 23:40:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 119E46121F for ; Wed, 21 Jul 2021 23:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231271AbhGUW7q (ORCPT ); Wed, 21 Jul 2021 18:59:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230289AbhGUW7o (ORCPT ); Wed, 21 Jul 2021 18:59:44 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6740FC061757 for ; Wed, 21 Jul 2021 16:40:19 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id o3-20020a05600c5103b029024c0f9e1a5fso215637wms.4 for ; Wed, 21 Jul 2021 16:40:19 -0700 (PDT) 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=N1n+ssmJcSqfB74nzNj5hZys7EX39DUF3DOWr+C/NWU=; b=GiIWsPtb0wljqiprfteXfbCDy5l/U3HydeH7hsgfK2cq6aYQfst21yMLiNh4vu03p9 rHwGoJiG5d0imArh1l5YUaIOXyicuAVck445PMWuW/HeRnULaeMxP84woflRfgIfHxNv q2NBmfk6C0+DxhsiHP+rcqgNuUr93srKxT2nqEEAf83ZeGt+0QFEmh2P2lrPTiK1qjZz RaAM7teNtyLUudpHquX8qKhhZNtnTogV+FXcL9jseUXQhmQHvDTBKCyEErbQ49rYOgJs DqCx4JSHMakNxzh4Uw9dCw1qWhQMuxzWvLYy9ylTDeqrR6nb02x3QQUsdthw7jgGo2tR 8slw== 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=N1n+ssmJcSqfB74nzNj5hZys7EX39DUF3DOWr+C/NWU=; b=Eet9ZV0hRsAiCH3zZ5gFUnLtYoisCwdkkVaTDFOcSQON1yTIdJ2SkwztNIva4OSAWn kzv0uE+IVCm56S/2RxKUAs5fhYLACS3F8z0lWlmDag1MO6ixYehwpXUyTbcyAt+n6S8g 6u7avrFDftp7AL+I7cdIb2e0qkEbVNAl8ML/SNHUw/dP5bzHUSqS0jcm+YnuQ2ShSeJe zesTD83kVQgqEjOwyVA2xrpFQhmPHsMS/k82KYS7fA9UHIx+++OdIwFW8LEBZd1ljy/8 V9RNbkgulIZ2l8U/KV5UCFDw+RVGjezhOSQL/2HxUS7sQIOzvcIxFVjB5NdGwa6dVhNr SfhQ== X-Gm-Message-State: AOAM531eXiv0WV0HOAoPuy22PmWxXqKGgTGzXGZHqOCNCbdq4CMJKuNq K48qc+Ewo2ekT+K1jeBLhxT3Ww4DcQ/T+w== X-Google-Smtp-Source: ABdhPJzLVCOsWUJr37zpKovG+D4bGgb0jdqymxSihjwPrPqzQYdCK9Jp0idijBh8zI/MjQGF/ILS6g== X-Received: by 2002:a1c:23d0:: with SMTP id j199mr20984994wmj.176.1626910817823; Wed, 21 Jul 2021 16:40:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:17 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 01/12] serve: mark has_capability() as static Date: Thu, 22 Jul 2021 01:40:02 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The has_capability() function introduced in ed10cb952d3 (serve: introduce git-serve, 2018-03-15) has never been used anywhere except serve.c, so let's mark it as static. It was later changed from "extern" in 554544276a6 (*.[ch]: remove extern from function declarations using spatch, 2019-04-29), but we could have simply marked it as "static" instead. Signed-off-by: Ævar Arnfjörð Bjarmason --- serve.c | 4 ++-- serve.h | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/serve.c b/serve.c index aa8209f147e..6748c590b74 100644 --- a/serve.c +++ b/serve.c @@ -156,8 +156,8 @@ static int is_command(const char *key, struct protocol_capability **command) return 0; } -int has_capability(const struct strvec *keys, const char *capability, - const char **value) +static int has_capability(const struct strvec *keys, const char *capability, + const char **value) { int i; for (i = 0; i < keys->nr; i++) { diff --git a/serve.h b/serve.h index fc2683e24d3..56da77a87af 100644 --- a/serve.h +++ b/serve.h @@ -1,10 +1,6 @@ #ifndef SERVE_H #define SERVE_H -struct strvec; -int has_capability(const struct strvec *keys, const char *capability, - const char **value); - struct serve_options { unsigned advertise_capabilities; unsigned stateless_rpc; From patchwork Wed Jul 21 23:40:03 2021 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: 12392517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBDACC6377A for ; Wed, 21 Jul 2021 23:40:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A230B61222 for ; Wed, 21 Jul 2021 23:40:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231276AbhGUW7q (ORCPT ); Wed, 21 Jul 2021 18:59:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231268AbhGUW7p (ORCPT ); Wed, 21 Jul 2021 18:59:45 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8077CC061575 for ; Wed, 21 Jul 2021 16:40:20 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id t5so3880855wrw.12 for ; Wed, 21 Jul 2021 16:40:20 -0700 (PDT) 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=BBhSgJ197C6XcNth5XEFoKmYYgYN07YEA3M83wlnAPU=; b=J0/pHhlFFgVlROMyWM+fFFU4B+k8lANtrRnYpmhpazC5iPrd/ceaxzNgqGXJNFlKS5 JjwT606UdHlgCu/V8+UJgyNFQpQMq1+N8PfRkn+Hwsuv/9CwifQDU4Y7hMtkNkfViGra 3ZTzBZJKpAiF35V724SEtOo+fPSNDL+6c1Xjuy4LFS1Eym6/HyIP4uFvGvFPXNJ3j5/1 yXF51cdYhMGZUnNi8UdH+h8L/jBA/ee3FTLBPBqF1bcKPOf8o5rv1g9f0/r+WX0WSBmI 55taol5a/4ARJjIBM7hbXPshAyBgLhYRXUo98aQJf62iF/g35vx4VPkqzaOzUgXz5ISN 6AXg== 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=BBhSgJ197C6XcNth5XEFoKmYYgYN07YEA3M83wlnAPU=; b=bxERHmgiy9C7Bk6YyrHZJBDUph8iTDVd8QCAp3A2QgsgQy9Hea5tV9pVmuhXcaf7Qo I/3jsiTYIKtBDoCHx1Oisz3V6RMx7XPCprOSNW8saRdZYOscdzEv6Big93Kg9exHZyHI YygNxZKVZ46a2L1cRFwHwaYujoFqaNJ8xjS4Q697BDcC+ZZesu/202ILbasXQP1bbZhQ VuznhSZo84pYwgR6w8DzS9wMGwdfRfD1M8Kg6mPmqeZLnZit7I21cMkIEHcdpVZR5OVs tQYjSw1ZsXs8BuI88reUHFCik0lfxthYDnMQh7HCKZT63J8Icx6GariHIPOn1d84NQeW PZJQ== X-Gm-Message-State: AOAM532NYeb00j9v2pFmj7xvSoH8/EcQ8AVq9QgMCLIjIScH5s+XiBy9 PKf5HA1chu0lgVxK0U5dOIpgsx3qE/dFXg== X-Google-Smtp-Source: ABdhPJyP7gj4yiBENIWxq3Qb1GyZa5gPkuzSVsvanZ8AjCHZD2+JebXL1ynUeXZG0s2vMOTKgHUGWg== X-Received: by 2002:a5d:408d:: with SMTP id o13mr46251935wrp.246.1626910818863; Wed, 21 Jul 2021 16:40:18 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:18 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 02/12] transport: rename "fetch" in transport_vtable to "fetch_refs" Date: Thu, 22 Jul 2021 01:40:03 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename the "fetch" member of the transport_vtable to "fetch_refs" for consistency with the existing "push_refs". Neither of them just push "refs" but refs and objects, but having the two match makes the code more readable than having it be inconsistent, especially since "fetch_refs" is a lot easier to grep for than "fetch". Signed-off-by: Ævar Arnfjörð Bjarmason --- transport-helper.c | 8 ++++---- transport-internal.h | 2 +- transport.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/transport-helper.c b/transport-helper.c index 4be035edb8b..8d445a8f3ee 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -671,8 +671,8 @@ static int connect_helper(struct transport *transport, const char *name, static struct ref *get_refs_list_using_list(struct transport *transport, int for_push); -static int fetch(struct transport *transport, - int nr_heads, struct ref **to_fetch) +static int fetch_refs(struct transport *transport, + int nr_heads, struct ref **to_fetch) { struct helper_data *data = transport->data; int i, count; @@ -681,7 +681,7 @@ static int fetch(struct transport *transport, if (process_connect(transport, 0)) { do_take_over(transport); - return transport->vtable->fetch(transport, nr_heads, to_fetch); + return transport->vtable->fetch_refs(transport, nr_heads, to_fetch); } /* @@ -1263,7 +1263,7 @@ static struct ref *get_refs_list_using_list(struct transport *transport, static struct transport_vtable vtable = { set_helper_option, get_refs_list, - fetch, + fetch_refs, push_refs, connect_helper, release_helper diff --git a/transport-internal.h b/transport-internal.h index b60f1ba9077..c4ca0b733ac 100644 --- a/transport-internal.h +++ b/transport-internal.h @@ -34,7 +34,7 @@ struct transport_vtable { * get_refs_list(), it should set the old_sha1 fields in the * provided refs now. **/ - int (*fetch)(struct transport *transport, int refs_nr, struct ref **refs); + int (*fetch_refs)(struct transport *transport, int refs_nr, struct ref **refs); /** * Push the objects and refs. Send the necessary objects, and diff --git a/transport.c b/transport.c index 17e9629710a..3e8a27b0321 100644 --- a/transport.c +++ b/transport.c @@ -1453,7 +1453,7 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs) heads[nr_heads++] = rm; } - rc = transport->vtable->fetch(transport, nr_heads, heads); + rc = transport->vtable->fetch_refs(transport, nr_heads, heads); free(heads); return rc; From patchwork Wed Jul 21 23:40:04 2021 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: 12392519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F12F1C6377B for ; Wed, 21 Jul 2021 23:40:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D506361222 for ; Wed, 21 Jul 2021 23:40:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231285AbhGUW7w (ORCPT ); Wed, 21 Jul 2021 18:59:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231272AbhGUW7q (ORCPT ); Wed, 21 Jul 2021 18:59:46 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AF1FC0613C1 for ; Wed, 21 Jul 2021 16:40:21 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id c12so3903600wrt.3 for ; Wed, 21 Jul 2021 16:40:21 -0700 (PDT) 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=o+8ZAAQNDihFUXFEwCrjmlIzX0BXJVDYNDsNA3Ze5RI=; b=BDNruivgF43eWwfvD+Z6kd9FKXdquKzyDKXzto6VTR+tp2e2WhonA/pkj8qZ/20vFI s9qvWcz/1S0lVwmpOtMXGI660dIzx/kJCKM2zxOWMtdQ5d7+M32iP/1nyNhD3iqc4KsB k+i/e8/r2ubuAFb3et7smy8SOeatJRljW0pO7MvYjRVER86GnRCM6D5iLI3NfMskcDPK 6jZA3NL/9NVnDu0J/mcp/5mvlVsCLIC8aJ1Wj1XME7y73Rg4oLAIeu11J1SBE5m3RoJS RdTneIvaL7e0EggvQ0KCid2nn5kowKkosANfBSeXJAUaGrd0KQKAj8GxIIUkdWabsv2h GVMQ== 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=o+8ZAAQNDihFUXFEwCrjmlIzX0BXJVDYNDsNA3Ze5RI=; b=tKYtryxFwn+S2j+YoltGbbUy2/JlAI0kcWSQMWJtSFaCYijWI3q4dluecph98TmdBR jRIgwU3+1Pe7S2EOgHMEaKzS1BlGecZxIMu/kXeB2sQiHB2BmZtu4xYnAYK/F4Pz5Q9L ZZ17AJd2tCrWrPnIQQS8dtNkf+4u+SQvfRhASgLP/xJ2n32atLhkdkM5mcmiR1Qh8w3Y Q8jMdY/3rV+kV/vYWYBJI1ciJobzZGqWcBqAjOWm2Ieyi1cM42NfodQ5oovw/tMpnYrS 35oa6sszsaCB90qMhB0sKgAnMN25sU6Di5HQxavmWWCENdLLVwqzgYjG1jNzGkqNImoE 4Zuw== X-Gm-Message-State: AOAM532OxQ51NmsSg4xu92BchOOQT8z3lS9KOk2V4y9j8fb8tLN1Zogb fdWWSfxXpmjWLuh80wmZ0O+dXzAwHmdeuA== X-Google-Smtp-Source: ABdhPJzTSR+penfx8Po7Knk6+zJtnqyhCSce4CJ3G46nyMRcLRU+8BaoHjs+FMjD7ZZwsZx5/Bwv/w== X-Received: by 2002:a5d:4e05:: with SMTP id p5mr45065358wrt.322.1626910819790; Wed, 21 Jul 2021 16:40:19 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:19 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 03/12] transport: use designated initializers Date: Thu, 22 Jul 2021 01:40:04 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the assignments to the various transport_vtables to use designated initializers, this makes the code easier to read and maintain. Signed-off-by: Ævar Arnfjörð Bjarmason --- transport-helper.c | 12 ++++++------ transport.c | 30 ++++++++++++------------------ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/transport-helper.c b/transport-helper.c index 8d445a8f3ee..e8dbdd11530 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -1261,12 +1261,12 @@ static struct ref *get_refs_list_using_list(struct transport *transport, } static struct transport_vtable vtable = { - set_helper_option, - get_refs_list, - fetch_refs, - push_refs, - connect_helper, - release_helper + .set_option = set_helper_option, + .get_refs_list = get_refs_list, + .fetch_refs = fetch_refs, + .push_refs = push_refs, + .connect = connect_helper, + .disconnect = release_helper }; int transport_helper_init(struct transport *transport, const char *name) diff --git a/transport.c b/transport.c index 3e8a27b0321..f9400b9b0bd 100644 --- a/transport.c +++ b/transport.c @@ -883,12 +883,10 @@ static int disconnect_git(struct transport *transport) } static struct transport_vtable taken_over_vtable = { - NULL, - get_refs_via_connect, - fetch_refs_via_pack, - git_transport_push, - NULL, - disconnect_git + .get_refs_list = get_refs_via_connect, + .fetch_refs = fetch_refs_via_pack, + .push_refs = git_transport_push, + .disconnect = disconnect_git }; void transport_take_over(struct transport *transport, @@ -1032,21 +1030,17 @@ void transport_check_allowed(const char *type) } static struct transport_vtable bundle_vtable = { - NULL, - get_refs_from_bundle, - fetch_refs_from_bundle, - NULL, - NULL, - close_bundle + .get_refs_list = get_refs_from_bundle, + .fetch_refs = fetch_refs_from_bundle, + .disconnect = close_bundle }; static struct transport_vtable builtin_smart_vtable = { - NULL, - get_refs_via_connect, - fetch_refs_via_pack, - git_transport_push, - connect_git, - disconnect_git + .get_refs_list = get_refs_via_connect, + .fetch_refs = fetch_refs_via_pack, + .push_refs = git_transport_push, + .connect = connect_git, + .disconnect = disconnect_git }; struct transport *transport_get(struct remote *remote, const char *url) From patchwork Wed Jul 21 23:40:05 2021 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: 12392521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 716D2C6377C for ; Wed, 21 Jul 2021 23:40:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BDA561241 for ; Wed, 21 Jul 2021 23:40:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231290AbhGUW7y (ORCPT ); Wed, 21 Jul 2021 18:59:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231268AbhGUW7r (ORCPT ); Wed, 21 Jul 2021 18:59:47 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E5E3C0613CF for ; Wed, 21 Jul 2021 16:40:22 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id t5so3880909wrw.12 for ; Wed, 21 Jul 2021 16:40:22 -0700 (PDT) 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=fN6TqGOnIRPyZFHYAnlasxZNQC8ih5QnEoNRDDA9m+E=; b=BuoLYAp4czZSaUGN0ZkDuxUJ/Rw3xc4y38ndcb5de0sXZWxb2ueLijfAIdPkRcYlNn 33jcat75EiwkBui8pns6Y5q85blehdi1V757dlbI1eXfpCu6noKSL9LFPjjF9Xjirvi9 dwDVDkItXh+WxtNwkkgpzb2hw6Q9BPB1tKmzBdMhyXeX4I+lrtqRKJEiBW3V8MBr+s6L 3Qv0suXAg/EWti0RzwgYrVVbHXzNTR0c9z6ERN7x8gtnt67lx91sFbZtxKjc7Sp2tkLY nT9IWerjvZkblHlaqQJCyi99LzLt5u/zPb/8eTUEF7wsTBpuuPKbCGdEtNzWP93RHn73 wPKQ== 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=fN6TqGOnIRPyZFHYAnlasxZNQC8ih5QnEoNRDDA9m+E=; b=a4DDAKTED7w/2xplHxod//gFQWTaklorj32hOAfcGDDys0jcrv/dGMND+wEUz+05O1 w20h8pypbzZKPt+G/Jgd3J0t3tMu54lTWuudqePPrrfFvNdrcqbjGxaNjrHnKGb/LW8g 8IlccGsgjGQB70su6w/UWtS02i9Xq3XbwJ5r0XdnyKnXtZoAqycnoNJikh+cqtssEsH7 nSx8NNWdIwHL4QXtxBzQJy4wIq+BQ1AhwzfAJuUkOxOQwE+UhZBxIl9iTh11TjbEUI/C n1docfS18RthVMLY0apWhLsWceoDsDCOi4VGcH70JLQTDfuTXEZBu21KqpUEFYGGMrUi 1Jhg== X-Gm-Message-State: AOAM532hrHHsKQPmloTKjrRoPAaBnPX/TC5fRtYughM1fZz+2WCM6SGB R0i2XgC7tCj1qmGYixho2JmfPWsPCrjTXw== X-Google-Smtp-Source: ABdhPJwK15havmJfLwDrdm8QGZgntb4oqpL8RcPpLgzdqUx/kwn0C75iH+ai9PvZwAGm9P7Y24e7FA== X-Received: by 2002:a5d:684b:: with SMTP id o11mr26031672wrw.29.1626910820608; Wed, 21 Jul 2021 16:40:20 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:20 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 04/12] serve: use designated initializers Date: Thu, 22 Jul 2021 01:40:05 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the declaration of the protocol_capability struct to use designated initializers, this makes this more verbose now, but a follow-up commit will add a new field. At that point these lines would be too dense to be on one line comfortably. Signed-off-by: Ævar Arnfjörð Bjarmason --- serve.c | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/serve.c b/serve.c index 6748c590b74..49ea9fc8fd5 100644 --- a/serve.c +++ b/serve.c @@ -73,13 +73,37 @@ struct protocol_capability { }; static struct protocol_capability capabilities[] = { - { "agent", agent_advertise, NULL }, - { "ls-refs", ls_refs_advertise, ls_refs }, - { "fetch", upload_pack_advertise, upload_pack_v2 }, - { "server-option", always_advertise, NULL }, - { "object-format", object_format_advertise, NULL }, - { "session-id", session_id_advertise, NULL }, - { "object-info", always_advertise, cap_object_info }, + { + .name = "agent", + .advertise = agent_advertise, + }, + { + .name = "ls-refs", + .advertise = ls_refs_advertise, + .command = ls_refs, + }, + { + .name = "fetch", + .advertise = upload_pack_advertise, + .command = upload_pack_v2, + }, + { + .name = "server-option", + .advertise = always_advertise, + }, + { + .name = "object-format", + .advertise = object_format_advertise, + }, + { + .name = "session-id", + .advertise = session_id_advertise, + }, + { + .name = "object-info", + .advertise = always_advertise, + .command = cap_object_info, + }, }; static void advertise_capabilities(void) From patchwork Wed Jul 21 23:40:06 2021 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: 12392523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 076B3C6377B for ; Wed, 21 Jul 2021 23:40:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DDB0D60FDA for ; Wed, 21 Jul 2021 23:40:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231296AbhGUW7z (ORCPT ); Wed, 21 Jul 2021 18:59:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231278AbhGUW7s (ORCPT ); Wed, 21 Jul 2021 18:59:48 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07A90C061575 for ; Wed, 21 Jul 2021 16:40:23 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id o5-20020a1c4d050000b02901fc3a62af78so462854wmh.3 for ; Wed, 21 Jul 2021 16:40:22 -0700 (PDT) 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=BTOiJfnIT2RXCZYRRLrLqdCWnviE/dc7wsNL07F7uGw=; b=JYPLvCT3bqQUo/lQYw++06SbkEpPOS65wJzsxDA1lMi3AQ4U2ZEDqdV+N4+v91evoB JcHFmiwAy/JEqh+wQHpanblHjB80fytQjOzVAseF233qphoqcPRC3tY6XS7aluIIoQUO 9BDdO4AW445lbLCPPELuqY/i0MOWFXZU+s0BgQJiRAJ3WPExqkg58pkBcTEob6Q/7VVF KBpX2yknXluWPIoD4C5/dmPxwTfc0tETeC/T7jsHmXo63ErxLSXLASB5Qtbfkmdk9AjE kjl+YO7nY73VnwGgWzhV/sSrJKbHT51SgDCIPRdCiBvHGPLIEA+qLz1FxiGcWslCuGAi o/ag== 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=BTOiJfnIT2RXCZYRRLrLqdCWnviE/dc7wsNL07F7uGw=; b=AwWwkkTAAl0bC1HXv9nwrEuXh+jaYYqlGt2rkU4+tLfVLy+NoKZfCDfe6nvmwG0ksJ 2UMxSUuP8Cg/UGUa3Ir00ZCF69UMqVUR9NG+zbM47YR9zu30tQKHpM+Q1NZbbdtU8H4A JghbgWadvQ8EUOEVdPqgawlIIIVx0X1tQ9Zbx4QXTyNUvNT9HwoA6KpFzpHy6k/sCICo lLRyTlwqTYDR4zGySspq8j8QaefoGJ40auti4Le6iIb2w++mJRVZn9kKEf10u2Jr+DaY lpm7ClT0S6D6Z5SYn8H58W/34AejMQ7+mgY7ofnXWnoau9zV9gioRisMV8GQfYiFFuT5 0ZzQ== X-Gm-Message-State: AOAM53044p7wo98VviD4HeePb/iin2zw2h8/N4OmIvV+XiEpEHsxflRi UDuaK/ttdY7rOGjJmtmqn7UJRQwE7xmmrQ== X-Google-Smtp-Source: ABdhPJxAa3z/hQ5uv0IhL/0/tpbZGSfKPwve7jET9sn4yxcjTVJYelPk6jdUQjVSzun34Edxy/HUfA== X-Received: by 2002:a1c:7410:: with SMTP id p16mr6151130wmc.6.1626910821411; Wed, 21 Jul 2021 16:40:21 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:21 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 05/12] serve.c: add call_{advertise,command}() indirection Date: Thu, 22 Jul 2021 01:40:06 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Instead of directly calling the callbacks defined in the "struct protocol_capability", let's call them via new "call_{advertise,command}()" functions. There's no use in this indirection now, but it'll be used in a subsequent commit to ensure that config is read before they're called. See ed10cb952d3 (serve: introduce git-serve, 2018-03-15) for the introduction of the code being changed here. Signed-off-by: Ævar Arnfjörð Bjarmason --- serve.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/serve.c b/serve.c index 49ea9fc8fd5..85cd3eab26e 100644 --- a/serve.c +++ b/serve.c @@ -42,6 +42,10 @@ static int session_id_advertise(struct repository *r, struct strbuf *value) return 1; } +typedef int (*advertise_fn_t)(struct repository *r, struct strbuf *value); +typedef int (*command_fn_t)(struct repository *r, struct strvec *keys, + struct packet_reader *request); + struct protocol_capability { /* * The name of the capability. The server uses this name when @@ -56,7 +60,7 @@ struct protocol_capability { * If a value is added to 'value', the server will advertise this * capability as "=" instead of "". */ - int (*advertise)(struct repository *r, struct strbuf *value); + advertise_fn_t advertise; /* * Function called when a client requests the capability as a command. @@ -67,9 +71,7 @@ struct protocol_capability { * * This field should be NULL for capabilities which are not commands. */ - int (*command)(struct repository *r, - struct strvec *keys, - struct packet_reader *request); + command_fn_t command; }; static struct protocol_capability capabilities[] = { @@ -106,6 +108,19 @@ static struct protocol_capability capabilities[] = { }, }; +static int call_advertise(struct protocol_capability *command, + struct repository *r, struct strbuf *value) +{ + return command->advertise(r, value); +} + +static int call_command(struct protocol_capability *command, + struct repository *r, struct strvec *keys, + struct packet_reader *request) +{ + return command->command(r, keys, request); +} + static void advertise_capabilities(void) { struct strbuf capability = STRBUF_INIT; @@ -115,7 +130,7 @@ static void advertise_capabilities(void) for (i = 0; i < ARRAY_SIZE(capabilities); i++) { struct protocol_capability *c = &capabilities[i]; - if (c->advertise(the_repository, &value)) { + if (call_advertise(c, the_repository, &value)) { strbuf_addstr(&capability, c->name); if (value.len) { @@ -155,9 +170,9 @@ static struct protocol_capability *get_capability(const char *key) static int is_valid_capability(const char *key) { - const struct protocol_capability *c = get_capability(key); + struct protocol_capability *c = get_capability(key); - return c && c->advertise(the_repository, NULL); + return c && call_advertise(c, the_repository, NULL); } static int is_command(const char *key, struct protocol_capability **command) @@ -170,7 +185,7 @@ static int is_command(const char *key, struct protocol_capability **command) if (*command) die("command '%s' requested after already requesting command '%s'", out, (*command)->name); - if (!cmd || !cmd->advertise(the_repository, NULL) || !cmd->command) + if (!cmd || !call_advertise(cmd, the_repository, NULL) || !cmd->command) die("invalid command '%s'", out); *command = cmd; @@ -294,7 +309,7 @@ static int process_request(void) if (has_capability(&keys, "session-id", &client_sid)) trace2_data_string("transfer", NULL, "client-sid", client_sid); - command->command(the_repository, &keys, &reader); + call_command(command, the_repository, &keys, &reader); strvec_clear(&keys); return 0; From patchwork Wed Jul 21 23:40:07 2021 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: 12392525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97915C6377A for ; Wed, 21 Jul 2021 23:40:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D41F6121F for ; Wed, 21 Jul 2021 23:40:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231298AbhGUW7z (ORCPT ); Wed, 21 Jul 2021 18:59:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231279AbhGUW7t (ORCPT ); Wed, 21 Jul 2021 18:59:49 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4098BC061757 for ; Wed, 21 Jul 2021 16:40:24 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id d12so3860026wre.13 for ; Wed, 21 Jul 2021 16:40:24 -0700 (PDT) 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=XqvNMAoT1PFqUy3almKkv1pyszgu/Sr7uLOpqTgjyqY=; b=E+1ysuAMgg/7i49DfQu2vMbreoDkVSl76D6s/7PWrysMG8nwZCsmmfE39dDZHuYNXA yM4vZjU73qqIw+VR2ouIoOlYwtuUVrnNfPx/9S6yoQxKuWtXT3LilgpPxM5m8Uget1uK mcLcxNqwcLTNA0Wpbo8F6MaVscCLusriCpZ6o8vJHUzelpI3s8JIq4tyBfP8I2NpW+ms rg+FVtmLjZEATbseBMdnidYoc3vZHNR3KVGHI1D1/0FOit6CdP4fDrPG6AR7sQpmvMPx h5fYgp4cdkIIA89j6PZIWqGWcJaLPJa/gbfhbGD3zugOYf4B3aAOOzsF9EtACpHzXmrY RH7Q== 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=XqvNMAoT1PFqUy3almKkv1pyszgu/Sr7uLOpqTgjyqY=; b=bf8v4CTDrrUKba4ABkUhd2KDxVocXIG0Mi8H5nN2cJiOXSGatu1gjfNnfVhm7m8A26 A8ugun5LkJCSEHy077dRsh4Tt7W8qSNLqbia57BABWDL/XjA/TdVm6BeVPLGeHY9nm3n DmlBAyOUNDCWRtJmgp6XJR2GAPacEwytzHvUox1DTbmfAUFBjU5TNi50i3YKKOPhEom8 njKJY4/uV/hkB+YHRgQ9eB2D+d5OpYCC83Z+hgW3OgStPJW0LzDkDjwtktMECWzuipqo +8JF7IkT+gON1K4hgykOaMAKkOwomRoI9xd5K40rqCylOtbiGgKp5PYYgDkDnfurcz33 ZRyQ== X-Gm-Message-State: AOAM531/WE6Hste8y6cidnCOSSMil4bXaezyVKeXY143HPzaOW7Kb1u7 gjDWnV/VuZz5q0177b4eqXFtQdIXgiDKCw== X-Google-Smtp-Source: ABdhPJxadY0PGM6ppUnQiEUA7bBA2LW4KV9ZCOes/A39qm0lVbaIoKAPqNOdQqmBzM0bxNqc8RduAg== X-Received: by 2002:adf:b605:: with SMTP id f5mr45304235wre.419.1626910822545; Wed, 21 Jul 2021 16:40:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:21 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 06/12] serve: add support for a "startup" git_config() callback Date: Thu, 22 Jul 2021 01:40:07 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since the introduction of serve.c we've added git_config() callbacks and other config reading for capabilities in the following commits: - e20b4192a37 (upload-pack: support hidden refs with protocol v2, 2018-12-18) - 08450ef7918 (upload-pack: clear filter_options for each v2 fetch command, 2020-05-08) - 6b5b6e422ee (serve: advertise session ID in v2 capabilities, 2020-11-11) - 59e1205d167 (ls-refs: report unborn targets of symrefs, 2021-02-05) Of these 08450ef7918 fixed code that needed to read config on a per-request basis, whereas most of the config reading just wants to check if we've enabled one semi-static config variable or other. We'd like to re-read that value eventually, but from request-to-request it's OK if we retain the old one, and it isn't impacted by other request data. So let's support this common pattern as a "startup_config" callback, making use of our recently added "call_{advertise,command}()" functions. This allows us to simplify e.g. the "ensure_config_read()" function added in 59e1205d167 (ls-refs: report unborn targets of symrefs, 2021-02-05). We could read all the config for all the protocol capabilities, but let's do it one callback at a time in anticipation that some won't be called at all, and that some might be more expensive than others in the future. I'm not migrating over the code in the upload_pack_v2 function in upload-pack.c yet, that case is more complex since it deals with both v1 and v2. It will be dealt with in a code a subsequent commit. As we'll see in subsequent commits, by moving the transfer.advertisesid config reading out of serve() we can simplify the codepath around advertising-only requests. See 6b5b6e422ee (serve: advertise session ID in v2 capabilities, 2020-11-11)) for the commit that added transfer.advertisesid. Signed-off-by: Ævar Arnfjörð Bjarmason --- ls-refs.c | 42 ++++++++++++++---------------------------- ls-refs.h | 1 + serve.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 30 deletions(-) diff --git a/ls-refs.c b/ls-refs.c index 88f6c3f60d8..02fbcfd9bde 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -7,37 +7,26 @@ #include "pkt-line.h" #include "config.h" -static int config_read; -static int advertise_unborn; -static int allow_unborn; +/* "unborn" is on by default if there's no lsrefs.unborn config */ +static int advertise_unborn = 1; +static int allow_unborn = 1; -static void ensure_config_read(void) +int ls_refs_startup_config(const char *var, const char *value, void *data) { - const char *str = NULL; - - if (config_read) - return; - - if (repo_config_get_string_tmp(the_repository, "lsrefs.unborn", &str)) { - /* - * If there is no such config, advertise and allow it by - * default. - */ - advertise_unborn = 1; - allow_unborn = 1; - } else { - if (!strcmp(str, "advertise")) { - advertise_unborn = 1; + if (!strcmp(var, "lsrefs.unborn")) { + if (!strcmp(value, "advertise")) { + /* Allowed and advertised by default */ + } else if (!strcmp(value, "allow")) { + advertise_unborn = 0; allow_unborn = 1; - } else if (!strcmp(str, "allow")) { - allow_unborn = 1; - } else if (!strcmp(str, "ignore")) { - /* do nothing */ + } else if (!strcmp(value, "ignore")) { + advertise_unborn = 0; + allow_unborn = 0; } else { - die(_("invalid value '%s' for lsrefs.unborn"), str); + die(_("invalid value '%s' for lsrefs.unborn"), value); } } - config_read = 1; + return 0; } /* @@ -145,8 +134,6 @@ int ls_refs(struct repository *r, struct strvec *keys, memset(&data, 0, sizeof(data)); strvec_init(&data.prefixes); - - ensure_config_read(); git_config(ls_refs_config, NULL); while (packet_reader_read(request) == PACKET_READ_NORMAL) { @@ -179,7 +166,6 @@ int ls_refs(struct repository *r, struct strvec *keys, int ls_refs_advertise(struct repository *r, struct strbuf *value) { if (value) { - ensure_config_read(); if (advertise_unborn) strbuf_addstr(value, "unborn"); } diff --git a/ls-refs.h b/ls-refs.h index a99e4be0bdd..5fcab0d1dca 100644 --- a/ls-refs.h +++ b/ls-refs.h @@ -6,6 +6,7 @@ struct strvec; struct packet_reader; int ls_refs(struct repository *r, struct strvec *keys, struct packet_reader *request); +int ls_refs_startup_config(const char *var, const char *value, void *data); int ls_refs_advertise(struct repository *r, struct strbuf *value); #endif /* LS_REFS_H */ diff --git a/serve.c b/serve.c index 85cd3eab26e..3c7c9329a14 100644 --- a/serve.c +++ b/serve.c @@ -33,6 +33,13 @@ static int object_format_advertise(struct repository *r, return 1; } +static int session_id_startup_config(const char *var, const char *value, void *data) +{ + if (!strcmp(var, "transfer.advertisesid")) + advertise_sid = git_config_bool(var, value); + return 0; +} + static int session_id_advertise(struct repository *r, struct strbuf *value) { if (!advertise_sid) @@ -54,6 +61,24 @@ struct protocol_capability { */ const char *name; + /* + * A git_config() callback that'll be called only once for the + * lifetime of the process, possibly over many different + * requests. Used for reading config that's expected to be + * static. + * + * The "command" or "advertise" callbacks themselves are + * expected to read config that needs to be more current than + * that, or which is dependent on request data. + */ + int (*startup_config)(const char *var, const char *value, void *data); + + /* + * A boolean to check if we've called our "startup_config" + * callback. + */ + int have_startup_config; + /* * Function queried to see if a capability should be advertised. * Optionally a value can be specified by adding it to 'value'. @@ -81,6 +106,7 @@ static struct protocol_capability capabilities[] = { }, { .name = "ls-refs", + .startup_config = ls_refs_startup_config, .advertise = ls_refs_advertise, .command = ls_refs, }, @@ -99,6 +125,7 @@ static struct protocol_capability capabilities[] = { }, { .name = "session-id", + .startup_config = session_id_startup_config, .advertise = session_id_advertise, }, { @@ -108,9 +135,20 @@ static struct protocol_capability capabilities[] = { }, }; +static void read_startup_config(struct protocol_capability *command) +{ + if (!command->startup_config) + return; + if (command->have_startup_config++) + return; + git_config(command->startup_config, NULL); +} + static int call_advertise(struct protocol_capability *command, struct repository *r, struct strbuf *value) { + read_startup_config(command); + return command->advertise(r, value); } @@ -118,6 +156,9 @@ static int call_command(struct protocol_capability *command, struct repository *r, struct strvec *keys, struct packet_reader *request) { + + read_startup_config(command); + return command->command(r, keys, request); } @@ -318,8 +359,6 @@ static int process_request(void) /* Main serve loop for protocol version 2 */ void serve(struct serve_options *options) { - git_config_get_bool("transfer.advertisesid", &advertise_sid); - if (options->advertise_capabilities || !options->stateless_rpc) { /* serve by default supports v2 */ packet_write_fmt(1, "version 2\n"); From patchwork Wed Jul 21 23:40:08 2021 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: 12392527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6109DC6377C for ; Wed, 21 Jul 2021 23:40:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4AA6E60FDA for ; Wed, 21 Jul 2021 23:40:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231302AbhGUW75 (ORCPT ); Wed, 21 Jul 2021 18:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231280AbhGUW7t (ORCPT ); Wed, 21 Jul 2021 18:59:49 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9EE1C0613C1 for ; Wed, 21 Jul 2021 16:40:24 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id c12so3903692wrt.3 for ; Wed, 21 Jul 2021 16:40:24 -0700 (PDT) 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=iAhIuEN/SO4U2jb3YZV02g3Mjs167EhiJxdm1qXMXvY=; b=Tcmvur0FNd/VHgR8use97niPCZhwyI0byRGM6jqADXY9Hpd/08FxdsSMeGW8Refutu oenEgbY9qSvgU6DwsDdbZBrgSBcbAZuFN8MQM4g2RqQ+VH/q0E6ZZYpJJW4f30FmC6CC Y853lo3btRR9raZAKkLSYQznH3QwBrdoN+OOAzpMz1KLnawOd9hcoYzivPbmQ8wtH8J2 M9oMFzmFI1k6n89eiHN2kOqteH0Jh2p08MQokdQeD/UAL761HGmc6F1mPZ+YS82j76eK MrPD5OKpocPi3S1lcnQj5tk0N+keKrdgzkAxBJlXxqMzLwTl+oevaon0bxdkkhJ4q6qV rHvg== 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=iAhIuEN/SO4U2jb3YZV02g3Mjs167EhiJxdm1qXMXvY=; b=XwZFQcYMYU0rEsn6VBY2wHmOEQWuWSa/3k8VLeRuujwMosHHvLuV5DNAkYM18GTaYn islI0KaNTws9FlmS/3fp6DKt1jSOvvqKArK8PXFFA3uQ7iCbMT5I7tK96G8zRgrz+bAg D1ZyJwMvjhTJqNub0nzaDjmDF0WCYEJaGV7i8may0lR9Xu4Q14doGA+dXIUwQ5kyXT3l JwzhJIhMRPJLQl5oSHEjLvg+1TR/miRE5rYcjOxHDjs1q/azL/Bv4DiWREPDfi1Ea+iW Qt0mFPJ9xANx1qnHkOb3CWz4L/frxajvuxJHH11MJriNCH4/HJ8YOgDAGyMcXbbHGHS4 YUBA== X-Gm-Message-State: AOAM532v9VwIYYdYsXrQ9dLKxTZaHzaVUQ10gyQ3ZSJ4uVp2AgJGsyzX EhDc0gL0oFmwEaFVAhJZTeEAPkf50lS8cQ== X-Google-Smtp-Source: ABdhPJzgDgXJukBFpLqQ5sPJio4su7bAD0xvEeDuqqNvS8HAeP2e7Kxem4+EX/yRBFlXz3f3wsxHSA== X-Received: by 2002:adf:9084:: with SMTP id i4mr45604497wri.23.1626910823312; Wed, 21 Jul 2021 16:40:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:22 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 07/12] serve.c: move version line to advertise_capabilities() Date: Thu, 22 Jul 2021 01:40:08 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The advertise_capabilities() is only called from serve() and we always emit this version line before it, it makes more sense to consider the capabilities part of a "header" that has the version, so let's move the writing of the version there. Signed-off-by: Ævar Arnfjörð Bjarmason --- serve.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/serve.c b/serve.c index 3c7c9329a14..10209ab237d 100644 --- a/serve.c +++ b/serve.c @@ -168,6 +168,9 @@ static void advertise_capabilities(void) struct strbuf value = STRBUF_INIT; int i; + /* serve by default supports v2 */ + packet_write_fmt(1, "version 2\n"); + for (i = 0; i < ARRAY_SIZE(capabilities); i++) { struct protocol_capability *c = &capabilities[i]; @@ -360,9 +363,6 @@ static int process_request(void) void serve(struct serve_options *options) { if (options->advertise_capabilities || !options->stateless_rpc) { - /* serve by default supports v2 */ - packet_write_fmt(1, "version 2\n"); - advertise_capabilities(); /* * If only the list of capabilities was requested exit From patchwork Wed Jul 21 23:40:09 2021 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: 12392529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C12BC6377D for ; Wed, 21 Jul 2021 23:40:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0494D6121F for ; Wed, 21 Jul 2021 23:40:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231286AbhGUW76 (ORCPT ); Wed, 21 Jul 2021 18:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231282AbhGUW7u (ORCPT ); Wed, 21 Jul 2021 18:59:50 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE594C0613D3 for ; Wed, 21 Jul 2021 16:40:25 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id p15-20020a05600c358fb0290245467f26a4so1902429wmq.0 for ; Wed, 21 Jul 2021 16:40:25 -0700 (PDT) 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=GZHsAB+dmh65tEoAdxy0vHNdJHymc+12TBGJQ7MStzM=; b=mO8nORC/whGLkprjxN4leh+oJphwLEE0CxK0LoJXv5ByBZF8QGEQC6ZjpEwGMi1l0z 6Sa7+iz1RAamnGzSxvEEO09XvZwmt5WLvFKSuaR6FzWO8eC+YeJ6xJ+WJzEutj0Bh/4U 3qb22207ErAoE9JsFeuTi2qTEv00jmagln6M29Y3UKh75OdukbVh26+n0Hd6GuUKRbRk D2WNTU8qnejBlLWLrPrTZ4hYgWRUFEii/YcECwYKV4HEVISjvr31JIDDSTiobZpjZCp5 VjdP7B8YrT9scfXjmZ7cO61BLM7MFe5h1sjLrQ3FNIkW11qPJgUBrsTqXOyZV9VrRE/e 0pXw== 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=GZHsAB+dmh65tEoAdxy0vHNdJHymc+12TBGJQ7MStzM=; b=EyagCXgtkU3e5nk+oD+GvjWbkgFvLobZny7Ql7C5SeEttSBOMwJqi2i8cEhDQiMrJD SrGYNEYmBoPEEChhn8eHSYUPVjBOyy+dxkTFc9+EBhnRNsJU+q3eZsMX9n8gwzbAfPIe FZ5ZKhD7BTwawz7RIBd3ytnZ6AJz+bieYbro7f3n2ezUekI+X3vUHna3QhXfNnxdmKSa GruC5wKLi5vH7l7f8UrEOZZpfvz0MdkoaAW324UpmlZ899aQOQLs+ff0Yga62sf1QOu6 jmvOAqC72mjna1FPOhHGOKsFROEGw6T+zjPqIrEAJIdQ6gVMqRzSsWB3a34zgoB92Sn7 Wd5w== X-Gm-Message-State: AOAM533fSBWwf7p4rsIjATyGe+FYkskeOLqaVVzGcJDSvnng2isvAMXM QH82jRqGxKqecfwPI08h7FqS7xecEQDZxg== X-Google-Smtp-Source: ABdhPJxrXpsHHGcwxHwM9cHW0bKK43XSuKFSUfl3enK6KghCIGisNIm8aOEP7IgqhPkJuu79Rt+odQ== X-Received: by 2002:a05:600c:22d8:: with SMTP id 24mr39183585wmg.157.1626910824088; Wed, 21 Jul 2021 16:40:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:23 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 08/12] serve.[ch]: remove "serve_options", split up --advertise-refs code Date: Thu, 22 Jul 2021 01:40:09 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "advertise capabilities" mode of serve.c added in ed10cb952d3 (serve: introduce git-serve, 2018-03-15) is only used by the http-backend.c to call {upload,receive}-pack with the --advertise-refs parameter. See 42526b478e3 (Add stateless RPC options to upload-pack, receive-pack, 2009-10-30). Let's just make cmd_upload_pack() take the two (v2) or three (v2) parameters the the v2/v1 servicing functions need directly, and pass those in via the function signature. The logic of whether daemon mode is implied by the timeout belongs in the v1 function (only used there). Once we split up the "advertise v2 refs" from "serve v2 request" it becomes clear that v2 never cared about those in combination. The only time it mattered was for v1 to emit its ref advertisement, in that case we wanted to emit the smart-http-only "no-done" capability. Since we only do that in the --advertise-refs codepath let's just have it set "do_done" itself in v1's upload_pack() just before send_ref(), at that point --advertise-refs and --stateless-rpc in combination are redundant (the only user is get_info_refs() in http-backend.c), so we can just pass in --advertise-refs only. Since we need to touch all the serve() and advertise_capabilities() codepaths let's rename them to less clever and obvious names, it's been suggested numerous times, the latest of which is [1]'s suggestion for protocol_v2_serve_loop(). Let's go with that. 1. https://lore.kernel.org/git/CAFQ2z_NyGb8rju5CKzmo6KhZXD0Dp21u-BbyCb2aNxLEoSPRJw@mail.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/upload-pack.c | 25 ++++++++++++------------- http-backend.c | 2 +- serve.c | 18 +++++------------- serve.h | 8 ++------ t/helper/test-serve-v2.c | 14 +++++++++----- upload-pack.c | 18 +++++++++++------- upload-pack.h | 10 ++-------- 7 files changed, 42 insertions(+), 53 deletions(-) diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c index 6da8fa2607c..8506030a648 100644 --- a/builtin/upload-pack.c +++ b/builtin/upload-pack.c @@ -16,16 +16,17 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix) { const char *dir; int strict = 0; - struct upload_pack_options opts = { 0 }; - struct serve_options serve_opts = SERVE_OPTIONS_INIT; + int advertise_refs = 0; + int stateless_rpc = 0; + int timeout = 0; struct option options[] = { - OPT_BOOL(0, "stateless-rpc", &opts.stateless_rpc, + OPT_BOOL(0, "stateless-rpc", &stateless_rpc, N_("quit after a single request/response exchange")), - OPT_BOOL(0, "advertise-refs", &opts.advertise_refs, + OPT_BOOL(0, "advertise-refs", &advertise_refs, N_("exit immediately after initial ref advertisement")), OPT_BOOL(0, "strict", &strict, N_("do not try /.git/ if is no Git directory")), - OPT_INTEGER(0, "timeout", &opts.timeout, + OPT_INTEGER(0, "timeout", &timeout, N_("interrupt transfer after seconds of inactivity")), OPT_END() }; @@ -38,9 +39,6 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix) if (argc != 1) usage_with_options(upload_pack_usage, options); - if (opts.timeout) - opts.daemon_mode = 1; - setup_path(); dir = argv[0]; @@ -50,21 +48,22 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix) switch (determine_protocol_version_server()) { case protocol_v2: - serve_opts.advertise_capabilities = opts.advertise_refs; - serve_opts.stateless_rpc = opts.stateless_rpc; - serve(&serve_opts); + if (advertise_refs) + protocol_v2_advertise_capabilities(); + else + protocol_v2_serve_loop(stateless_rpc); break; case protocol_v1: /* * v1 is just the original protocol with a version string, * so just fall through after writing the version string. */ - if (opts.advertise_refs || !opts.stateless_rpc) + if (advertise_refs || !stateless_rpc) packet_write_fmt(1, "version 1\n"); /* fallthrough */ case protocol_v0: - upload_pack(&opts); + upload_pack(advertise_refs, stateless_rpc, timeout); break; case protocol_unknown_version: BUG("unknown protocol version"); diff --git a/http-backend.c b/http-backend.c index b329bf63f09..d37463cec8b 100644 --- a/http-backend.c +++ b/http-backend.c @@ -534,7 +534,7 @@ static void get_info_refs(struct strbuf *hdr, char *arg) if (service_name) { const char *argv[] = {NULL /* service name */, - "--stateless-rpc", "--advertise-refs", + "--advertise-refs", ".", NULL}; struct rpc_service *svc = select_service(hdr, service_name); diff --git a/serve.c b/serve.c index 10209ab237d..cacb0bc4e0e 100644 --- a/serve.c +++ b/serve.c @@ -162,7 +162,7 @@ static int call_command(struct protocol_capability *command, return command->command(r, keys, request); } -static void advertise_capabilities(void) +void protocol_v2_advertise_capabilities(void) { struct strbuf capability = STRBUF_INIT; struct strbuf value = STRBUF_INIT; @@ -359,24 +359,16 @@ static int process_request(void) return 0; } -/* Main serve loop for protocol version 2 */ -void serve(struct serve_options *options) +void protocol_v2_serve_loop(int stateless_rpc) { - if (options->advertise_capabilities || !options->stateless_rpc) { - advertise_capabilities(); - /* - * If only the list of capabilities was requested exit - * immediately after advertising capabilities - */ - if (options->advertise_capabilities) - return; - } + if (!stateless_rpc) + protocol_v2_advertise_capabilities(); /* * If stateless-rpc was requested then exit after * a single request/response exchange */ - if (options->stateless_rpc) { + if (stateless_rpc) { process_request(); } else { for (;;) diff --git a/serve.h b/serve.h index 56da77a87af..f946cf904a2 100644 --- a/serve.h +++ b/serve.h @@ -1,11 +1,7 @@ #ifndef SERVE_H #define SERVE_H -struct serve_options { - unsigned advertise_capabilities; - unsigned stateless_rpc; -}; -#define SERVE_OPTIONS_INIT { 0 } -void serve(struct serve_options *options); +void protocol_v2_advertise_capabilities(void); +void protocol_v2_serve_loop(int stateless_rpc); #endif /* SERVE_H */ diff --git a/t/helper/test-serve-v2.c b/t/helper/test-serve-v2.c index aee35e5aef4..28e905afc36 100644 --- a/t/helper/test-serve-v2.c +++ b/t/helper/test-serve-v2.c @@ -10,12 +10,12 @@ static char const * const serve_usage[] = { int cmd__serve_v2(int argc, const char **argv) { - struct serve_options opts = SERVE_OPTIONS_INIT; - + int stateless_rpc = 0; + int advertise_capabilities = 0; struct option options[] = { - OPT_BOOL(0, "stateless-rpc", &opts.stateless_rpc, + OPT_BOOL(0, "stateless-rpc", &stateless_rpc, N_("quit after a single request/response exchange")), - OPT_BOOL(0, "advertise-capabilities", &opts.advertise_capabilities, + OPT_BOOL(0, "advertise-capabilities", &advertise_capabilities, N_("exit immediately after advertising capabilities")), OPT_END() }; @@ -25,7 +25,11 @@ int cmd__serve_v2(int argc, const char **argv) argc = parse_options(argc, argv, prefix, options, serve_usage, PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN); - serve(&opts); + + if (advertise_capabilities) + protocol_v2_advertise_capabilities(); + else + protocol_v2_serve_loop(stateless_rpc); return 0; } diff --git a/upload-pack.c b/upload-pack.c index 297b76fcb43..48e8bf5694c 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1214,7 +1214,7 @@ static int send_ref(const char *refname, const struct object_id *oid, " allow-tip-sha1-in-want" : "", (data->allow_uor & ALLOW_REACHABLE_SHA1) ? " allow-reachable-sha1-in-want" : "", - data->stateless_rpc ? " no-done" : "", + data->no_done ? " no-done" : "", symref_info.buf, data->allow_filter ? " filter" : "", session_id.buf, @@ -1329,7 +1329,8 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data) return parse_hide_refs_config(var, value, "uploadpack"); } -void upload_pack(struct upload_pack_options *options) +void upload_pack(const int advertise_refs, const int stateless_rpc, + const int timeout) { struct packet_reader reader; struct upload_pack_data data; @@ -1338,14 +1339,17 @@ void upload_pack(struct upload_pack_options *options) git_config(upload_pack_config, &data); - data.stateless_rpc = options->stateless_rpc; - data.daemon_mode = options->daemon_mode; - data.timeout = options->timeout; + data.stateless_rpc = stateless_rpc; + data.timeout = timeout; + if (data.timeout) + data.daemon_mode = 1; head_ref_namespaced(find_symref, &data.symref); - if (options->advertise_refs || !data.stateless_rpc) { + if (advertise_refs || !data.stateless_rpc) { reset_timeout(data.timeout); + if (advertise_refs) + data.no_done = 1; head_ref_namespaced(send_ref, &data); for_each_namespaced_ref(send_ref, &data); advertise_shallow_grafts(1); @@ -1355,7 +1359,7 @@ void upload_pack(struct upload_pack_options *options) for_each_namespaced_ref(check_ref, NULL); } - if (!options->advertise_refs) { + if (!advertise_refs) { packet_reader_init(&reader, 0, NULL, 0, PACKET_READ_CHOMP_NEWLINE | PACKET_READ_DIE_ON_ERR_PACKET); diff --git a/upload-pack.h b/upload-pack.h index 27ddcdc6cb0..a06498bbea7 100644 --- a/upload-pack.h +++ b/upload-pack.h @@ -1,14 +1,8 @@ #ifndef UPLOAD_PACK_H #define UPLOAD_PACK_H -struct upload_pack_options { - int stateless_rpc; - int advertise_refs; - unsigned int timeout; - int daemon_mode; -}; - -void upload_pack(struct upload_pack_options *options); +void upload_pack(const int advertise_refs, const int stateless_rpc, + const int timeout); struct repository; struct strvec; From patchwork Wed Jul 21 23:40:10 2021 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: 12392531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58F84C63797 for ; Wed, 21 Jul 2021 23:40:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4890F61249 for ; Wed, 21 Jul 2021 23:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231317AbhGUW77 (ORCPT ); Wed, 21 Jul 2021 18:59:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231284AbhGUW7v (ORCPT ); Wed, 21 Jul 2021 18:59:51 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89099C061796 for ; Wed, 21 Jul 2021 16:40:26 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id l7so3894428wrv.7 for ; Wed, 21 Jul 2021 16:40:26 -0700 (PDT) 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=ROvVWEQgNBQJB0Q2UUhPlVHl8wCJCFFQGecrdev6tZA=; b=LP47NeEgS0NzL8ICRGGf1vE3tNlld7DF+LEG0xe2+651w9vzoeSLehWNSutNn1sjB9 j5mVV8qHZ/5Dx9lWuWmz4qZRfOiDaByewqIA9JtfvfRbiU0HR4I9dWNDt9Ywty2NWD4d sAFnEdq42jnPatBr5zptzjshchzhQ5DqqKhgksPD9OMlcQvISZvESPCzgSqvZW0ZCFPU B8xH/ICSmUoZeDXsejZFTcE7vQ3tmVJom6ylSCKX2bX02y/5cXJnIhsFt4uzhu8akV1x SqgMqeUcMhYziLNwz5lIftFtxC8qOFvgstijG9KApBK/P/PE0Bp//5F4lWeyP/RnRou6 EZ1g== 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=ROvVWEQgNBQJB0Q2UUhPlVHl8wCJCFFQGecrdev6tZA=; b=HI+uRHahPGE3EAUuUQ4Nex9jiP8z2HKQTMc+jk1Czpa4vf9GG89UJ+2VxZtLUf4/6A n6LCogszXi/Kh4UngJhFzPq9QVOz6Unw0VPgyqW8P6qKsBC1DxRPbcWOrB8+Q3yw3NKQ 0hnwgRcPg5hvNZEEw0DNEXk4Kcl7hps/xUf6UYfnhNm7SWGk6K4KyOMF319IiAQmSkgT MQKwYyjTRSVOtzb0k5KlpEs3aRPQODqVrN8MGdVIflrb96u72+cfKJH5l/o+di+eJc/5 m+aixwTico/Z9loUwokJzBKmIZesEVkUuaLWIwLNK2nfIVe2mLOsWHm/M0Ayzr+TZVy0 dKEA== X-Gm-Message-State: AOAM532ZYYm77XbEspAUmDoaXH9MFcDqJPm2WjfdoeYcG368vqxrUyKp Uvv1PemyocGYy0wS1lZgwZ8gjdMrStnkDA== X-Google-Smtp-Source: ABdhPJzUYckt+jeN1nls6A+hIa7PGFqM/O1MHX/d2/JwRX72+zzkInTjFg42pnCmPCcYhLwb0pL8AA== X-Received: by 2002:adf:a287:: with SMTP id s7mr44537853wra.120.1626910824825; Wed, 21 Jul 2021 16:40:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:24 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 09/12] {upload,receive}-pack tests: add --advertise-refs tests Date: Thu, 22 Jul 2021 01:40:10 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The --advertise-refs option had no explicit tests of its own, only other http tests that would fail at a distance if it it was broken. Let's test its behavior explicitly. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t5555-http-smart-common.sh | 145 +++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100755 t/t5555-http-smart-common.sh diff --git a/t/t5555-http-smart-common.sh b/t/t5555-http-smart-common.sh new file mode 100755 index 00000000000..389ee96987b --- /dev/null +++ b/t/t5555-http-smart-common.sh @@ -0,0 +1,145 @@ +test_description='test functionality common to smart fetch & push' + +. ./test-lib.sh + +test_expect_success 'setup' ' + test_commit --no-tag initial +' + +test_expect_success 'git upload-pack --advertise-refs' ' + cat >expect <<-EOF && + $(git rev-parse HEAD) HEAD + $(git rev-parse HEAD) $(git symbolic-ref HEAD) + 0000 + EOF + + # We only care about GIT_PROTOCOL, not GIT_TEST_PROTOCOL_VERSION + sane_unset GIT_PROTOCOL && + GIT_TEST_PROTOCOL_VERSION=2 \ + git upload-pack --advertise-refs . >out 2>err && + + test-tool pkt-line unpack actual && + test_must_be_empty err && + test_cmp actual expect && + + # The --advertise-refs alias works + git upload-pack --advertise-refs . >out 2>err && + + test-tool pkt-line unpack actual && + test_must_be_empty err && + test_cmp actual expect +' + +test_expect_success 'git upload-pack --advertise-refs: v0' ' + # With no specified protocol + cat >expect <<-EOF && + $(git rev-parse HEAD) HEAD + $(git rev-parse HEAD) $(git symbolic-ref HEAD) + 0000 + EOF + + git upload-pack --advertise-refs . >out 2>err && + test-tool pkt-line unpack actual && + test_must_be_empty err && + test_cmp actual expect && + + # With explicit v0 + GIT_PROTOCOL=version=0 \ + git upload-pack --advertise-refs . >out 2>err && + test-tool pkt-line unpack actual 2>err && + test_must_be_empty err && + test_cmp actual expect + +' + +test_expect_success 'git receive-pack --advertise-refs: v0' ' + # With no specified protocol + cat >expect <<-EOF && + $(git rev-parse HEAD) $(git symbolic-ref HEAD) + 0000 + EOF + + git receive-pack --advertise-refs . >out 2>err && + test-tool pkt-line unpack actual && + test_must_be_empty err && + test_cmp actual expect && + + # With explicit v0 + GIT_PROTOCOL=version=0 \ + git receive-pack --advertise-refs . >out 2>err && + test-tool pkt-line unpack actual 2>err && + test_must_be_empty err && + test_cmp actual expect + +' + +test_expect_success 'git upload-pack --advertise-refs: v1' ' + # With no specified protocol + cat >expect <<-EOF && + version 1 + $(git rev-parse HEAD) HEAD + $(git rev-parse HEAD) $(git symbolic-ref HEAD) + 0000 + EOF + + GIT_PROTOCOL=version=1 \ + git upload-pack --advertise-refs . >out && + + test-tool pkt-line unpack actual 2>err && + test_must_be_empty err && + test_cmp actual expect +' + +test_expect_success 'git receive-pack --advertise-refs: v1' ' + # With no specified protocol + cat >expect <<-EOF && + version 1 + $(git rev-parse HEAD) $(git symbolic-ref HEAD) + 0000 + EOF + + GIT_PROTOCOL=version=1 \ + git receive-pack --advertise-refs . >out && + + test-tool pkt-line unpack actual 2>err && + test_must_be_empty err && + test_cmp actual expect +' + +test_expect_success 'git upload-pack --advertise-refs: v2' ' + cat >expect <<-EOF && + version 2 + agent=FAKE + ls-refs=unborn + fetch=shallow wait-for-done + server-option + object-format=$(test_oid algo) + object-info + 0000 + EOF + + GIT_PROTOCOL=version=2 \ + GIT_USER_AGENT=FAKE \ + git upload-pack --advertise-refs . >out 2>err && + + test-tool pkt-line unpack actual && + test_must_be_empty err && + test_cmp actual expect +' + +test_expect_success 'git receive-pack --advertise-refs: v2' ' + # There is no v2 yet for receive-pack, implicit v0 + cat >expect <<-EOF && + $(git rev-parse HEAD) $(git symbolic-ref HEAD) + 0000 + EOF + + GIT_PROTOCOL=version=2 \ + git receive-pack --advertise-refs . >out 2>err && + + test-tool pkt-line unpack actual && + test_must_be_empty err && + test_cmp actual expect +' + +test_done From patchwork Wed Jul 21 23:40:11 2021 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: 12392533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34A5BC6377E for ; Wed, 21 Jul 2021 23:40:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F4C360FDA for ; Wed, 21 Jul 2021 23:40:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231307AbhGUW76 (ORCPT ); Wed, 21 Jul 2021 18:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231272AbhGUW7x (ORCPT ); Wed, 21 Jul 2021 18:59:53 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C090C061798 for ; Wed, 21 Jul 2021 16:40:27 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 14-20020a05600c028eb0290228f19cb433so500078wmk.0 for ; Wed, 21 Jul 2021 16:40:27 -0700 (PDT) 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=IjCaLSGbAjqhHi6teFpMeBlb6dBdZbPdb7mwWDfoaPU=; b=mQe1RRtJq1IdQ0NSepenoqoCUckhPtcam4+JrxM3rdq8+oVJcES+TkY/uECXSE5Gza LE3O2dYnsrXFoT+4iDPeVNK6ok64qKzGh4IBwS7b7ITd9oyUoWpab4sk3Xd1EMcwtGVr UvfakpOYs56/MYBySlmZDCjPx8JEGVKFXtHI8kS7S4YU+PRldlYboox7qmpWzNUq6Pwk 1sPlFWeunreuerVVAUyj+JVfgZgM1MKu2ZFrQt4PgvcQeKyFfEZoV019tuALn+tyXImx UyVLr6TsGg4xueaShELn4/ZTK/0/Tz72mJYL5MOCCWjE14xbtHBy2ss5aneCH3zuYBtx f6YQ== 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=IjCaLSGbAjqhHi6teFpMeBlb6dBdZbPdb7mwWDfoaPU=; b=aldfSmf3FMyp5MMxWxSbL6bTB2RDiaId6Tf5iXcnYV0jUrQW6w084i9+4tRsAROzRe bdrIFoYdy5nCv9tSRfVmpnmY8R+KD95icW/I8kwZMrRio0P0+KBZRS1QVwJ+9K6jc6xJ Kum61fTb+cNmgKXE0m9rbnWJ8DQpR+3flZNUSQxOZ7RhM1N4uSopumTttULbyXxZVNFe fGLfAI0kt2nqCgxpziSs/WmbIjpcNjXay8B5MKSkDuF9gexgYnpAyKEUV2MPGAQUp8+c mVPVGljvj4YTErnocHQmRTj6FBBWcv00vK31PpTW2kVmofHT4L29yn+cDWuFmPqS+Sji Hiyg== X-Gm-Message-State: AOAM531tj8C1yOGET1HubhwGPyxjuNonrU+iwHmn3jdkr6vp1S+aWbbm QHMv4T79I0SosYJbGLK6KXZe6ijRHN6vFg== X-Google-Smtp-Source: ABdhPJyxARqZ2vO1iXi/lH0YU5MMGk3HQrncySzi89NV5b94ndifh81LBZ3Ow+D6Eyur2w90tRNGcg== X-Received: by 2002:a7b:c7cb:: with SMTP id z11mr6326223wmk.102.1626910825696; Wed, 21 Jul 2021 16:40:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 10/12] upload-pack: document and rename --advertise-refs Date: Thu, 22 Jul 2021 01:40:11 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The --advertise-refs documentation in git-upload-pack added in 9812f2136b3 (upload-pack.c: use parse-options API, 2016-05-31) hasn't been entirely true ever since v2 support was implemented in e52449b6722 (connect: request remote refs using v2, 2018-03-15). Under v2 we don't advertise the refs at all, but rather dump the capabilities header. This option has always been an obscure internal implementation detail, it wasn't even documented for git-receive-pack. Since it has exactly one user let's rename it to --http-backend-info-refs, which is more accurate and points the reader in the right direction. Let's also cross-link this from the protocol v1 and v2 documentation. I'm retaining a hidden --advertise-refs alias in case there's any external users of this, and making both options hidden to the bash completion (as with most other internal-only options). Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-receive-pack.txt | 5 +++++ Documentation/git-upload-pack.txt | 12 ++++++++---- Documentation/technical/http-protocol.txt | 3 +++ Documentation/technical/protocol-v2.txt | 3 +++ builtin/receive-pack.c | 3 ++- builtin/upload-pack.c | 5 +++-- http-backend.c | 2 +- t/t5555-http-smart-common.sh | 14 ++++++++++++++ 8 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Documentation/git-receive-pack.txt b/Documentation/git-receive-pack.txt index 25702ed7307..014a78409b9 100644 --- a/Documentation/git-receive-pack.txt +++ b/Documentation/git-receive-pack.txt @@ -41,6 +41,11 @@ OPTIONS :: The repository to sync into. +--http-backend-info-refs:: + Used by linkgit:git-http-backend[1] to serve up + `$GIT_URL/info/refs?service=git-receive-pack` requests. See + `--http-backend-info-refs` in linkgit:git-upload-pack[1]. + PRE-RECEIVE HOOK ---------------- Before any ref is updated, if $GIT_DIR/hooks/pre-receive file exists diff --git a/Documentation/git-upload-pack.txt b/Documentation/git-upload-pack.txt index 9822c1eb1ad..739416ec83d 100644 --- a/Documentation/git-upload-pack.txt +++ b/Documentation/git-upload-pack.txt @@ -36,10 +36,14 @@ OPTIONS This fits with the HTTP POST request processing model where a program may read the request, write a response, and must exit. ---advertise-refs:: - Only the initial ref advertisement is output, and the program exits - immediately. This fits with the HTTP GET request model, where - no request content is received but a response must be produced. +--http-backend-info-refs:: + Used by linkgit:git-http-backend[1] to serve up + `$GIT_URL/info/refs?service=git-upload-pack` requests. See + "Smart Clients" in link:technical/http-protocol.html[the HTTP + transfer protocols] documentation and "HTTP Transport" in + link:technical/protocol-v2.html[the Git Wire Protocol, Version + 2] documentation. Also understood by + linkgit:git-receive-pack[1]. :: The repository to sync from. diff --git a/Documentation/technical/http-protocol.txt b/Documentation/technical/http-protocol.txt index 96d89ea9b22..cc5126cfeda 100644 --- a/Documentation/technical/http-protocol.txt +++ b/Documentation/technical/http-protocol.txt @@ -225,6 +225,9 @@ The client may send Extra Parameters (see Documentation/technical/pack-protocol.txt) as a colon-separated string in the Git-Protocol HTTP header. +Uses the `--http-backend-info-refs` option to +linkgit:git-upload-pack[1]. + Dumb Server Response ^^^^^^^^^^^^^^^^^^^^ Dumb servers MUST respond with the dumb server reply format. diff --git a/Documentation/technical/protocol-v2.txt b/Documentation/technical/protocol-v2.txt index 1040d853198..213538f1d0e 100644 --- a/Documentation/technical/protocol-v2.txt +++ b/Documentation/technical/protocol-v2.txt @@ -81,6 +81,9 @@ A v2 server would reply: Subsequent requests are then made directly to the service `$GIT_URL/git-upload-pack`. (This works the same for git-receive-pack). +Uses the `--http-backend-info-refs` option to +linkgit:git-upload-pack[1]. + Capability Advertisement ------------------------ diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index a34742513ac..b12820dbd6c 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -2478,7 +2478,8 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix) struct option options[] = { OPT__QUIET(&quiet, N_("quiet")), OPT_HIDDEN_BOOL(0, "stateless-rpc", &stateless_rpc, NULL), - OPT_HIDDEN_BOOL(0, "advertise-refs", &advertise_refs, NULL), + OPT_HIDDEN_BOOL(0, "http-backend-info-refs", &advertise_refs, NULL), + OPT_ALIAS(0, "advertise-refs", "http-backend-info-refs"), OPT_HIDDEN_BOOL(0, "reject-thin-pack-for-testing", &reject_thin, NULL), OPT_END() }; diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c index 8506030a648..125af53885f 100644 --- a/builtin/upload-pack.c +++ b/builtin/upload-pack.c @@ -22,8 +22,9 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix) struct option options[] = { OPT_BOOL(0, "stateless-rpc", &stateless_rpc, N_("quit after a single request/response exchange")), - OPT_BOOL(0, "advertise-refs", &advertise_refs, - N_("exit immediately after initial ref advertisement")), + OPT_HIDDEN_BOOL(0, "http-backend-info-refs", &advertise_refs, + N_("serve up the info/refs for git-http-backend")), + OPT_ALIAS(0, "advertise-refs", "http-backend-info-refs"), OPT_BOOL(0, "strict", &strict, N_("do not try /.git/ if is no Git directory")), OPT_INTEGER(0, "timeout", &timeout, diff --git a/http-backend.c b/http-backend.c index d37463cec8b..838374edb91 100644 --- a/http-backend.c +++ b/http-backend.c @@ -534,7 +534,7 @@ static void get_info_refs(struct strbuf *hdr, char *arg) if (service_name) { const char *argv[] = {NULL /* service name */, - "--advertise-refs", + "--http-backend-info-refs", ".", NULL}; struct rpc_service *svc = select_service(hdr, service_name); diff --git a/t/t5555-http-smart-common.sh b/t/t5555-http-smart-common.sh index 389ee96987b..8d9d6a556f0 100755 --- a/t/t5555-http-smart-common.sh +++ b/t/t5555-http-smart-common.sh @@ -6,6 +6,20 @@ test_expect_success 'setup' ' test_commit --no-tag initial ' +test_expect_success 'git upload-pack --http-backend-info-refs and --advertise-refs are aliased' ' + git upload-pack --http-backend-info-refs . >expected 2>err.expected && + git upload-pack --advertise-refs . >actual 2>err.actual && + test_cmp err.expected err.actual && + test_cmp expected actual +' + +test_expect_success 'git receive-pack --http-backend-info-refs and --advertise-refs are aliased' ' + git receive-pack --http-backend-info-refs . >expected 2>err.expected && + git receive-pack --advertise-refs . >actual 2>err.actual && + test_cmp err.expected err.actual && + test_cmp expected actual +' + test_expect_success 'git upload-pack --advertise-refs' ' cat >expect <<-EOF && $(git rev-parse HEAD) HEAD From patchwork Wed Jul 21 23:40:12 2021 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: 12392537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E25A8C63798 for ; Wed, 21 Jul 2021 23:40:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA77160FDA for ; Wed, 21 Jul 2021 23:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231319AbhGUXAA (ORCPT ); Wed, 21 Jul 2021 19:00:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231288AbhGUW7y (ORCPT ); Wed, 21 Jul 2021 18:59:54 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54118C06179A for ; Wed, 21 Jul 2021 16:40:28 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id n1so3879088wri.10 for ; Wed, 21 Jul 2021 16:40:28 -0700 (PDT) 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=fnPVSSmamXFCgSHV5ypFYK1ExGvlZhS63QWQKAgXhkM=; b=MkeoTZafOQoND681y5T6HuAJaXhr6jvo+ZLcDxvfE2YDpf45h+NtMCxKhWj6SinHex Twbs6gqqgydk85SlCbYaXkT05qdgwORM3rQWjjkToJixMGmuAHJxHzSAWz7mTsxtB8xd WIywoyLtksWWtT2WpbFNz78D8hCBgQ0PmZvPBoH6j+0cy3D06Q3+qdT7DiMn/kzUPn+b Qc5CbsF8fnYakv5YpFg310QrgiaKh+wKzwy3F+dqaD3YsT1ih40SJd1Y3mDqHNhXZQcn pMd2rj2OxBzzDi1cb5f0ghIleWlQvppnM4W+P03RYsIAiVaqXU8dzRxrnChOfy75NbD0 uggg== 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=fnPVSSmamXFCgSHV5ypFYK1ExGvlZhS63QWQKAgXhkM=; b=smHRV9sw559BH+I46L3dPzJ9MXRFIupNeDgHu2s+rQGZlk3SeFUXfnwzwNnOqSTSTA +ZtzcOqWwjWW5IbiScDoVYHJwsuQWti/eNGFEpk7kPr3G2FrbrFFjLTA/XmmVV8lrFmX i78AU0t7nk/y77tkk6dCZrpotmSrQE2sB84uhjw0T0HsNIXCLSNVqQLtIlo+FJ76Tby/ uktKPUZKEN+kCfdWtImWZIO/qewdVj8GPwfaIodYovC23zcSHpV+LZ8smsmR6ISa3CF1 Xd2ROkK4Lm3prPKoNanuFT0wxHgBAThH4HGSp5u0ovaiPDN8bCP5hCiVv6EcaEDNswfO /QAA== X-Gm-Message-State: AOAM533TQwqTCmvQ8I23zlTxdeiV9NfqG8rNekXty+HgvzdGxVM/pxE2 Ib5fQ6tkmgCy1M4YUiihssEUO2sc7XBiAg== X-Google-Smtp-Source: ABdhPJwXQuYFsh3UPgbzg2O4r1apgDYYOaND/IH5LnzShC+AX07/6DVwaHKzHO64jKo/UU3uL+ErMA== X-Received: by 2002:adf:f109:: with SMTP id r9mr26851496wro.370.1626910826608; Wed, 21 Jul 2021 16:40:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 11/12] upload-pack.c: convert to new serve.c "startup" config cb Date: Thu, 22 Jul 2021 01:40:12 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Convert the config reading code in upload-pack.c to use the new "startup_config" callback when we're using the v2 protocol, and lightly fake up the same when we're using v0 and v1. Before the series that fixed 08450ef7918 (upload-pack: clear filter_options for each v2 fetch command, 2020-05-08) landed, most of what's now "struct upload_pack_data" used to be static variables at the top of this file. This moves some of them back. See f203a88cf14 (upload-pack: move keepalive to upload_pack_data, 2020-06-04), f1514c6aad0 (upload-pack: move allow_unadvertised_object_request to upload_pack_data, 2020-06-11) etc. I think this makes it easier to understand the this code, as we're now clearly separating data and config that changes on a request-to-request basis (see 08450ef7918), and the sort of config that serve.c's "startup_config" is aimed at. Thus it's clear that the "allow_uor" passed to functions like "is_our_ref()" is constant after startup (usually it'll never change for a given server's configuration, or change once). This requires a very light compatibility layer with the serve.c callback mechanism in the form of "upload_pack" for the v0 and v1 protocols. Signed-off-by: Ævar Arnfjörð Bjarmason --- serve.c | 1 + upload-pack.c | 133 +++++++++++++++++++++++++++++--------------------- upload-pack.h | 2 + 3 files changed, 80 insertions(+), 56 deletions(-) diff --git a/serve.c b/serve.c index cacb0bc4e0e..162e8cea550 100644 --- a/serve.c +++ b/serve.c @@ -112,6 +112,7 @@ static struct protocol_capability capabilities[] = { }, { .name = "fetch", + .startup_config = serve_upload_pack_startup_config, .advertise = upload_pack_advertise, .command = upload_pack_v2, }, diff --git a/upload-pack.c b/upload-pack.c index 48e8bf5694c..b9cfc09795b 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -52,6 +52,19 @@ enum allow_uor { ALLOW_ANY_SHA1 = 0x07 }; +/* + * "Global" configuration that won't be affected by the type of + * request we're doing, or by other request data in "struct + * upload_pack_data" below. + */ +static int v1_have_startup_config; +static int config_keepalive_secs = 5; +static enum allow_uor config_allow_uor; +static unsigned config_advertise_sid; +static const char *config_pack_objects_hook; +static unsigned config_v2_allow_ref_in_want; +static unsigned config_v2_allow_sideband_all; + /* * Please annotate, and if possible group together, fields used only * for protocol v0 or only for protocol v2. @@ -70,7 +83,6 @@ struct upload_pack_data { timestamp_t deepen_since; int deepen_rev_list; int deepen_relative; - int keepalive; int shallow_nr; timestamp_t oldest_have; @@ -85,15 +97,12 @@ struct upload_pack_data { int use_sideband; struct string_list uri_protocols; - enum allow_uor allow_uor; struct list_objects_filter_options filter_options; struct string_list allowed_filters; struct packet_writer writer; - const char *pack_objects_hook; - unsigned stateless_rpc : 1; /* v0 only */ unsigned no_done : 1; /* v0 only */ unsigned daemon_mode : 1; /* v0 only */ @@ -109,9 +118,6 @@ struct upload_pack_data { unsigned long tree_filter_max_depth; unsigned done : 1; /* v2 only */ - unsigned allow_ref_in_want : 1; /* v2 only */ - unsigned allow_sideband_all : 1; /* v2 only */ - unsigned advertise_sid : 1; }; static void upload_pack_data_init(struct upload_pack_data *data) @@ -141,9 +147,6 @@ static void upload_pack_data_init(struct upload_pack_data *data) data->allow_filter_fallback = 1; data->tree_filter_max_depth = ULONG_MAX; packet_writer_init(&data->writer, 1); - - data->keepalive = 5; - data->advertise_sid = 0; } static void upload_pack_data_clear(struct upload_pack_data *data) @@ -158,8 +161,6 @@ static void upload_pack_data_clear(struct upload_pack_data *data) object_array_clear(&data->extra_edge_obj); list_objects_filter_release(&data->filter_options); string_list_clear(&data->allowed_filters, 0); - - free((char *)data->pack_objects_hook); } static void reset_timeout(unsigned int timeout) @@ -277,10 +278,10 @@ static void create_pack_file(struct upload_pack_data *pack_data, int i; FILE *pipe_fd; - if (!pack_data->pack_objects_hook) + if (!config_pack_objects_hook) pack_objects.git_cmd = 1; else { - strvec_push(&pack_objects.args, pack_data->pack_objects_hook); + strvec_push(&pack_objects.args, config_pack_objects_hook); strvec_push(&pack_objects.args, "git"); pack_objects.use_shell = 1; } @@ -371,9 +372,9 @@ static void create_pack_file(struct upload_pack_data *pack_data, if (!pollsize) break; - polltimeout = pack_data->keepalive < 0 + polltimeout = config_keepalive_secs < 0 ? -1 - : 1000 * pack_data->keepalive; + : 1000 * config_keepalive_secs; ret = poll(pfd, pollsize, polltimeout); @@ -581,9 +582,9 @@ static int get_common_commits(struct upload_pack_data *data, } } -static int is_our_ref(struct object *o, enum allow_uor allow_uor) +static int is_our_ref(struct object *o) { - int allow_hidden_ref = (allow_uor & + int allow_hidden_ref = (config_allow_uor & (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1)); return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF); } @@ -593,8 +594,7 @@ static int is_our_ref(struct object *o, enum allow_uor allow_uor) */ static int do_reachable_revlist(struct child_process *cmd, struct object_array *src, - struct object_array *reachable, - enum allow_uor allow_uor) + struct object_array *reachable) { static const char *argv[] = { "rev-list", "--stdin", NULL, @@ -627,14 +627,14 @@ static int do_reachable_revlist(struct child_process *cmd, continue; if (reachable && o->type == OBJ_COMMIT) o->flags &= ~TMP_MARK; - if (!is_our_ref(o, allow_uor)) + if (!is_our_ref(o)) continue; if (fprintf(cmd_in, "^%s\n", oid_to_hex(&o->oid)) < 0) goto error; } for (i = 0; i < src->nr; i++) { o = src->objects[i].item; - if (is_our_ref(o, allow_uor)) { + if (is_our_ref(o)) { if (reachable) add_object_array(o, NULL, reachable); continue; @@ -671,8 +671,7 @@ static int get_reachable_list(struct upload_pack_data *data, char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */ const unsigned hexsz = the_hash_algo->hexsz; - if (do_reachable_revlist(&cmd, &data->shallows, reachable, - data->allow_uor) < 0) + if (do_reachable_revlist(&cmd, &data->shallows, reachable) < 0) return -1; while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) { @@ -703,13 +702,13 @@ static int get_reachable_list(struct upload_pack_data *data, return 0; } -static int has_unreachable(struct object_array *src, enum allow_uor allow_uor) +static int has_unreachable(struct object_array *src) { struct child_process cmd = CHILD_PROCESS_INIT; char buf[1]; int i; - if (do_reachable_revlist(&cmd, src, NULL, allow_uor) < 0) + if (do_reachable_revlist(&cmd, src, NULL) < 0) return 1; /* @@ -748,9 +747,9 @@ static void check_non_tip(struct upload_pack_data *data) * uploadpack.allowReachableSHA1InWant, * non-tip requests can never happen. */ - if (!data->stateless_rpc && !(data->allow_uor & ALLOW_REACHABLE_SHA1)) + if (!data->stateless_rpc && !(config_allow_uor & ALLOW_REACHABLE_SHA1)) goto error; - if (!has_unreachable(&data->want_obj, data->allow_uor)) + if (!has_unreachable(&data->want_obj)) /* All the non-tip ones are ancestors of what we advertised */ return; @@ -758,7 +757,7 @@ static void check_non_tip(struct upload_pack_data *data) /* Pick one of them (we know there at least is one) */ for (i = 0; i < data->want_obj.nr; i++) { struct object *o = data->want_obj.objects[i].item; - if (!is_our_ref(o, data->allow_uor)) { + if (!is_our_ref(o)) { packet_writer_error(&data->writer, "upload-pack: not our ref %s", oid_to_hex(&o->oid)); @@ -1123,8 +1122,8 @@ static void receive_needs(struct upload_pack_data *data, } if (!(o->flags & WANTED)) { o->flags |= WANTED; - if (!((data->allow_uor & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1 - || is_our_ref(o, data->allow_uor))) + if (!((config_allow_uor & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1 + || is_our_ref(o))) has_non_tip = 1; add_object_array(o, NULL, &data->want_obj); } @@ -1184,7 +1183,7 @@ static void format_symref_info(struct strbuf *buf, struct string_list *symref) } static void format_session_id(struct strbuf *buf, struct upload_pack_data *d) { - if (d->advertise_sid) + if (config_advertise_sid) strbuf_addf(buf, " session-id=%s", trace2_session_id()); } @@ -1210,9 +1209,9 @@ static int send_ref(const char *refname, const struct object_id *oid, packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s%s object-format=%s agent=%s\n", oid_to_hex(oid), refname_nons, 0, capabilities, - (data->allow_uor & ALLOW_TIP_SHA1) ? + (config_allow_uor & ALLOW_TIP_SHA1) ? " allow-tip-sha1-in-want" : "", - (data->allow_uor & ALLOW_REACHABLE_SHA1) ? + (config_allow_uor & ALLOW_REACHABLE_SHA1) ? " allow-reachable-sha1-in-want" : "", data->no_done ? " no-done" : "", symref_info.buf, @@ -1282,46 +1281,66 @@ static int parse_object_filter_config(const char *var, const char *value, return 0; } -static int upload_pack_config(const char *var, const char *value, void *cb_data) +static int upload_pack_startup_config(const char *var, const char *value, + void *cb_data) { - struct upload_pack_data *data = cb_data; - if (!strcmp("uploadpack.allowtipsha1inwant", var)) { if (git_config_bool(var, value)) - data->allow_uor |= ALLOW_TIP_SHA1; + config_allow_uor |= ALLOW_TIP_SHA1; else - data->allow_uor &= ~ALLOW_TIP_SHA1; + config_allow_uor &= ~ALLOW_TIP_SHA1; } else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) { if (git_config_bool(var, value)) - data->allow_uor |= ALLOW_REACHABLE_SHA1; + config_allow_uor |= ALLOW_REACHABLE_SHA1; else - data->allow_uor &= ~ALLOW_REACHABLE_SHA1; + config_allow_uor &= ~ALLOW_REACHABLE_SHA1; } else if (!strcmp("uploadpack.allowanysha1inwant", var)) { if (git_config_bool(var, value)) - data->allow_uor |= ALLOW_ANY_SHA1; + config_allow_uor |= ALLOW_ANY_SHA1; else - data->allow_uor &= ~ALLOW_ANY_SHA1; + config_allow_uor &= ~ALLOW_ANY_SHA1; } else if (!strcmp("uploadpack.keepalive", var)) { - data->keepalive = git_config_int(var, value); - if (!data->keepalive) - data->keepalive = -1; - } else if (!strcmp("uploadpack.allowfilter", var)) { - data->allow_filter = git_config_bool(var, value); - } else if (!strcmp("uploadpack.allowrefinwant", var)) { - data->allow_ref_in_want = git_config_bool(var, value); - } else if (!strcmp("uploadpack.allowsidebandall", var)) { - data->allow_sideband_all = git_config_bool(var, value); + config_keepalive_secs = git_config_int(var, value); + if (!config_keepalive_secs) + config_keepalive_secs = -1; } else if (!strcmp("core.precomposeunicode", var)) { precomposed_unicode = git_config_bool(var, value); } else if (!strcmp("transfer.advertisesid", var)) { - data->advertise_sid = git_config_bool(var, value); + config_advertise_sid = git_config_bool(var, value); } if (current_config_scope() != CONFIG_SCOPE_LOCAL && current_config_scope() != CONFIG_SCOPE_WORKTREE) { if (!strcmp("uploadpack.packobjectshook", var)) - return git_config_string(&data->pack_objects_hook, var, value); + return git_config_string(&config_pack_objects_hook, var, value); } + return 0; +} + +static int upload_pack_startup_config_v2_only(const char *var, + const char *value, void *cb_data) +{ + if (!strcmp("uploadpack.allowrefinwant", var)) + config_v2_allow_ref_in_want = git_config_bool(var, value); + else if (!strcmp("uploadpack.allowsidebandall", var)) + config_v2_allow_sideband_all = git_config_bool(var, value); + return 0; +} + +int serve_upload_pack_startup_config(const char *var, const char *value, void *data) +{ + upload_pack_startup_config(var, value, data); + upload_pack_startup_config_v2_only(var, value, data); + return 0; +} + +static int upload_pack_config(const char *var, const char *value, + void *cb_data) +{ + struct upload_pack_data *data = cb_data; + + if (!strcmp("uploadpack.allowfilter", var)) + data->allow_filter = git_config_bool(var, value); if (parse_object_filter_config(var, value, data) < 0) return -1; @@ -1337,6 +1356,8 @@ void upload_pack(const int advertise_refs, const int stateless_rpc, upload_pack_data_init(&data); + if (!v1_have_startup_config++) + git_config(upload_pack_startup_config, NULL); git_config(upload_pack_config, &data); data.stateless_rpc = stateless_rpc; @@ -1472,7 +1493,7 @@ static void process_args(struct packet_reader *request, /* process want */ if (parse_want(&data->writer, arg, &data->want_obj)) continue; - if (data->allow_ref_in_want && + if (config_v2_allow_ref_in_want && parse_want_ref(&data->writer, arg, &data->wanted_refs, &data->want_obj)) continue; @@ -1530,7 +1551,7 @@ static void process_args(struct packet_reader *request, } if ((git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) || - data->allow_sideband_all) && + config_v2_allow_sideband_all) && !strcmp(arg, "sideband-all")) { data->writer.use_sideband = 1; continue; diff --git a/upload-pack.h b/upload-pack.h index a06498bbea7..52011d9ecff 100644 --- a/upload-pack.h +++ b/upload-pack.h @@ -13,5 +13,7 @@ int upload_pack_v2(struct repository *r, struct strvec *keys, struct strbuf; int upload_pack_advertise(struct repository *r, struct strbuf *value); +int serve_upload_pack_startup_config(const char *var, const char *value, + void *data); #endif /* UPLOAD_PACK_H */ From patchwork Wed Jul 21 23:40:13 2021 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: 12392535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF8C3C63793 for ; Wed, 21 Jul 2021 23:40:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4EB760FDA for ; Wed, 21 Jul 2021 23:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231318AbhGUXAC (ORCPT ); Wed, 21 Jul 2021 19:00:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231293AbhGUW7y (ORCPT ); Wed, 21 Jul 2021 18:59:54 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20601C06179B for ; Wed, 21 Jul 2021 16:40:29 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id d2so3952648wrn.0 for ; Wed, 21 Jul 2021 16:40:29 -0700 (PDT) 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=86QPuNHoNiJaJIf2Wuf3PKYrDObLqDNb+SsZ42wIYp0=; b=h31gVjzVa+Sm687L7xD8QnKy6emBg70zHw83+6M9Tyu+yh32fM3wr+PbEII5ImCVna J5oHqmz3wSeGWNi+Mot9/ro60Gyu3CEGOWKYmDhBx3TWu8EwFU/oGTkdYCB2bXRwhmwC mam6kkk0IkMEn5hfuAmOWR40v2MhLvMINGfYQc/nRoQKgq/2ItfPwJY9a5tQ3OtWYNoE m+MLeidbPOmhDA82oH4ybicc4ilVOWkKk1XnDjFUeF7dy+earPlD1F5CBfntd+IfO+7/ A+2rIkNihKQI0Rx2LWuLs1+36Z6wrUquDlAozHiO/nDcv59Ah3yHJF7B7JVtTTZofknS b8uA== 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=86QPuNHoNiJaJIf2Wuf3PKYrDObLqDNb+SsZ42wIYp0=; b=Q17hV/xQBT5QVvjty+BateUquOF8pBWIp0e9Th9t1e07g1Pi2zlQ0g1f38g9Kfv2Sk MOmZY2FujDW662XA/EUUBw2XmZoO4m48uol2MzXxw+G+9F6fedwANXbtq2i0HT8QNI+w stzK3gmisvKFZjS9wpAUZ6AbhYMHQLwSK8e9JT30GU3cHas8bsqSj2FD7vKcwqlHJc37 2GboVE4cfe6nGWHsI6Bw2PSnP+arKz4MrVuNThpuSuesOtXuh0MRZmVa016B9u1vFdin U6QzfxXtU5O0ULTpbh9LnFdPSqKOKTY/I24Te7ptnNeeoAfygGeLXy+mEqabbZlRiUJN 0wkg== X-Gm-Message-State: AOAM530WG+2P6hl3eKzUqmHA3htRvCmh3Jjdt2EcQ/0vUW5BeCHRxMEM +RTUaI73UPMWxTyzKoaVc7k5MbFt8soC3g== X-Google-Smtp-Source: ABdhPJxrVKBHCiiuYKwU5Y2CIMeKHkJbR902OhdEJ4sQbcN79xzZwaQ9Jqh1hgp+Fh8VlbfPidJjfw== X-Received: by 2002:adf:9d8d:: with SMTP id p13mr45947684wre.300.1626910827419; Wed, 21 Jul 2021 16:40:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o19sm1145649wmc.12.2021.07.21.16.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 16:40:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan , Josh Steadmon , Bruno Albuquerque , Jeff King , Eric Sunshine , Han-Wen Nienhuys , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 12/12] serve.[ch]: don't pass "struct strvec *keys" to commands Date: Thu, 22 Jul 2021 01:40:13 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.955.ge7c5360f7e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The serve.c API added in ed10cb952d3 (serve: introduce git-serve, 2018-03-15) was passing in the raw capabilities "keys", but nothing downstream of it ever used them. Let's remove that code because it's not needed, and because if and when we need to pass data about the advertisement (I have some WIP patches for that), it makes much more sense to have the serve.c parse the capabilities, and then pass specific information we need down than expecting its API users to re-do their own parsing of the raw data. Signed-off-by: Ævar Arnfjörð Bjarmason --- ls-refs.c | 3 +-- ls-refs.h | 4 +--- protocol-caps.c | 3 +-- protocol-caps.h | 4 +--- serve.c | 7 +++---- upload-pack.c | 3 +-- upload-pack.h | 4 +--- 7 files changed, 9 insertions(+), 19 deletions(-) diff --git a/ls-refs.c b/ls-refs.c index 02fbcfd9bde..787e3849d97 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -127,8 +127,7 @@ static int ls_refs_config(const char *var, const char *value, void *data) return parse_hide_refs_config(var, value, "uploadpack"); } -int ls_refs(struct repository *r, struct strvec *keys, - struct packet_reader *request) +int ls_refs(struct repository *r, struct packet_reader *request) { struct ls_refs_data data; diff --git a/ls-refs.h b/ls-refs.h index 5fcab0d1dca..32f9e0eddd0 100644 --- a/ls-refs.h +++ b/ls-refs.h @@ -2,10 +2,8 @@ #define LS_REFS_H struct repository; -struct strvec; struct packet_reader; -int ls_refs(struct repository *r, struct strvec *keys, - struct packet_reader *request); +int ls_refs(struct repository *r, struct packet_reader *request); int ls_refs_startup_config(const char *var, const char *value, void *data); int ls_refs_advertise(struct repository *r, struct strbuf *value); diff --git a/protocol-caps.c b/protocol-caps.c index 901b6795e42..bbde91810ac 100644 --- a/protocol-caps.c +++ b/protocol-caps.c @@ -75,8 +75,7 @@ static void send_info(struct repository *r, struct packet_writer *writer, strbuf_release(&send_buffer); } -int cap_object_info(struct repository *r, struct strvec *keys, - struct packet_reader *request) +int cap_object_info(struct repository *r, struct packet_reader *request) { struct requested_info info; struct packet_writer writer; diff --git a/protocol-caps.h b/protocol-caps.h index 0a9f49df115..15c4550360c 100644 --- a/protocol-caps.h +++ b/protocol-caps.h @@ -2,9 +2,7 @@ #define PROTOCOL_CAPS_H struct repository; -struct strvec; struct packet_reader; -int cap_object_info(struct repository *r, struct strvec *keys, - struct packet_reader *request); +int cap_object_info(struct repository *r, struct packet_reader *request); #endif /* PROTOCOL_CAPS_H */ diff --git a/serve.c b/serve.c index 162e8cea550..3e82178c0f7 100644 --- a/serve.c +++ b/serve.c @@ -50,7 +50,7 @@ static int session_id_advertise(struct repository *r, struct strbuf *value) } typedef int (*advertise_fn_t)(struct repository *r, struct strbuf *value); -typedef int (*command_fn_t)(struct repository *r, struct strvec *keys, +typedef int (*command_fn_t)(struct repository *r, struct packet_reader *request); struct protocol_capability { @@ -89,8 +89,7 @@ struct protocol_capability { /* * Function called when a client requests the capability as a command. - * The function will be provided the capabilities requested via 'keys' - * as well as a struct packet_reader 'request' which the command should + * Will be provided a struct packet_reader 'request' which it should * use to read the command specific part of the request. Every command * MUST read until a flush packet is seen before sending a response. * @@ -160,7 +159,7 @@ static int call_command(struct protocol_capability *command, read_startup_config(command); - return command->command(r, keys, request); + return command->command(r, request); } void protocol_v2_advertise_capabilities(void) diff --git a/upload-pack.c b/upload-pack.c index b9cfc09795b..097b982c010 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1680,8 +1680,7 @@ enum fetch_state { FETCH_DONE, }; -int upload_pack_v2(struct repository *r, struct strvec *keys, - struct packet_reader *request) +int upload_pack_v2(struct repository *r, 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 52011d9ecff..0ae817c1d0d 100644 --- a/upload-pack.h +++ b/upload-pack.h @@ -5,10 +5,8 @@ void upload_pack(const int advertise_refs, const int stateless_rpc, const int timeout); struct repository; -struct strvec; struct packet_reader; -int upload_pack_v2(struct repository *r, struct strvec *keys, - struct packet_reader *request); +int upload_pack_v2(struct repository *r, struct packet_reader *request); struct strbuf; int upload_pack_advertise(struct repository *r,