git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 00/10] serve.[ch]: general API cleanup + --advertise-refs cleanup

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 5, 2021, 01:25 UTC
Message-ID
<cover-v4-00.10-00000000000-20210805T011823Z-avarab@gmail.com>
In-Reply-To
<cover-00.12-00000000000-20210721T233307Z-avarab@gmail.com>

This is a general API cleanup and simplifiction of of serve.[ch] and its interaction with "upload-pack --advertise-refs".

Previous rounds of this series had a way to define "startup config" for commands hanging off the v2 server. That's now entirely gone, along with prep work required for it.

For v3, see : https://lore.kernel.org/git/cover-00.12-00000000000-20210721T233307Z-avarab@gmail.com/

The fixup for the missing test shebang has also been squashed in, thanks Carlo!: https://lore.kernel.org/git/20210803060005.18151-1-carenas@gmail.com/

Despite the overall diffstat this is a net deletion of code in any meaningful sense of reducing complexity, i.e. it goes into the plus on the diffstat due to the addition of previously missing tests, and the use of designated initializers.

Ævar Arnfjörð Bjarmason (10):
  serve: mark has_capability() as static
  transport: rename "fetch" in transport_vtable to "fetch_refs"
  transport: use designated initializers
  serve: use designated initializers
  serve.[ch]: don't pass "struct strvec *keys" to commands
  serve: move transfer.advertiseSID check into session_id_advertise()
  serve.c: move version line to advertise_capabilities()
  {upload,receive}-pack tests: add --advertise-refs tests
  serve.[ch]: remove "serve_options", split up --advertise-refs code
  upload-pack: document and rename --advertise-refs
 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                     |  28 ++--
 http-backend.c                            |   2 +-
 ls-refs.c                                 |   3 +-
 ls-refs.h                                 |   4 +-
 protocol-caps.c                           |   3 +-
 protocol-caps.h                           |   4 +-
 serve.c                                   |  82 ++++++-----
 serve.h                                   |  12 +-
 t/helper/test-serve-v2.c                  |  14 +-
 t/t5555-http-smart-common.sh              | 161 ++++++++++++++++++++++
 transport-helper.c                        |  18 +--
 transport-internal.h                      |   2 +-
 transport.c                               |  32 ++---
 upload-pack.c                             |  21 +--
 upload-pack.h                             |  14 +-
 20 files changed, 298 insertions(+), 128 deletions(-)
 create mode 100755 t/t5555-http-smart-common.sh
Range-diff against v3:
 1:  192fb64ef82 =  1:  13bb1a06078 serve: mark has_capability() as static
 2:  d716bd3c537 =  2:  162f717436f transport: rename "fetch" in transport_vtable to "fetch_refs"
 3:  d31690614af =  3:  d3d5818adda transport: use designated initializers
 4:  13f1a8d8325 =  4:  8da15c373cc serve: use designated initializers
 5:  99eeff6f890 <  -:  ----------- serve.c: add call_{advertise,command}() indirection
 6:  be719dc3dc1 <  -:  ----------- serve: add support for a "startup" git_config() callback
