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

Re: [GSoC PATCH v5 2/5] repo: add the field references.format

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 27, 2025, 21:16 UTC
Message-ID
<CAPig+cTuiUy=+2Jf1Lrp1gaM03_zPf8EFMVSKmShqU05t-3aWQ@mail.gmail.com>
In-Reply-To
<20250727175110.84770-3-lucasseikioshiro@gmail.com>

On Sun, Jul 27, 2025 at 1:52 PM Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> wrote:

Show 21 quoted lines
> This commit is part of the series that introduces the new subcommand
> git-repo-info.
>
> The flag `--show-ref-format` from git-rev-parse is used for retrieving
> the reference format (i.e. `files` or `reftable`). This way, it is
> used for querying repository metadata, fitting in the purpose of
> git-repo-info.
>
> Add a new field `references.format` to the repo-info subcommand
> containing that information.
>
> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
> ---
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> @@ -29,6 +29,10 @@ INFO KEYS
>  The set of data that `git repo` can return is grouped into the following
>  categories:
>
> +`references`::
> +Reference-related data:
> +* `format`: the reference storage format

Based upon the implementation, I can see that the user must type the key in "dotted" form:

    git repo info references.format

but I wonder if the above documentation actually conveys this requirement. I don't think I would figure it out easily. Perhaps hand-holding the user by giving an example would help.

Show 5 quoted lines
> diff --git a/builtin/repo.c b/builtin/repo.c
> +/* repo_info_fields keys should be in lexicographical order */
> +static const struct field repo_info_fields[] = {
> +       { "references.format", get_references_format },
> +};

How can we ensure that the lexicographical-order requirement won't break? If someone adds a new entry which is not in its proper place, presumably that will be noticed because some existing test in a test script will stop working, but it feels unnecessarily fragile and a bit of a maintenance burden. Also, this requirement does feel like a premature optimization. Do you expect this list to become so huge and the corresponding lookup function to be called so frequently that a simple brute-force linear search would be too slow?

Show 13 quoted lines
> +static int qsort_strcmp(const void *va, const void *vb)
>  {
> +       const char *a = *(const char **)va;
> +       const char *b = *(const char **)vb;
> +
> +       return strcmp(a, b);
> +}
> +
> +static int print_fields(int argc, const char **argv, struct repository *repo)
> +{
> +       const char *last = "";
> +
> +       QSORT(argv, argc, qsort_strcmp);

I can see from the implementation that you are sorting the incoming arguments in order to detect and fold out duplicates. However, that raises a couple questions. First, is it really a good idea to do something other than what the user asked for? Second, if this is a good idea, then should the behavior be documented?

I can see arguments in favor of sorting and de-duplicating, as well as in favor of producing exactly the (unordered) output the user asked for, including duplicates, so I don't have a strong opinion either way. But, if you do retain this behavior, then the sorting and deduplication behaviors should probably be documented.

Show 17 quoted lines
> +       for (int i = 0; i < argc; i++) {
> +               get_value_fn *get_value;
> +               const char *key = argv[i];
> +               struct strbuf value;
> +
> +               if (!strcmp(key, last))
> +                       continue;
> +
> +               strbuf_init(&value, 64);
> +               get_value = get_value_fn_for_key(key);
> +
> +               if (!get_value) {
> +                       strbuf_release(&value);
> +                       return error(_("key '%s' not found"), key);
> +               }
> +
> +               get_value(repo, &value);
A couple observations:

First, you don't actually use the strbuf until the call to get_value(), so the strbuf_init() call seems to be too early, with the result that you need a corresponding strbuf_release() in the error branch. If you move the strbuf_init() so it occurs immediately before get_value(), then you can simplify the early exit case.

Second, this seems to be getting unnecessarily intimate with strbuf. I can guess that you're doing this late strbuf_init() to avoid an allocation in the case when a duplicate key was encountered, however, STRBUF_INIT doesn't actually perform an allocation, so it would be clearer to just initialize the strbuf at the time you declare it rather than calling strbuf_init() manually. However...

Although it is a micro optimization (as well as a premature-optimization), it is far more common in this code base to hoist the strbuf outside of the loop and instead call strbuf_reset() it upon each iteration:

    struct strbuf value = STRBUF_INIT;
    for (...) {
        strbuf_reset(&value);
        ...
        if (error_condition) {
            strbuf_release(...);
            return error(...);
        }
       ...
    }
    strbuf_release(...);
Show 7 quoted lines
> +               printf("%s=%s\n", key, value.buf);
> +               last = key;
> +               strbuf_release(&value);
> +       }
> +
>         return 0;
>  }

