Message ID | 20240720034337.57125-2-eric.peijian@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | cat-file: add remote-object-info to batch-command | expand |
On Sat, Jul 20, 2024 at 5:43 AM Eric Ju <eric.peijian@gmail.com> wrote: > > From: Calvin Wan <calvinwan@google.com> > > A subsequent patch needs to write capabilities for another command. > Refactor write_fetch_command_and_capabilities() to be a more general > purpose function write_command_and_capabilities(), so that it can be > used by both fetch and future command. > > Here "command" means the "operations" supported by Git’s wire protocol > https://git-scm.com/docs/protocol-v2. An example would be a > git's subcommand, such as git-fetch(1); or an operation supported by > the server side such as "object-info" implemented in "a2ba162cda > (object-info: support for retrieving object info, 2021-04-20)". I agree that reusing or refactoring the new write_command_and_capabilities() function for more commands can be done in a separate series that could perhaps also move the new function to connect.c. Maybe this could be added to the commit message though. [...] > -static void write_fetch_command_and_capabilities(struct strbuf *req_buf, > - const struct string_list *server_options) > +static void write_command_and_capabilities(struct strbuf *req_buf, > + const struct string_list *server_options, const char* command) In https://lore.kernel.org/git/xmqqfsn0qsi4.fsf@gitster.g/ Junio suggested swaping the "command" and "server_options" arguments as well as sticking the "*" to "command" instead of "char", so: static void write_command_and_capabilities(struct strbuf *req_buf, const char *command, const struct string_list *server_options) The rest of the patch looks good.
On Tue, Sep 24, 2024 at 7:45 AM Christian Couder <christian.couder@gmail.com> wrote: > > On Sat, Jul 20, 2024 at 5:43 AM Eric Ju <eric.peijian@gmail.com> wrote: > > > > From: Calvin Wan <calvinwan@google.com> > > > > A subsequent patch needs to write capabilities for another command. > > Refactor write_fetch_command_and_capabilities() to be a more general > > purpose function write_command_and_capabilities(), so that it can be > > used by both fetch and future command. > > > > Here "command" means the "operations" supported by Git’s wire protocol > > https://git-scm.com/docs/protocol-v2. An example would be a > > git's subcommand, such as git-fetch(1); or an operation supported by > > the server side such as "object-info" implemented in "a2ba162cda > > (object-info: support for retrieving object info, 2021-04-20)". > > I agree that reusing or refactoring the new > write_command_and_capabilities() function for more commands can be > done in a separate series that could perhaps also move the new > function to Maybe this could be added to the commit message > though. > Thank you, I am adding this to the commit message, "In a future separate series, we can move write_command_and_capabilities() to a higher-level file, such as connect.c, so that it becomes accessible to other commands." > [...] > > > -static void write_fetch_command_and_capabilities(struct strbuf *req_buf, > > - const struct string_list *server_options) > > +static void write_command_and_capabilities(struct strbuf *req_buf, > > + const struct string_list *server_options, const char* command) > > In https://lore.kernel.org/git/xmqqfsn0qsi4.fsf@gitster.g/ Junio > suggested swaping the "command" and "server_options" arguments as well > as sticking the "*" to "command" instead of "char", so: > > static void write_command_and_capabilities(struct strbuf *req_buf, > > const char *command, > > const struct string_list *server_options) > > The rest of the patch looks good. Thank you. The format is changed in V3.
diff --git a/fetch-pack.c b/fetch-pack.c index 732511604b..9c8cda0f9e 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1312,13 +1312,13 @@ static int add_haves(struct fetch_negotiator *negotiator, return haves_added; } -static void write_fetch_command_and_capabilities(struct strbuf *req_buf, - const struct string_list *server_options) +static void write_command_and_capabilities(struct strbuf *req_buf, + const struct string_list *server_options, const char* command) { const char *hash_name; - ensure_server_supports_v2("fetch"); - packet_buf_write(req_buf, "command=fetch"); + ensure_server_supports_v2(command); + packet_buf_write(req_buf, "command=%s", command); if (server_supports_v2("agent")) packet_buf_write(req_buf, "agent=%s", git_user_agent_sanitized()); if (advertise_sid && server_supports_v2("session-id")) @@ -1354,7 +1354,7 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out, int done_sent = 0; struct strbuf req_buf = STRBUF_INIT; - write_fetch_command_and_capabilities(&req_buf, args->server_options); + write_command_and_capabilities(&req_buf, args->server_options, "fetch"); if (args->use_thin_pack) packet_buf_write(&req_buf, "thin-pack"); @@ -2172,7 +2172,7 @@ void negotiate_using_fetch(const struct oid_array *negotiation_tips, the_repository, "%d", negotiation_round); strbuf_reset(&req_buf); - write_fetch_command_and_capabilities(&req_buf, server_options); + write_command_and_capabilities(&req_buf, server_options, "fetch"); packet_buf_write(&req_buf, "wait-for-done");