12:  e4eb31b5b8e !  5:  7714f81d62c serve.[ch]: don't pass "struct strvec *keys" to commands
    @@ Commit message
         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.
    +    Let's remove that code because it's not needed. If we do end up
    +    needing to pass information about the advertisement in the future
    +    it'll make more sense to have serve.c parse the capabilities keys and
    +    pass the result of its parsing, rather than expecting expecting its
    +    API users to parse the same keys again.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
    @@ ls-refs.h
     -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);
      
    + #endif /* LS_REFS_H */
     
      ## protocol-caps.c ##
     @@ protocol-caps.c: 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,
    @@ protocol-caps.h
      #endif /* PROTOCOL_CAPS_H */
     
      ## serve.c ##
    -@@ serve.c: 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 {
     @@ serve.c: struct protocol_capability {
      
      	/*
    @@ serve.c: struct protocol_capability {
      	 * use to read the command specific part of the request.  Every command
      	 * MUST read until a flush packet is seen before sending a response.
      	 *
    -@@ serve.c: static int call_command(struct protocol_capability *command,
    + 	 * This field should be NULL for capabilities which are not commands.
    + 	 */
    +-	int (*command)(struct repository *r,
    +-		       struct strvec *keys,
    +-		       struct packet_reader *request);
    ++	int (*command)(struct repository *r, struct packet_reader *request);
    + };
      
    - 	read_startup_config(command);
    + static struct protocol_capability capabilities[] = {
    +@@ serve.c: static int process_request(void)
    + 	if (has_capability(&keys, "session-id", &client_sid))
    + 		trace2_data_string("transfer", NULL, "client-sid", client_sid);
      
    --	return command->command(r, keys, request);
    -+	return command->command(r, request);
    - }
    +-	command->command(the_repository, &keys, &reader);
    ++	command->command(the_repository, &reader);
      
    - void protocol_v2_advertise_capabilities(void)
    + 	strvec_clear(&keys);
    + 	return 0;
     
      ## upload-pack.c ##
     @@ upload-pack.c: enum fetch_state {
    @@ upload-pack.c: enum fetch_state {
      	struct upload_pack_data data;
     
      ## upload-pack.h ##
    -@@ upload-pack.h: void upload_pack(const int advertise_refs, const int stateless_rpc,
    - 		 const int timeout);
    +@@ upload-pack.h: struct upload_pack_options {
    + void upload_pack(struct upload_pack_options *options);
      
      struct repository;
     -struct strvec;
 -:  ----------- >  6:  33db6b7cf53 serve: move transfer.advertiseSID check into session_id_advertise()
 7:  b7928ddbe9b !  7:  9828e08cbad serve.c: move version line to advertise_capabilities()
    @@ Commit message
         serve.c: move version line to advertise_capabilities()
     
         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.
    +    emit this version line before it. In a subsequent commit I'll make
    +    builtin/upload-pack.c sometimes call advertise_capabilities()
    +    directly, so it'll make sense to have this line emitted by
    +    advertise_capabilities(), not serve() itself.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
 9:  beafe9811c1 !  8:  fd58abb7420 {upload,receive}-pack tests: add --advertise-refs tests
    @@ Commit message
     
      ## t/t5555-http-smart-common.sh (new) ##
     @@
    ++#!/bin/sh
    ++
     +test_description='test functionality common to smart fetch & push'
     +
     +. ./test-lib.sh
 8:  fb80f152713 !  9:  c9a35868933 serve.[ch]: remove "serve_options", split up --advertise-refs code
    @@ http-backend.c: static void get_info_refs(struct strbuf *hdr, char *arg)
      
     
      ## serve.c ##
    -@@ serve.c: static int call_command(struct protocol_capability *command,
    - 	return command->command(r, keys, request);
    - }
    +@@ serve.c: static struct protocol_capability capabilities[] = {
    + 	},
    + };
      
     -static void advertise_capabilities(void)
     +void protocol_v2_advertise_capabilities(void)
    @@ upload-pack.h
     +		 const int timeout);
      
      struct repository;
    - struct strvec;
    + struct packet_reader;
10:  c6870b5f18a = 10:  2006cb234b6 upload-pack: document and rename --advertise-refs
11:  2d4c3d0d463 <  -:  ----------- upload-pack.c: convert to new serve.c "startup" config cb
-- 
2.33.0.rc0.597.gc569a812f0a
Previous: Josh SteadmonNext: Ævar Arnfjörð Bjarmason
Message 46 of 58 in “serve: add "configure" callback”
  1. 0/5 serve: add "configure" callbackÆvar Arnfjörð Bjarmason, Jun 16, 2021
  2. 1/5 serve: mark has_capability() as staticÆvar Arnfjörð Bjarmason, Jun 16, 2021
  3. Eric SunshineJun 16, 2021
  4. Junio C HamanoJun 17, 2021
  5. 2/5 transport: rename "fetch" in transport_vtable to "fetch_refs"Ævar Arnfjörð Bjarmason, Jun 16, 2021
  6. 3/5 transport: use designated initializersÆvar Arnfjörð Bjarmason, Jun 16, 2021
  7. 5/5 serve: add support for a git_config() callbackÆvar Arnfjörð Bjarmason, Jun 16, 2021
  8. Jeff KingJun 16, 2021
  9. 4/5 serve: use designated initializersÆvar Arnfjörð Bjarmason, Jun 16, 2021
  10. Jeff KingJun 16, 2021
  11. Junio C HamanoJun 17, 2021
  12. 0/8 serve: add "startup_config" callbackÆvar Arnfjörð Bjarmason, Jun 28, 2021
  13. 1/8 serve: mark has_capability() as staticÆvar Arnfjörð Bjarmason, Jun 28, 2021
  14. 3/8 transport: use designated initializersÆvar Arnfjörð Bjarmason, Jun 28, 2021
  15. 2/8 transport: rename "fetch" in transport_vtable to "fetch_refs"Ævar Arnfjörð Bjarmason, Jun 28, 2021
  16. 5/8 serve.c: add call_{advertise,command}() indirectionÆvar Arnfjörð Bjarmason, Jun 28, 2021
  17. 4/8 serve: use designated initializersÆvar Arnfjörð Bjarmason, Jun 28, 2021
  18. 7/8 serve: add support for a "startup" git_config() callbackÆvar Arnfjörð Bjarmason, Jun 28, 2021
  19. Jeff KingJul 1, 2021
  20. Jeff KingJul 1, 2021
  21. Ævar Arnfjörð BjarmasonJul 2, 2021
  22. Jeff KingJul 2, 2021
  23. Han-Wen NienhuysJul 5, 2021
  24. Han-Wen NienhuysJul 5, 2021
  25. 6/8 serve.c: add trace2 regions for advertise & commandÆvar Arnfjörð Bjarmason, Jun 28, 2021
  26. Jeff KingJul 1, 2021
  27. Ævar Arnfjörð BjarmasonJul 2, 2021
  28. Han-Wen NienhuysJul 5, 2021
  29. 8/8 upload-pack.c: convert to new serve.c "startup" config cbÆvar Arnfjörð Bjarmason, Jun 28, 2021
  30. Han-Wen NienhuysJul 5, 2021
  31. 00/12 serve.[ch]: general API cleanupÆvar Arnfjörð Bjarmason, Jul 21, 2021
  32. 01/12 serve: mark has_capability() as staticÆvar Arnfjörð Bjarmason, Jul 21, 2021
  33. 02/12 transport: rename "fetch" in transport_vtable to "fetch_refs"Ævar Arnfjörð Bjarmason, Jul 21, 2021
  34. 03/12 transport: use designated initializersÆvar Arnfjörð Bjarmason, Jul 21, 2021
  35. 04/12 serve: use designated initializersÆvar Arnfjörð Bjarmason, Jul 21, 2021
  36. 05/12 serve.c: add call_{advertise,command}() indirectionÆvar Arnfjörð Bjarmason, Jul 21, 2021
  37. 06/12 serve: add support for a "startup" git_config() callbackÆvar Arnfjörð Bjarmason, Jul 21, 2021
  38. 07/12 serve.c: move version line to advertise_capabilities()Ævar Arnfjörð Bjarmason, Jul 21, 2021
  39. 08/12 serve.[ch]: remove "serve_options", split up --advertise-refs codeÆvar Arnfjörð Bjarmason, Jul 21, 2021
  40. 10/12 upload-pack: document and rename --advertise-refsÆvar Arnfjörð Bjarmason, Jul 21, 2021
  41. 09/12 {upload,receive}-pack tests: add --advertise-refs testsÆvar Arnfjörð Bjarmason, Jul 21, 2021
  42. fixup! {upload,receive}-pack tests: add --advertise-refs testsCarlo Marcelo Arenas Belón, Aug 3, 2021
  43. 11/12 upload-pack.c: convert to new serve.c "startup" config cbÆvar Arnfjörð Bjarmason, Jul 21, 2021
  44. 12/12 serve.[ch]: don't pass "struct strvec *keys" to commandsÆvar Arnfjörð Bjarmason, Jul 21, 2021
  45. Josh SteadmonAug 2, 2021
  46. 00/10 serve.[ch]: general API cleanup + --advertise-refs cleanupÆvar Arnfjörð Bjarmason, Aug 5, 2021
  47. 01/10 serve: mark has_capability() as staticÆvar Arnfjörð Bjarmason, Aug 5, 2021
  48. 02/10 transport: rename "fetch" in transport_vtable to "fetch_refs"Ævar Arnfjörð Bjarmason, Aug 5, 2021
  49. 03/10 transport: use designated initializersÆvar Arnfjörð Bjarmason, Aug 5, 2021
  50. 04/10 serve: use designated initializersÆvar Arnfjörð Bjarmason, Aug 5, 2021
  51. 05/10 serve.[ch]: don't pass "struct strvec *keys" to commandsÆvar Arnfjörð Bjarmason, Aug 5, 2021
  52. 06/10 serve: move transfer.advertiseSID check into session_id_advertise()Ævar Arnfjörð Bjarmason, Aug 5, 2021
  53. 07/10 serve.c: move version line to advertise_capabilities()Ævar Arnfjörð Bjarmason, Aug 5, 2021
  54. 08/10 {upload,receive}-pack tests: add --advertise-refs testsÆvar Arnfjörð Bjarmason, Aug 5, 2021
  55. 09/10 serve.[ch]: remove "serve_options", split up --advertise-refs codeÆvar Arnfjörð Bjarmason, Aug 5, 2021
  56. Derrick StoleeAug 24, 2021
  57. 10/10 upload-pack: document and rename --advertise-refsÆvar Arnfjörð Bjarmason, Aug 5, 2021
  58. Derrick StoleeAug 24, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.