Looking at this from a higher level, is it presenting a good user-experience by potentially printing some output but then erroring out upon the first unrecognized key? Would the user-experience be improved by instead continuing the loop even after reporting an error, and then adjusting the final `return 0` to conditionally return success or error depending upon whether any keys were unrecognized?

Show 9 quoted lines
> diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
> @@ -0,0 +1,57 @@
> +#!/bin/sh
> +
> +test_description='test git repo-info'
> +
> +. ./test-lib.sh
> +
> +# Test if a field is correctly returned in the null-terminated format

This is talking about null-terminated format, but the implementation doesn't seem to emit NUL-terminated output at all.

Show 23 quoted lines
> +# Usage: test_repo_info <label> <init command> <key> <expected value>
> +#
> +# Arguments:
> +#   label: the label of the test
> +#   init command: a command that creates a repository called 'repo', configured
> +#      accordingly to what is being tested
> +#   key: the key of the field that is being tested
> +#   expected value: the value that the field should contain
> +test_repo_info () {
> +       label=$1
> +       init_command=$2
> +       key=$3
> +       expected_value=$4
> +
> +       test_expect_success "$label" '
> +               test_when_finished "rm -rf repo" &&
> +               eval "$init_command" &&
> +               echo "$expected_value" >expected &&
> +               git -C repo repo info "$key" >output &&
> +               cut -d "=" -f 2 <output >actual &&
> +               test_cmp expected actual
> +       '
> +}

It seems that this could be simplified by crafting the expected output more precisely?

    eval ... &&
    echo "$key=$expected_value" >expect &&
    git -C repo repo info "$key" >actual &&
    test_cmp expect actual

By the way, we typically avoid cleaning up test detritus merely for the sake of cleaning up because doing so slows down the already too-slow test suite. Instead, cleanup is usually only performed when absolutely necessary to avoid some undesirable interaction between tests. Avoiding cleanup also makes it easier to debug failed tests since (hopefully) the cause of the failure is still present in the "trash" directory.

In this case, if you call this function with a distinct repository name each time, then you don't have to remove the repository at all. Moreover, giving each repository a distinct and _meaningful_ name, rather than reusing the same name, could also be helpful when diagnosing failures.

Show 5 quoted lines
> +test_repo_info 'ref format files is retrieved correctly' '
> +       git init --ref-format=files repo' 'references.format' 'files'
> +
> +test_repo_info 'ref format reftable is retrieved correctly' '
> +       git init --ref-format=reftable repo' 'references.format' 'reftable'

This is overly fragile. The `test_repo_info` function hardcodes the name "repo" but then the caller is also expected to pass in the name as part of the initialization argument (i.e. `git init ... repo`). To make this more robust, either don't hardcode it in the function, or stop expecting the caller to supply the name as part of the initialization argument.

With only two callers, it's not clear at this point whether the `test_repo_info` function is providing any added value, especially since the additional abstraction increases cognitive load, but perhaps later patches in this series add more callers?

