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

Re: [GSoC RFC PATCH v2 5/7] repo-info: add the field references.format

From
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Date
Jul 4, 2025, 21:11 UTC
Message-ID
<6FDFCF2E-1148-4531-B957-FC61F42793F7@gmail.com>
In-Reply-To
<aGZqN-oqctJ79Chz@pks.im>
> Hm, okay. I guess later patches will add separate enums for each
> category, so this saves us a couple bytes as the number of categories
> grows.
Yeah, that's the idea.

However, even though it saves some bytes (we don't need to keep several empty fields), I used a union here mostly because of what it means semantically. In the print functions where I'm `switch`ing between values of one of those enums, the compiler complains if I missed something :-).

> I wonder a bit what it buys us that we have the difference between the
> category and reference format. Right now it feels like it can cause more
> errors that it prevents, as we now always have doubly-nested switches.

I reckon that my solution was a little hacky bit, but I tried to solve two things:

1. The plaintext/linewise/null-terminated format can return the values in the
order they were requested, like this:

``` $ git repo-info --format=plaintext layout.bare references.format layout.shallow layout.bare=true references.format=files layout.shallow=false

```
2. The same is not applicable to the JSON format, where the order shouldn't
matter and we can't have the same key repeating. Then it works like this:
```
$ git repo-info --format=json layout.bare references.format layout.shallow
{
  "references": {
    "format": "files"
  },
  "layout": {
    "bare": false,
    "shallow": false
  }
}
```
but not like this:
```
$ git repo-info --format=json layout.bare references.format layout.shallow
{
  "layout": {
    "bare": false
  },
  "references": {
    "format": "files"
  },
  "layout": {
    "shallow": false
  }
}
```
.

I'm still open to changes here. Perhaps keeping the same order in 1. is not so useful from this v2 as I'll always return the name of the keys (like, for example, git-config but unlike git-rev-parse).

Show 20 quoted lines
> Wouldn't it make more sense to only only pass around the fields as
> `repo_info_references_field`? We could then have two arrays that we
> define globally:
> 
>    static const char const* name_by_field[] = {
>        [FIELD_REFERENCES_FORMAT] = "references.format",
>    };
> 
>    static repo_info_category category_by_field[] = {
>        [FIELD_REFERENCES_FORMAT] = CATEGORY_REFERENCES,
>    };
> 
> So `name_by_field[FIELD_REFERENCES_FORMAT]` would yield the name and
> `category_by_field[CATEGORY_REFERENCES]` would yield its category. But
> the benefit is that you only need to pass around the field enum from now
> on, all other information is implicit.
> 
> The reverse information can also be obtained easily. To e.g. get all
> fields of a reference you'd iterate through `category_by_field` and take
> all array indices whose value matches the desired category.

A downside that I see is that it seems to be make the print_json function too complex. Currently, the complexities of the printing functions are (if I'm not missing something and ignoring the complexity of data the retrieval):

- plaintext: O(n_fields), as it only iterates over the fields
- json: O(n_fields + F), where F is number of possible fields that we can get,
  as we first fill the `<category>_fields` variables and then we iterate over
  each possible field to find if it was requested

In the plaintext format it wouldn't change too much, it would be still O(n_fields). But in the json format, it seems that will be something like (in pseudocode):

``` jw = json_writer fields_to_print = array with F values set to false

for (field in repo_info->fields)
    fields_to_print[field] = true
for (category in all_categories)
    object_started = false
    for (field in all_fields)
        if (category_by_field[field] == category)
            if (!object_started)
                jw_object_inline_begin_object(&jw, category)
            jw_object(&jw, name_by_field[field], retrieve(field))
    
    if (object_started)
        jw_end(&jw)
```

which would be O(n_fields + n_categories * F). To be honest I'm not exactly thinking about performance (which would be in fact negligible in this command), but how complex the code would be. If I understood it correctly, I wwould be trading nested `switch`es by nested `for`s.

But again, I'm still open to change everything again here!

Anyway, thank you for your time reviewing this patch, seeing what I did in the past weeks and joining again the discussion! :-)

Previous: Patrick SteinhardtNext: Lucas Seiki Oshiro
Message 55 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.