From patchwork Mon Jun 28 19:19:18 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: 12348505 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 42BF9C11F65 for ; Mon, 28 Jun 2021 19:19:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FDF261941 for ; Mon, 28 Jun 2021 19:19:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236354AbhF1TWE (ORCPT ); Mon, 28 Jun 2021 15:22:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234418AbhF1TWC (ORCPT ); Mon, 28 Jun 2021 15:22:02 -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 5902EC061760 for ; Mon, 28 Jun 2021 12:19:34 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id r3so7682097wmq.1 for ; Mon, 28 Jun 2021 12:19:34 -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=wA1eKElB3w/MW9OGt6dcaujQcyaR8T/ROg81FShaK2M=; b=ZEjHzruX0/cdkwWA32tIXKsqkQk9Jb4QTIkWb5ooh+yYDkYdb4yJwp/1CklTEtLZo9 98JSSSk+HzQUD6yZUSZkingjRQMM1lIVguctCIUbq6z6y/Ns3zq+CYN0u0owRWaGZmbU r9C+s7hZ1rdK3jZkqBxi34LPe2EcPJ1+qToZ+cvFIDDi8eru/E2maMfwoZAtna8TKHs2 LKR34v7qfBV20dqA4EBGlaYL+kPAHTS0YhFaYCtvHauHV7ZIPGkThSltFkoBB8fk83ik p6g4AYrKsM/zhdUyZN62Ocr9Gk+dBnrp5lg3ETitAxSk0u+PQYoin1HQ7eeetXxcq9VG 2vHw== 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=wA1eKElB3w/MW9OGt6dcaujQcyaR8T/ROg81FShaK2M=; b=ChWfGtQSj5Ta7Ut4su26Ec/AKn6CXqSd8hFyoK/PsyXUltphmkL7HfA2WGD6vxUn+k nUS9lQKNTGWj0KJjLTV7bTJpdsr04ENMnpiRkqLEAz6nww8KAj9djyyioEh9KzKIYnEM lvs/98mUm5ouGHWqta099hoGlagYWtNbNdgNRGeVUPfvEm4J5sN7dyOoB6eXQxquL1UH hDtQ3yOVKAVYZdm9KomtL/xD9s6RzZYuaCUhXBFfMFqb64Qm3I6BhF4/UjMW8aBOMWwg x3sQbK8B6qeauL/mNaQt3GQ5WnXOjsdSFhE/5yPTzS+HYYT7TXUPBNdsI4gEVwy5yX0T k0Fw== X-Gm-Message-State: AOAM533MjY+lxN1xGy2gVEJqurJhJQSpK5wSP7XBynxmcLeLsAiMVma2 gn5LivAghfiaod+UwJnalQoO4zFtuvWfJQ== X-Google-Smtp-Source: ABdhPJy9REYqEMe3xaGQtd2QUKLKZW2zSXQRJWv3WoCdHtBH0iGAGYPY6wGrYHm9rNGv43RdQNGGLw== X-Received: by 2002:a7b:c7da:: with SMTP id z26mr28450036wmk.29.1624907972775; Mon, 28 Jun 2021 12:19:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s5sm350531wmh.46.2021.06.28.12.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 12:19:32 -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 , Christian Couder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 1/8] serve: mark has_capability() as static Date: Mon, 28 Jun 2021 21:19:18 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.611.gd4a17395dfa 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 Mon Jun 28 19:19:19 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: 12348509 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 EA84BC11F64 for ; Mon, 28 Jun 2021 19:19:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C8DE061992 for ; Mon, 28 Jun 2021 19:19:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236389AbhF1TWI (ORCPT ); Mon, 28 Jun 2021 15:22:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234572AbhF1TWD (ORCPT ); Mon, 28 Jun 2021 15:22:03 -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 321C4C061766 for ; Mon, 28 Jun 2021 12:19:35 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id a13so22575013wrf.10 for ; Mon, 28 Jun 2021 12:19:35 -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=R4mnmf+zQquQk2VS0VCraZZaOLEW0g3riRf7ZlJoXOk=; b=WT5Jgdy3KT2aeLJYYO/EZQnbd4zlipx97SLPNGfglwgsN7bKaCHuclVDocxk7+zYkB WSLBrKJMbh1a+LN7FrqvzZFGsfdQpZih3Uz0f8ztiQATcwoNsS0Gs4/b38EINifReEYJ zxi6THIelvb/oeLjeFqj9ggAwA3KJcv97xC8UOKv0TTKdKRA85d9wf5mcnAbFntt5EbG UGfAnzN4mvylvZdNesGe1bHgCm6WXGykEpGKFiuZ/tuuxcTNXM3bbCQMCMH0b+gZfV2G ZM4zJzlzsaY+x3KSl41JuYg1ouQWBCk9n3AKm522Wy00FKe/hxCSVd1VkaTQjvAM3kQq +KMg== 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=R4mnmf+zQquQk2VS0VCraZZaOLEW0g3riRf7ZlJoXOk=; b=JWR/fsqnjf6pmXpwqmV2uVsrviq429/AavpRH/PmXM3BohmGMqOInRLf57BL4ENeMS K19zH4Izlmn8QVAsrQLraG9QnGqK7Faz6wCvnhwJKzR1TmPDXavT6raD1MBwTyPlcv+I O0qkchR4i8JhPkMisaTA+iOTFn01CEMo/ovR1ur00jFpGQAHhpVrmnebSWPo9EPOFatG z8Bo2GeX82rQ7dHn7i4Z45EQUHZPZTK4sy2Ip83/rg7VTqVmUfLOQg+DiZ3idAeWB1mx rhmOYWbuDhaYclTCIALCoCwWPQTp8H4I1+5fk7gVLI4Y/E9aUu3EC5npKf/LNYk4IaqS RxHQ== X-Gm-Message-State: AOAM530vrOwM5uEiiznZBGYZw3YqHjrnaGNVnJN3R2wASByvva0qoAju RTP0B4kt8FSlLXgeZanu2470I0FLaeX7oQ== X-Google-Smtp-Source: ABdhPJzC7u9qw8XCQxXfUSQ3dtSUaK8WDXZIoUiNsYT2OicHGl9uJsAvQ+mtSpa3NVOdm1RB3zMhTA== X-Received: by 2002:a5d:60ce:: with SMTP id x14mr28757423wrt.385.1624907973645; Mon, 28 Jun 2021 12:19:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s5sm350531wmh.46.2021.06.28.12.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 12:19:33 -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 , Christian Couder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 2/8] transport: rename "fetch" in transport_vtable to "fetch_refs" Date: Mon, 28 Jun 2021 21:19:19 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.611.gd4a17395dfa 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 50f5830eb6b..f60985e2dbd 100644 --- a/transport.c +++ b/transport.c @@ -1449,7 +1449,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 Mon Jun 28 19:19:20 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: 12348507 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 CE710C11F66 for ; Mon, 28 Jun 2021 19:19:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4BF961997 for ; Mon, 28 Jun 2021 19:19:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236371AbhF1TWH (ORCPT ); Mon, 28 Jun 2021 15:22:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234314AbhF1TWD (ORCPT ); Mon, 28 Jun 2021 15:22:03 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 013BAC061767 for ; Mon, 28 Jun 2021 12:19:36 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso152936wmh.4 for ; Mon, 28 Jun 2021 12:19:35 -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=j2uro04gEiRKvFmfFcUKQpqQa9AQXX3y0z6jJPc+XBY=; b=nfVr2UxI8IFaFXsVFq9cz58eQlfEjFocaRBngDBrsxTDEhlzHLNTOJ43DeGS5fbvQX nb3J9xD1Ivo2s8ouIY1ZrIcCamnoeyJh49fjS4mzSyR01sJkQQKp+YIL3lBfzZeRA5eU BlS4+3a/atUJATyqXtwajAgFbLQjwV+hG0J+rhPUB/mC3Qtj0ia8zqk9XQMF93TkO5aN D0qP/g7/4ymou31YQbPOMBKlMFXxcVYlgOTIL9e8xNVjq6v6HxuFr0ydlUCfnQYHHP0d 4E7BMxr4hTVmRb/tdogyt3gOsv/QDMXYL8D6F6NlmglGp/Ri3cZ5O05y6Vu8okQc1CiQ aCWA== 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=j2uro04gEiRKvFmfFcUKQpqQa9AQXX3y0z6jJPc+XBY=; b=WqZh7oI4NrfmGOkbHa9QyTsdAg6iOJxmHVqnxM79c9hyXXuwv6IkWUM5nvPKRvEXhf lu3N4zzc4smg+P+R0xf+hxSQ3Ja4w9OKRvIGfzL9trw/6TWbBVhokRulKPjNfG2rVa4b I28QJ5tnKysx+/RGQKYnPHAvPXhPcnEC4WKPfvn65JQbEqKlpT/c+Lo33qHSPWMT/htP WaHScCe8ptaHaEJttOpScXMqxjHTtfOXrV22vJk8Bf7WrijirnwcVCFepb8I9WBubKRh jxsVvVgXvFfGcVCaD0dKARaD8LINDmQgsv8ygOT+WwdbVmtpOn/lx8jg95vBBOtCUB24 piow== X-Gm-Message-State: AOAM531g/yOAS6VjCFEGWG3euE+UkSYcGuKThi3bDw/QWwzNCIMrE/gX WCKvi9Aow7bsSLl9j6y5rtW+n7/o9gN6Hw== X-Google-Smtp-Source: ABdhPJzb6OMTs+OnfACSUwg/Glnl1JA3KBxSHSIKeDSlRb90TwoGVF6M2AW5Mf4fil8S8j5fssZ7+w== X-Received: by 2002:a1c:9a51:: with SMTP id c78mr587936wme.103.1624907974437; Mon, 28 Jun 2021 12:19:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s5sm350531wmh.46.2021.06.28.12.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 12:19:34 -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 , Christian Couder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 3/8] transport: use designated initializers Date: Mon, 28 Jun 2021 21:19:20 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.611.gd4a17395dfa 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 f60985e2dbd..bdd9b5a93cf 100644 --- a/transport.c +++ b/transport.c @@ -880,12 +880,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, @@ -1029,21 +1027,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 Mon Jun 28 19:19:21 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: 12348513 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 205DDC11F65 for ; Mon, 28 Jun 2021 19:19:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFA2C6198E for ; Mon, 28 Jun 2021 19:19:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236433AbhF1TWM (ORCPT ); Mon, 28 Jun 2021 15:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236359AbhF1TWE (ORCPT ); Mon, 28 Jun 2021 15:22:04 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F984C061760 for ; Mon, 28 Jun 2021 12:19:38 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id u11so22550934wrw.11 for ; Mon, 28 Jun 2021 12:19:38 -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=gUR4J0PiYcaNYPdNPOwmbDwIYv010ilIwXFhLx01/0U=; b=rMiq4QgEXmh3+ofAWB95FkmPjvSipldiN/2nRC6nPj8HkkTHkp31RR6QScoTCjKE5w TtZvaNhrkmeeK4AQ6YUrVU5KZYOVmimAEIvygZoJ2n2hmZ+14fbAox6ZK+9D1f7f7W5F +/ba43hi/lVwnUnU53axgH7cGWccdUhaxtBhD+1Qes8BJo1BQrgAs6Gsp2KVzUdH5UsI pl1Ko9BvnOn09J6mGA4zZBfSbSXr3hdQ0mtJ0ZuaIlkJTYpo0hep6BaY/f6gkvdbSe5Z qyQ8bQZsY3jrAGX9GAkqivaDL1zVrwLAhFD9KDYBe0gPpEe6C0MhvCtsFKGGGI43B/Kt Pp2A== 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=gUR4J0PiYcaNYPdNPOwmbDwIYv010ilIwXFhLx01/0U=; b=BZlvEfSu3AgmetsTTTC5X5STqBCTgGrRVDr9ezP996YJr08ZzaOtnFzB97Rgs3qVpa f3FFvI8+wK14p+QMybl4y/n1RLPjemyzX8b8qdoVlciAvoE7aFhfflbOaTCVjatQuQdZ 78YP832SiEh8w2kn8eus7UM1feTV+DHdgXYBCzAaPGO6RYNne0cG8rFxfOJsjKPa8PCG GZltkrmqavFweHqSSW4igS2E19KFXvu8KJsCzcoajnBmKGIfVil59gObbkGU+pSAooN2 3R2I5xpREth3nxRco9iKcwuw8tjtPzBmjikPzAiu7XG63eUP9DmKZuW4ov+4u6NNyoON k4JA== X-Gm-Message-State: AOAM531O5oqP86YYyShVDBjklgndxH/8CzCr4zwgVqZzKvXUFd9zWI4t 0g5lKLUKv/Q1lGlmREg2HBFc5KPYr5YTjw== X-Google-Smtp-Source: ABdhPJw1KYNirpR+R+x/bZQxWxavHvuvgKQGR41GWRcPQCqLPeKcCM0M+BHpRkwDtLvdDdDg/VQhUQ== X-Received: by 2002:a5d:4445:: with SMTP id x5mr29252286wrr.356.1624907975234; Mon, 28 Jun 2021 12:19:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s5sm350531wmh.46.2021.06.28.12.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 12:19:34 -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 , Christian Couder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 4/8] serve: use designated initializers Date: Mon, 28 Jun 2021 21:19:21 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.611.gd4a17395dfa 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 Mon Jun 28 19:19:22 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: 12348511 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 AAFA9C11F64 for ; Mon, 28 Jun 2021 19:19:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96C916198E for ; Mon, 28 Jun 2021 19:19:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236408AbhF1TWK (ORCPT ); Mon, 28 Jun 2021 15:22:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236356AbhF1TWE (ORCPT ); Mon, 28 Jun 2021 15:22:04 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C888C061574 for ; Mon, 28 Jun 2021 12:19:37 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id m41-20020a05600c3b29b02901dcd3733f24so172702wms.1 for ; Mon, 28 Jun 2021 12:19:37 -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=bFb4KrSbP4oprPBBt9LPcaEQfuq166rH4eTe9iGNomc=; b=jB8ZiynV9BdtEdqVKzMhSQ/CQQtzSyFacow8zvjpj4MSgN2NIy4fbjCQcfioo/4f3E AMJuQqSgXiT438A9bOgogDWN31kvj1D/Dm1vHAvQloE52VJs5I6pe1IfJZi99ylv6erh g+nl2u4CdDs0xltG2huZ1iacJCoPXTzoK8MwoCM0nB4T/eandmMJxaZeptYOFVogUVX4 NNWbDkvGxdpkvh0usju/KqeulTcKzzvE2v2Z7FY2RW4eBuN1t36cUdkZUYbd43MbMQ/1 h5vg8c6G7hS0ipNMfrTmlfsPv7MIpe2Ol8Dkr3ldgw4ua9cqlekhXQcYeLXa3Ue/wrcg 8mlw== 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=bFb4KrSbP4oprPBBt9LPcaEQfuq166rH4eTe9iGNomc=; b=sb2YY8QYEGr7ZgBrhEhVBcpnYBCSE6H1oqJZmwHSFGvbv7ZHE5M+DRCEKyrpfJvQvA XgSQeOClj1IKFn4Ztox7IBAbyZLqR243Vn05vXfxhu4wEhdCWwRHygxjzp8l2mVY0Im9 FIKrondoOyZdS+pKI7xWKQUEuvhH4ad32gwOfToyr0FMwgMSoF4eQ3Hm0FDeFA8YdCsY ad5RlvlBkeo6P/iQYN8wFATZZbT01Q3RvxRA89+QEgKaZs2LwnJCAWztRiVUPacPGnZE zTnyd9NhqrHv16IvE36SdSCSm+dcxVSid7X+e2qob1UfFKEhyQKvy6JoJnFHGJdEbo98 416A== X-Gm-Message-State: AOAM530Gmns50VkhhyNYa+Hs2VumB2jk9uM++tRdcxg2zBvvyO1HBc9L kLdwDutyHunGi5//ocSK6XywulBbuKwEfQ== X-Google-Smtp-Source: ABdhPJzQ+LnFZyWg6treBQIFMi+lhdNuFdzdAlqXA7tYc7nz4i+2lElt/1WhjtDRKJZlzo2ri61hwg== X-Received: by 2002:a1c:ed10:: with SMTP id l16mr28014870wmh.8.1624907976035; Mon, 28 Jun 2021 12:19:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s5sm350531wmh.46.2021.06.28.12.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 12:19:35 -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 , Christian Couder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 5/8] serve.c: add call_{advertise,command}() indirection Date: Mon, 28 Jun 2021 21:19:22 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.611.gd4a17395dfa 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 Mon Jun 28 19:19:23 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: 12348517 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.7 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,URIBL_BLOCKED,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 EBA3CC11F64 for ; Mon, 28 Jun 2021 19:19:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D370161992 for ; Mon, 28 Jun 2021 19:19:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236374AbhF1TWP (ORCPT ); Mon, 28 Jun 2021 15:22:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236363AbhF1TWF (ORCPT ); Mon, 28 Jun 2021 15:22:05 -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 82E67C061766 for ; Mon, 28 Jun 2021 12:19:38 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id p8so6483847wrr.1 for ; Mon, 28 Jun 2021 12:19:38 -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=9BJK6EM5uaSUttMB1wcIdc6cwrE+wbRlHtGLr0eBXQM=; b=UCtUgMgImpZBWOA9wm0gP046mrK450uKhv9JqO3AFur4wsrIGzmNbKo1JcHb5kShcL rWGpqwub9ZNOGJZhACsxggAXstI1Eg16rM2bnMBlZLu5tUyKZpwnlsAFYtKRR40msGdI KGNpzIPBn3WekNhnwO+B3dug2PQK4qnX8H/wwbvMynNWRqHAVXGKOx/Iiu4+MRQguCL6 DO1aUU/2ns+yY7Zn5bqatVUS4f7tBnd2AWoJr1GZ7yPRCcO6OUSBZetFfe+GCi5OSZ0+ 2cU2quX5TqtNgE+AUzpv5CBNN+7U2SOvEsNl3lD5+mGtB4WERjuGJQ1ARaeOsKWGUai7 iosQ== 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=9BJK6EM5uaSUttMB1wcIdc6cwrE+wbRlHtGLr0eBXQM=; b=JnBf793DzTqW5GbRaLnSYp/+u5xBHccDUj0rzPIU3K97IUxEEdHkjXi1KKk/4M/2zQ Iw7rDt04SHcS6xuGc0vaX5G6UefGdK2pDtPz8Fhmp2lkgU2ms2ebCKGTPTgGDwfgu61M U0Wt5REFggbxa70r+xe96vq2VQWVMgDPZn9YpmJZDQcNc4cN/hU78kAS0Y0fJKvs/Pn1 KSmLCx/ATtvFP7euwgsjAjLLd84JJjJhz7y8YsGn60hToefzAxcHPEBHNqOabgcnAbM2 3U1HjF5E6MeHKgoefZ0c9hP/nBw4Mnhl4MT7roCoTbjWw2KeXKCX2L+l88WJqiu2SOjL I7DA== X-Gm-Message-State: AOAM532H5QAkEpb6dszyILb3T5751wukYnFYJ9+ounaBYqvZbqnUeQW/ plHr/wTQeeUfvhO0wUqx0792MUj7WwhDHA== X-Google-Smtp-Source: ABdhPJywruw6Lyv1eQpPwzSyVH2+wC5JJnnFB3Bb4A932+AJXKJZ8ii1S7YQ4I8lwWerEV9XKXAtQQ== X-Received: by 2002:adf:bb54:: with SMTP id x20mr29260864wrg.19.1624907976935; Mon, 28 Jun 2021 12:19:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s5sm350531wmh.46.2021.06.28.12.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 12:19:36 -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 , Christian Couder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 6/8] serve.c: add trace2 regions for advertise & command Date: Mon, 28 Jun 2021 21:19:23 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.611.gd4a17395dfa In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that we've factored out "call_{advertise,command}()" in a preceding commit it becomes easy to trace all these callbacks with trace2. Let's do that. As the tests demonstrate there's no v2 push protocol, which the tests assert. Signed-off-by: Ævar Arnfjörð Bjarmason --- serve.c | 24 ++++++++++++++++++++++-- t/t5705-session-id-in-capabilities.sh | 16 ++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/serve.c b/serve.c index 85cd3eab26e..6dbd05248b9 100644 --- a/serve.c +++ b/serve.c @@ -111,14 +111,34 @@ static struct protocol_capability capabilities[] = { static int call_advertise(struct protocol_capability *command, struct repository *r, struct strbuf *value) { - return command->advertise(r, value); + int ret; + struct strbuf sb = STRBUF_INIT; + const char *msg; + + strbuf_addf(&sb, "advertise/%s", command->name); + trace2_region_enter("serve", sb.buf, r); + ret = command->advertise(r, value); + msg = ret ? "advertised" : "hidden"; + trace2_region_leave_printf("serve", sb.buf, r, "%s", msg); + strbuf_release(&sb); + + return ret; } static int call_command(struct protocol_capability *command, struct repository *r, struct strvec *keys, struct packet_reader *request) { - return command->command(r, keys, request); + int ret; + struct strbuf sb = STRBUF_INIT; + + strbuf_addf(&sb, "command/%s", command->name); + trace2_region_enter("serve", sb.buf, r); + ret = command->command(r, keys, request); + trace2_region_leave("serve", sb.buf, r); + strbuf_release(&sb); + + return ret; } static void advertise_capabilities(void) diff --git a/t/t5705-session-id-in-capabilities.sh b/t/t5705-session-id-in-capabilities.sh index f1d189d5bcc..cda78fa7a1d 100755 --- a/t/t5705-session-id-in-capabilities.sh +++ b/t/t5705-session-id-in-capabilities.sh @@ -57,7 +57,13 @@ do --upload-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-upload-pack" \ origin && grep \"key\":\"server-sid\" tr2-client-events && - grep \"key\":\"client-sid\" tr2-server-events + grep \"key\":\"client-sid\" tr2-server-events && + + if test "$PROTO" = 2 + then + grep \"event\":\"region_enter\".*\"category\":\"serve\" tr2-server-events && + grep \"event\":\"region_leave\".*\"category\":\"serve\" tr2-server-events + fi ' test_expect_success "session IDs advertised (push v${PROTO})" ' @@ -71,7 +77,13 @@ do --receive-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-receive-pack" \ origin HEAD:new-branch && grep \"key\":\"server-sid\" tr2-client-events && - grep \"key\":\"client-sid\" tr2-server-events + grep \"key\":\"client-sid\" tr2-server-events && + + if test "$PROTO" = 2 + then + ! grep \"event\":\"region_enter\".*\"category\":\"serve\" tr2-server-events && + ! grep \"event\":\"region_leave\".*\"category\":\"serve\" tr2-server-events + fi ' done From patchwork Mon Jun 28 19:19:24 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: 12348515 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 A5422C11F67 for ; Mon, 28 Jun 2021 19:19:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 89F5B61992 for ; Mon, 28 Jun 2021 19:19:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236437AbhF1TWN (ORCPT ); Mon, 28 Jun 2021 15:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236362AbhF1TWF (ORCPT ); Mon, 28 Jun 2021 15:22:05 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CA72C061767 for ; Mon, 28 Jun 2021 12:19:39 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id u8so9310900wrq.8 for ; Mon, 28 Jun 2021 12:19:39 -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=UY4h8s3G2YOHwkAT4tEY5NOgJh8Kv382VgqvFyK7y2c=; b=oMKpVBAVgdHu3dumhKRmfI5KXgE1r9nLMci3Ox4Nj2Z+lY/0eGOI1Yq6IDBO1ZE0mb zMS/+Fut5VHpCWEm+ClGgIJOQU8AMq8WKQREzjy3jtM4KP80d0LyCzjtGxITa0c8ZoZ+ 4xsak+vgNuBSIVSEi6bEMCV3Hreg7Ykn1RYpHz2R9O32ACss+efcfRIlHoQ9V46mVHJ9 /Lc66y7FpGWl8oHJZG86UTQKx25fXv25qYjnV+lE0UGej7WJSrNGXJcGn7kEZG2ddbM+ 2K88/dgVzSwz/ayj7QOEdfYjQKnqxqtTRBM86SIoRdorQFECvUij2kST/0kaER1ha2BO KQfA== 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=UY4h8s3G2YOHwkAT4tEY5NOgJh8Kv382VgqvFyK7y2c=; b=QO2AoBReMUWxUDOfuo3CVNSEjpsIyzhkEgqRl1vbzQzR9DGRlgkKUpPuLN6kRJp/Eb X8xlTpeNm5RF2/kX5aycZFbCYl2kbHX2FjrsuqB/8fqEewb50v+2XUbb2mQtUb16Ms2c BGfXqNTSXZKFBUE+O+buv00sbxi6UE8z20mXZFbzm6JZUrsJyy0Z6zgN6Vv1lNGdMJIu nfn/hHX00FM2vu15tNbbGpoRsgrUle+UbiYK59IR7eEIqG8tGgAo+AjzjjQIrsC+59QM issW2r8X8MNOjH1yEuSPZP3KEU7Bs7w/hjlkNlOakTyJFHOEg8B8++az6AeLHja8Wh2z Mmdg== X-Gm-Message-State: AOAM5319juYocE7Os243GVmxArmIcbub3mIRBL1BhxjeYiG8qxvV9XGd oQP6yRJjah59Y2Qd7X03eSfjQWep6H6PJQ== X-Google-Smtp-Source: ABdhPJyNvJar1xG8eMMMD9Kq02Mb0vs5QKY72c+FOaJtX5m0G6xOeKRf2kc1Ct+Bl0XZzJIBn95m2A== X-Received: by 2002:a5d:6cce:: with SMTP id c14mr8050588wrc.183.1624907977933; Mon, 28 Jun 2021 12:19:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s5sm350531wmh.46.2021.06.28.12.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 12:19:37 -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 , Christian Couder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 7/8] serve: add support for a "startup" git_config() callback Date: Mon, 28 Jun 2021 21:19:24 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.611.gd4a17395dfa 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. Signed-off-by: Ævar Arnfjörð Bjarmason --- ls-refs.c | 42 ++++++++++++++---------------------------- ls-refs.h | 1 + serve.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 55 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 6dbd05248b9..cce96dd5a81 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,6 +135,15 @@ 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) { @@ -115,6 +151,8 @@ static int call_advertise(struct protocol_capability *command, struct strbuf sb = STRBUF_INIT; const char *msg; + read_startup_config(command); + strbuf_addf(&sb, "advertise/%s", command->name); trace2_region_enter("serve", sb.buf, r); ret = command->advertise(r, value); @@ -132,6 +170,8 @@ static int call_command(struct protocol_capability *command, int ret; struct strbuf sb = STRBUF_INIT; + read_startup_config(command); + strbuf_addf(&sb, "command/%s", command->name); trace2_region_enter("serve", sb.buf, r); ret = command->command(r, keys, request); @@ -338,8 +378,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 Mon Jun 28 19:19:25 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: 12348519 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 494FEC11F64 for ; Mon, 28 Jun 2021 19:19:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DDEC6198E for ; Mon, 28 Jun 2021 19:19:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236497AbhF1TWV (ORCPT ); Mon, 28 Jun 2021 15:22:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236383AbhF1TWI (ORCPT ); Mon, 28 Jun 2021 15:22:08 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4254C061768 for ; Mon, 28 Jun 2021 12:19:40 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id j1so22553691wrn.9 for ; Mon, 28 Jun 2021 12:19:40 -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=mGO+xKI1Y5vAzZOie0bbcmq/muUo8iIvBabQgr8m8kA=; b=u9L3taX0e1V7+XIb7DJmLqEl13KFwThACHMY3EwJo2nrrnkTmJHwVBkGxVmnM6L64V jgvEzhH9O24RcDhdBZ7tPXAvsB6MqTXgKrEASVjwGkyBue2fVlc0ZSI0gI9BUm9MXp0F tCVWp/uGYVQSIGZV6G4pORTztv5HUCsRr+ejocXheIIxD7GKaa9AHfHIuxBxczoDWqdi 97EJ680OkAwMTzsCvDntX5yWJhFPmbSnKqPZd094FGoVu4cHEtt/O1I+Z0y9mC2tRkcO 85LtvwVtcVmFmSEErV2zis9biqpKVUU9Kobd5yJhAicVlGPe9Bti4bK6/NXsOPXUwYo6 x+eQ== 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=mGO+xKI1Y5vAzZOie0bbcmq/muUo8iIvBabQgr8m8kA=; b=VjHP2cAXeErZ4Fi5JxnVUFM7wBYTv0QKup+Qt7rCNxOVgXcaCHeRFC+XNHC05W9vU2 kVefiTD2f6AXjKk+xpVA/K9ySX6QQtwTbArtDx6bw4fu9WNMI9SrJXAhol4MeMj/pSVf 9tET/hYjDtTDxD8BkHaxhlRUBhpD9Omllx+qNTIQN4uEMOb/hf2pgpGO2Cr/JmJpK9qD lRZzq0Mz69CpnNP3b/5XrICpfqRTcTBLfopwxgY+dQmoanmXgnHV7D4GOKO/oI2mAqc1 zqheJ/W0bxhpZ/BBqUaQtBaUhlrYcAACSj3nYPXc64L1N8TniApiul+nX5jsPvReLgnl za1A== X-Gm-Message-State: AOAM530HXTnvXAs/e45RsX32sgYuklWRHlD2Nm8sE4tMnYhCCuXuyNo0 sdaA8SRK7jrW0ThOcSNgHn7lUJY9wba6FA== X-Google-Smtp-Source: ABdhPJy+JrDA8/+g3LeVm95yL2fCa6Z1TQJh7I4Ds/6VMaw0uXPv8VO5dKo1pK0CtaKb39UMYCpobw== X-Received: by 2002:a05:6000:1242:: with SMTP id j2mr28503681wrx.362.1624907979045; Mon, 28 Jun 2021 12:19:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id s5sm350531wmh.46.2021.06.28.12.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 12:19:38 -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 , Christian Couder , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 8/8] upload-pack.c: convert to new serve.c "startup" config cb Date: Mon, 28 Jun 2021 21:19:25 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.611.gd4a17395dfa 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 compatibly 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 | 139 ++++++++++++++++++++++++++++++-------------------- upload-pack.h | 2 + 3 files changed, 86 insertions(+), 56 deletions(-) diff --git a/serve.c b/serve.c index cce96dd5a81..1054d1459c9 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 297b76fcb43..6c0d566e9e0 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 = 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 < 0 ? -1 - : 1000 * pack_data->keepalive; + : 1000 * config_keepalive; 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->stateless_rpc ? " no-done" : "", symref_info.buf, @@ -1282,45 +1281,71 @@ 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 = git_config_int(var, value); + if (!config_keepalive) + config_keepalive = -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) +{ + int ret; + ret = upload_pack_startup_config(var, value, data); + if (ret) + return ret; + ret = upload_pack_startup_config_v2_only(var, value, data); + if (ret) + return ret; + 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) @@ -1336,6 +1361,8 @@ void upload_pack(struct upload_pack_options *options) 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 = options->stateless_rpc; @@ -1468,7 +1495,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; @@ -1526,7 +1553,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 27ddcdc6cb0..bd8b1ec5b3e 100644 --- a/upload-pack.h +++ b/upload-pack.h @@ -19,5 +19,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 */