Show 8 quoted lines
> +test_expect_success 'git-repo-info aborts if an invalid key is requested' '
> +       test_when_finished "rm -rf expected err" &&
> +       echo "error: key '\'foo\'' not found" >expected &&
> +       test_must_fail git repo info foo 2>err &&
> +       test_cmp expected err
> +'
> +
> +test_expect_success "only one value is returned if the same key is requested twice" '
This test title can be single-quoted rather than double-quoted.
Show 9 quoted lines
> +       test_when_finished "rm -f expected_key expected_value actual_key actual_value output" &&
> +       echo "references.format" >expected_key &&
> +       git rev-parse --show-ref-format >expected_value &&
> +       git repo info references.format references.format >output &&
> +       cut -d "=" -f 1 <output >actual_key &&
> +       cut -d "=" -f 2 <output >actual_value &&
> +        test_cmp expected_key actual_key &&
> +        test_cmp expected_value actual_value
> +'

As above, it seems that this could be simplified by crafting the expected state more precisely rather than slicing and dicing the actual output. Perhaps something like this?

    val=$(git rev-parse --show-ref-format) &&
    echo "references.format=$val" >expect &&
    git repo info references.format references.format >actual &&
    test_cmp expect actual

Aside from the above tests, based upon the implementation, I also expected to find a test checking that the command correctly outputs multiple values, but perhaps a later patch adds that since, presently, the implementation only knows "references.format" (thus with deduplication, you can't yet implement such a test).

Previous: Lucas Seiki OshiroNext: Lucas Seiki Oshiro
Message 137 of 226 in “repo-info: add new command for retrieving repository info”
  1. 0/5 repo-info: add new command for retrieving repository infoLucas Seiki Oshiro, Jun 10, 2025
  2. 1/5 repo-info: declare the repo-info commandLucas Seiki Oshiro, Jun 10, 2025
  3. Karthik NayakJun 11, 2025
  4. 2/5 repo-info: add the --format flagLucas Seiki Oshiro, Jun 10, 2025
  5. Karthik NayakJun 11, 2025
  6. Lucas Seiki OshiroJun 12, 2025
  7. Karthik NayakJun 13, 2025
  8. 3/5 repo-info: add the field references.formatLucas Seiki Oshiro, Jun 10, 2025
  9. Karthik NayakJun 11, 2025
  10. Junio C HamanoJun 12, 2025
  11. 5/5 repo-info: add field layout.shallowLucas Seiki Oshiro, Jun 10, 2025
  12. 4/5 repo-info: add field layout.bareLucas Seiki Oshiro, Jun 10, 2025
  13. Karthik NayakJun 11, 2025
  14. Lucas Seiki OshiroJun 12, 2025
  15. Junio C HamanoJun 12, 2025
  16. Kristoffer HaugsbakkJun 10, 2025
  17. Junio C HamanoJun 10, 2025
  18. Lucas Seiki OshiroJun 12, 2025
  19. Junio C HamanoJun 12, 2025
  20. Lucas Seiki OshiroJun 16, 2025
  21. Junio C HamanoJun 16, 2025
  22. Lucas Seiki OshiroJun 19, 2025
  23. Karthik NayakJun 11, 2025
  24. 0/7 repo-info: add new command for retrieving repository infoLucas Seiki Oshiro, Jun 19, 2025
  25. 1/7 repo-info: declare the repo-info commandLucas Seiki Oshiro, Jun 19, 2025
  26. Karthik NayakJun 20, 2025
  27. Junio C HamanoJun 20, 2025
  28. Karthik NayakJun 23, 2025
  29. Lucas Seiki OshiroJun 23, 2025
  30. Karthik NayakJun 20, 2025
  31. Phillip WoodJun 24, 2025
  32. Patrick SteinhardtJul 3, 2025
  33. Lucas Seiki OshiroJul 4, 2025
  34. Patrick SteinhardtJul 7, 2025
  35. Justin ToblerJul 9, 2025
  36. 2/7 repo-info: add the --format flagLucas Seiki Oshiro, Jun 19, 2025
  37. Karthik NayakJun 20, 2025
  38. Junio C HamanoJun 20, 2025
  39. Patrick SteinhardtJul 3, 2025
  40. 3/7 repo-info: add plaintext as an output formatLucas Seiki Oshiro, Jun 19, 2025
  41. Junio C HamanoJun 20, 2025
  42. Patrick SteinhardtJul 3, 2025
  43. 4/7 repo-info: add the --allow-empty flagLucas Seiki Oshiro, Jun 19, 2025
  44. Karthik NayakJun 20, 2025
  45. Lucas Seiki OshiroJun 23, 2025
  46. Junio C HamanoJun 20, 2025
  47. Karthik NayakJun 23, 2025
  48. Lucas Seiki OshiroJun 23, 2025
  49. 5/7 repo-info: add the field references.formatLucas Seiki Oshiro, Jun 19, 2025
  50. Junio C HamanoJun 20, 2025
  51. Phillip WoodJun 24, 2025
  52. Junio C HamanoJun 24, 2025
  53. Phillip WoodJun 25, 2025
  54. Patrick SteinhardtJul 3, 2025
  55. Lucas Seiki OshiroJul 4, 2025
  56. 6/7 repo-info: add field layout.bareLucas Seiki Oshiro, Jun 19, 2025
  57. Patrick SteinhardtJul 3, 2025
  58. Lucas Seiki OshiroJul 3, 2025
  59. Phillip WoodJul 4, 2025
  60. 7/7 repo-info: add field layout.shallowLucas Seiki Oshiro, Jun 19, 2025
  61. Phillip WoodJun 23, 2025
  62. Lucas Seiki OshiroJun 23, 2025
  63. Phillip WoodJun 24, 2025
  64. Junio C HamanoJun 24, 2025
  65. Lucas Seiki OshiroJul 1, 2025
  66. phillip.wood123@gmail.comJul 2, 2025
  67. 0/5 repo-info: add new command for retrieving repository infoLucas Seiki Oshiro, Jul 6, 2025
  68. 1/5 repo-info: declare the repo-info commandLucas Seiki Oshiro, Jul 6, 2025
  69. 2/5 repo-info: add the --format flagLucas Seiki Oshiro, Jul 6, 2025
  70. 3/5 repo-info: add the field references.formatLucas Seiki Oshiro, Jul 6, 2025
  71. 4/5 repo-info: add field layout.bareLucas Seiki Oshiro, Jul 6, 2025
  72. 5/5 repo-info: add field layout.shallowLucas Seiki Oshiro, Jul 6, 2025
  73. Phillip WoodJul 8, 2025
  74. Lucas Seiki OshiroJul 8, 2025
  75. Phillip WoodJul 10, 2025
  76. Lucas Seiki OshiroJul 11, 2025
  77. Justin ToblerJul 11, 2025
  78. 0/4 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Jul 14, 2025
  79. 1/4 repo: declare the repo commandLucas Seiki Oshiro, Jul 14, 2025
  80. Karthik NayakJul 15, 2025
  81. Patrick SteinhardtJul 15, 2025
  82. Justin ToblerJul 15, 2025
  83. Lucas Seiki OshiroJul 20, 2025
  84. Justin ToblerJul 15, 2025
  85. 2/4 repo: add the field references.formatLucas Seiki Oshiro, Jul 14, 2025
  86. Patrick SteinhardtJul 15, 2025
  87. Lucas Seiki OshiroJul 18, 2025
  88. Karthik NayakJul 15, 2025
  89. Justin ToblerJul 15, 2025
  90. Patrick SteinhardtJul 16, 2025
  91. Justin ToblerJul 16, 2025
  92. Patrick SteinhardtJul 17, 2025
  93. Justin ToblerJul 17, 2025
  94. Lucas Seiki OshiroJul 18, 2025
  95. Justin ToblerJul 21, 2025
  96. 3/4 repo: add field layout.bareLucas Seiki Oshiro, Jul 14, 2025
  97. 4/4 repo: add field layout.shallowLucas Seiki Oshiro, Jul 14, 2025
  98. Oswald BuddenhagenJul 15, 2025
  99. Patrick SteinhardtJul 15, 2025
  100. Oswald BuddenhagenJul 15, 2025
  101. Justin ToblerJul 15, 2025
  102. Junio C HamanoJul 15, 2025
  103. Oswald BuddenhagenJul 17, 2025
  104. Patrick SteinhardtJul 17, 2025
  105. Junio C HamanoJul 16, 2025
  106. Junio C HamanoJul 16, 2025
  107. Lucas Seiki OshiroJul 21, 2025
  108. 0/5 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Jul 22, 2025
  109. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Jul 22, 2025
  110. Karthik NayakJul 22, 2025
  111. Junio C HamanoJul 22, 2025
  112. Lucas Seiki OshiroJul 23, 2025
  113. Junio C HamanoJul 23, 2025
  114. Patrick SteinhardtJul 24, 2025
  115. Junio C HamanoJul 24, 2025
  116. Patrick SteinhardtJul 25, 2025
  117. Lucas Seiki OshiroJul 26, 2025
  118. Junio C HamanoJul 28, 2025
  119. Lucas Seiki OshiroJul 23, 2025
  120. Jean-Noël AVILAJul 23, 2025
  121. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Jul 22, 2025
  122. Karthik NayakJul 22, 2025
  123. Justin ToblerJul 22, 2025
  124. Phillip WoodJul 23, 2025
  125. Lucas Seiki OshiroJul 23, 2025
  126. Lucas Seiki OshiroJul 23, 2025
  127. Patrick SteinhardtJul 24, 2025
  128. 3/5 repo: add field layout.bareLucas Seiki Oshiro, Jul 22, 2025
  129. 4/5 repo: add field layout.shallowLucas Seiki Oshiro, Jul 22, 2025
  130. 5/5 repo: add the --format flagLucas Seiki Oshiro, Jul 22, 2025
  131. Karthik NayakJul 22, 2025
  132. Patrick SteinhardtJul 24, 2025
  133. 0/5 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Jul 27, 2025
  134. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Jul 27, 2025
  135. Eric SunshineJul 27, 2025
  136. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Jul 27, 2025
  137. Eric SunshineJul 27, 2025
  138. Lucas Seiki OshiroJul 31, 2025
  139. Patrick SteinhardtJul 29, 2025
  140. Lucas Seiki OshiroJul 31, 2025
  141. 3/5 repo: add field layout.bareLucas Seiki Oshiro, Jul 27, 2025
  142. 4/5 repo: add field layout.shallowLucas Seiki Oshiro, Jul 27, 2025
  143. Eric SunshineJul 27, 2025
  144. 5/5 repo: add the --format flagLucas Seiki Oshiro, Jul 27, 2025
  145. Eric SunshineJul 27, 2025
  146. Ben KnobleJul 29, 2025
  147. Eric SunshineJul 29, 2025
  148. Ben KnobleJul 29, 2025
  149. Eric SunshineJul 29, 2025
  150. Lucas Seiki OshiroJul 31, 2025
  151. Lucas Seiki OshiroJul 31, 2025
  152. Eric SunshineJul 27, 2025
  153. Patrick SteinhardtJul 29, 2025
  154. Lucas Seiki OshiroJul 30, 2025
  155. 0/5 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Aug 1, 2025
  156. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 1, 2025
  157. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Aug 1, 2025
  158. Eric SunshineAug 1, 2025
  159. Lucas Seiki OshiroAug 3, 2025
  160. 3/5 repo: add the field layout.bareLucas Seiki Oshiro, Aug 1, 2025
  161. Eric SunshineAug 1, 2025
  162. Lucas Seiki OshiroAug 3, 2025
  163. Eric SunshineAug 3, 2025
  164. Patrick SteinhardtAug 5, 2025
  165. 4/5 repo: add the field layout.shallowLucas Seiki Oshiro, Aug 1, 2025
  166. Patrick SteinhardtAug 5, 2025
  167. 5/5 repo: add the --format flagLucas Seiki Oshiro, Aug 1, 2025
  168. Junio C HamanoAug 1, 2025
  169. Jean-Noël AVILAAug 1, 2025
  170. Eric SunshineAug 1, 2025
  171. Patrick SteinhardtAug 5, 2025
  172. Patrick SteinhardtAug 5, 2025
  173. 0/5 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Aug 6, 2025
  174. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 6, 2025
  175. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Aug 6, 2025
  176. Karthik NayakAug 7, 2025
  177. 3/5 repo: add the field layout.bareLucas Seiki Oshiro, Aug 6, 2025
  178. Patrick SteinhardtAug 7, 2025
  179. 4/5 repo: add the field layout.shallowLucas Seiki Oshiro, Aug 6, 2025
  180. 5/5 repo: add the --format flagLucas Seiki Oshiro, Aug 6, 2025
  181. Patrick SteinhardtAug 7, 2025
  182. Junio C HamanoAug 7, 2025
  183. Junio C HamanoAug 6, 2025
  184. Karthik NayakAug 7, 2025
  185. 0/5 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Aug 7, 2025
  186. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 7, 2025
  187. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Aug 7, 2025
  188. Eric SunshineAug 11, 2025
  189. Phillip WoodAug 11, 2025
  190. Junio C HamanoAug 11, 2025
  191. Lucas Seiki OshiroAug 13, 2025
  192. Eric SunshineAug 13, 2025
  193. Lucas Seiki OshiroAug 13, 2025
  194. Phillip WoodAug 14, 2025
  195. 3/5 repo: add the field layout.bareLucas Seiki Oshiro, Aug 7, 2025
  196. Eric SunshineAug 11, 2025
  197. Lucas Seiki OshiroAug 14, 2025
  198. Eric SunshineAug 14, 2025
  199. Junio C HamanoAug 14, 2025
  200. Eric SunshineAug 14, 2025
  201. Junio C HamanoAug 15, 2025
  202. Lucas Seiki OshiroAug 14, 2025
  203. Eric SunshineAug 14, 2025
  204. 4/5 repo: add the field layout.shallowLucas Seiki Oshiro, Aug 7, 2025
  205. 5/5 repo: add the --format flagLucas Seiki Oshiro, Aug 7, 2025
  206. Eric SunshineAug 11, 2025
  207. Patrick SteinhardtAug 8, 2025
  208. Junio C HamanoAug 8, 2025
  209. Karthik NayakAug 8, 2025
  210. 0/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 15, 2025
  211. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 15, 2025
  212. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Aug 15, 2025
  213. Junio C HamanoAug 15, 2025
  214. Lucas Seiki OshiroAug 15, 2025
  215. 3/5 repo: add the field layout.bareLucas Seiki Oshiro, Aug 15, 2025
  216. 4/5 repo: add the field layout.shallowLucas Seiki Oshiro, Aug 15, 2025
  217. Junio C HamanoAug 15, 2025
  218. 5/5 repo: add the --format flagLucas Seiki Oshiro, Aug 15, 2025
  219. Junio C HamanoAug 15, 2025
  220. 0/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 16, 2025
  221. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 16, 2025
  222. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Aug 16, 2025
  223. 3/5 repo: add the field layout.bareLucas Seiki Oshiro, Aug 16, 2025
  224. 4/5 repo: add the field layout.shallowLucas Seiki Oshiro, Aug 16, 2025
  225. 5/5 repo: add the --format flagLucas Seiki Oshiro, Aug 16, 2025
  226. Junio C HamanoAug 17, 2025

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.