From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Jonathan Tan" <jonathantanmy@google.com>,
"Josh Steadmon" <steadmon@google.com>,
"Bruno Albuquerque" <bga@google.com>, "Jeff King" <peff@peff.net>,
"Eric Sunshine" <sunshine@sunshineco.com>,
"Christian Couder" <chriscool@tuxfamily.org>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 5/8] serve.c: add call_{advertise,command}() indirection
Date: Mon, 28 Jun 2021 21:19:22 +0200 [thread overview]
Message-ID: <patch-5.8-d0b02aa0c7d-20210628T191634Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-0.8-00000000000-20210628T191634Z-avarab@gmail.com>
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 <avarab@gmail.com>
---
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 "<name>=<value>" instead of "<name>".
*/
- 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;
--
2.32.0.611.gd4a17395dfa
next prev parent reply other threads:[~2021-06-28 19:19 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-16 14:16 [PATCH 0/5] serve: add "configure" callback Ævar Arnfjörð Bjarmason
2021-06-16 14:16 ` [PATCH 1/5] serve: mark has_capability() as static Ævar Arnfjörð Bjarmason
2021-06-16 16:28 ` Eric Sunshine
2021-06-17 0:45 ` Junio C Hamano
2021-06-16 14:16 ` [PATCH 2/5] transport: rename "fetch" in transport_vtable to "fetch_refs" Ævar Arnfjörð Bjarmason
2021-06-16 14:16 ` [PATCH 3/5] transport: use designated initializers Ævar Arnfjörð Bjarmason
2021-06-16 14:16 ` [PATCH 4/5] serve: " Ævar Arnfjörð Bjarmason
2021-06-16 14:16 ` [PATCH 5/5] serve: add support for a git_config() callback Ævar Arnfjörð Bjarmason
2021-06-16 16:22 ` Jeff King
2021-06-16 16:23 ` [PATCH 0/5] serve: add "configure" callback Jeff King
2021-06-17 0:49 ` Junio C Hamano
2021-06-28 19:19 ` [PATCH v2 0/8] serve: add "startup_config" callback Ævar Arnfjörð Bjarmason
2021-06-28 19:19 ` [PATCH v2 1/8] serve: mark has_capability() as static Ævar Arnfjörð Bjarmason
2021-06-28 19:19 ` [PATCH v2 2/8] transport: rename "fetch" in transport_vtable to "fetch_refs" Ævar Arnfjörð Bjarmason
2021-06-28 19:19 ` [PATCH v2 3/8] transport: use designated initializers Ævar Arnfjörð Bjarmason
2021-06-28 19:19 ` [PATCH v2 4/8] serve: " Ævar Arnfjörð Bjarmason
2021-06-28 19:19 ` Ævar Arnfjörð Bjarmason [this message]
2021-06-28 19:19 ` [PATCH v2 6/8] serve.c: add trace2 regions for advertise & command Ævar Arnfjörð Bjarmason
2021-07-01 16:30 ` Jeff King
2021-07-02 12:54 ` Ævar Arnfjörð Bjarmason
2021-07-05 12:24 ` Han-Wen Nienhuys
2021-06-28 19:19 ` [PATCH v2 7/8] serve: add support for a "startup" git_config() callback Ævar Arnfjörð Bjarmason
2021-07-01 16:43 ` Jeff King
2021-07-01 16:47 ` Jeff King
2021-07-02 12:55 ` Ævar Arnfjörð Bjarmason
2021-07-02 21:13 ` Jeff King
2021-07-05 12:23 ` Han-Wen Nienhuys
2021-07-05 12:34 ` Han-Wen Nienhuys
2021-06-28 19:19 ` [PATCH v2 8/8] upload-pack.c: convert to new serve.c "startup" config cb Ævar Arnfjörð Bjarmason
2021-07-05 14:00 ` Han-Wen Nienhuys
2021-07-21 23:40 ` [PATCH v3 00/12] serve.[ch]: general API cleanup Ævar Arnfjörð Bjarmason
2021-07-21 23:40 ` [PATCH v3 01/12] serve: mark has_capability() as static Ævar Arnfjörð Bjarmason
2021-07-21 23:40 ` [PATCH v3 02/12] transport: rename "fetch" in transport_vtable to "fetch_refs" Ævar Arnfjörð Bjarmason
2021-07-21 23:40 ` [PATCH v3 03/12] transport: use designated initializers Ævar Arnfjörð Bjarmason
2021-07-21 23:40 ` [PATCH v3 04/12] serve: " Ævar Arnfjörð Bjarmason
2021-07-21 23:40 ` [PATCH v3 05/12] serve.c: add call_{advertise,command}() indirection Ævar Arnfjörð Bjarmason
2021-07-21 23:40 ` [PATCH v3 06/12] serve: add support for a "startup" git_config() callback Ævar Arnfjörð Bjarmason
2021-07-21 23:40 ` [PATCH v3 07/12] serve.c: move version line to advertise_capabilities() Ævar Arnfjörð Bjarmason
2021-07-21 23:40 ` [PATCH v3 08/12] serve.[ch]: remove "serve_options", split up --advertise-refs code Ævar Arnfjörð Bjarmason
2021-07-21 23:40 ` [PATCH v3 09/12] {upload,receive}-pack tests: add --advertise-refs tests Ævar Arnfjörð Bjarmason
2021-08-03 6:00 ` [PATCH] fixup! " Carlo Marcelo Arenas Belón
2021-07-21 23:40 ` [PATCH v3 10/12] upload-pack: document and rename --advertise-refs Ævar Arnfjörð Bjarmason
2021-07-21 23:40 ` [PATCH v3 11/12] upload-pack.c: convert to new serve.c "startup" config cb Ævar Arnfjörð Bjarmason
2021-07-21 23:40 ` [PATCH v3 12/12] serve.[ch]: don't pass "struct strvec *keys" to commands Ævar Arnfjörð Bjarmason
2021-08-02 21:07 ` [PATCH v3 00/12] serve.[ch]: general API cleanup Josh Steadmon
2021-08-05 1:25 ` [PATCH v4 00/10] serve.[ch]: general API cleanup + --advertise-refs cleanup Ævar Arnfjörð Bjarmason
2021-08-05 1:25 ` [PATCH v4 01/10] serve: mark has_capability() as static Ævar Arnfjörð Bjarmason
2021-08-05 1:25 ` [PATCH v4 02/10] transport: rename "fetch" in transport_vtable to "fetch_refs" Ævar Arnfjörð Bjarmason
2021-08-05 1:25 ` [PATCH v4 03/10] transport: use designated initializers Ævar Arnfjörð Bjarmason
2021-08-05 1:25 ` [PATCH v4 04/10] serve: " Ævar Arnfjörð Bjarmason
2021-08-05 1:25 ` [PATCH v4 05/10] serve.[ch]: don't pass "struct strvec *keys" to commands Ævar Arnfjörð Bjarmason
2021-08-05 1:25 ` [PATCH v4 06/10] serve: move transfer.advertiseSID check into session_id_advertise() Ævar Arnfjörð Bjarmason
2021-08-05 1:25 ` [PATCH v4 07/10] serve.c: move version line to advertise_capabilities() Ævar Arnfjörð Bjarmason
2021-08-05 1:25 ` [PATCH v4 08/10] {upload,receive}-pack tests: add --advertise-refs tests Ævar Arnfjörð Bjarmason
2021-08-05 1:25 ` [PATCH v4 09/10] serve.[ch]: remove "serve_options", split up --advertise-refs code Ævar Arnfjörð Bjarmason
2021-08-24 16:52 ` Derrick Stolee
2021-08-05 1:25 ` [PATCH v4 10/10] upload-pack: document and rename --advertise-refs Ævar Arnfjörð Bjarmason
2021-08-24 16:55 ` [PATCH v4 00/10] serve.[ch]: general API cleanup + --advertise-refs cleanup Derrick Stolee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-5.8-d0b02aa0c7d-20210628T191634Z-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=bga@google.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jonathantanmy@google.com \
--cc=peff@peff.net \
--cc=steadmon@google.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).