repo: refactoring leftover nits
Subsystems (2)
cover repo: refactoring leftover nits
Hi!
This patchset refactors git-repo-info after some suggestions and after the introduction of git-repo-structure. These changes were made:
1. CodingGuidelines now contains a instruction for naming arrays in singular (based on [1])
2. Rename a variable to its singular form in repo.c (based on [1])
3. Replace the function get_value_fn_for_key by a new function get_repo_info_field and make the structure of the function print_fields closer to the function print_all_fields (based on [1])
4. Rename the struct field to repo_info_field (after git-repo-structure)
5. Rename t1900-repo to t1900-repo-info (after git-repo-structure)
6. Use tr in output instead of the expected value (based on [2])
7. Replace NUL by _NUL_ in the documentation (based on [3])
8. Capitalize some paragraphs in the documentation (based on [4])
This patch is based on top of master 59438b41ab (Merge branch 'master' of github.com:git/git, 2026-02-18) with lo/repo-info-keys merged.
[1] [email protected]
[2] [email protected]
[3] 12814829.O9o76ZdvQC@piment-oiseau
[4] [email protected]
Lucas Seiki Oshiro (8):
CodingGuidelines: instruct to name arrays in singular
repo: rename repo_info_fields to repo_info_field
repo: replace get_value_fn_for_key by get_repo_info_field
repo: rename struct field to repo_info_field
t1900: rename t1900-repo to t1900-repo-info
t1901: use tr in git repo structure output instead of expected value Documentation/git-repo: replace 'NUL' with '_NUL_' Documentation/git-repo: capitalize format descriptions
Documentation/CodingGuidelines | 8 +++++
Documentation/git-repo.adoc | 8 ++---
builtin/repo.c | 44 ++++++++++++-------------
t/meson.build | 2 +-
t/{t1900-repo.sh => t1900-repo-info.sh} | 0
t/t1901-repo-structure.sh | 8 ++---
6 files changed, 39 insertions(+), 31 deletions(-)
rename t/{t1900-repo.sh => t1900-repo-info.sh} (100%)Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 1/8 CodingGuidelines: instruct to name arrays in singular
Arrays should be named in the singular form, ensuring that when accessing an element within an array (e.g. dog[0]) it's clear that we're referring to an element instead of a collection.
Add a new rule to CodingGuidelines asking for arrays to be named in singular instead of plural.
--- Documentation/CodingGuidelines | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/CodingGuidelines +8 -0
@@ -656,6 +656,14 @@ For C programs: unsigned other_field:1; unsigned field_with_longer_name:1; + - Array names should be named in the singular form. E.g.: + + char *dog[] = ...; + + and not: + + char *dogs[] = ...; + For Perl programs: - Most of the C guidelines above apply.
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH 1/8] CodingGuidelines: instruct to name arrays in singular
Quoted 11 lines · Lucas Seiki Oshiro
Arrays should be named in the singular form, ensuring that when accessing an element within an array (e.g. dog[0]) it's clear that we're referring to an element instead of a collection.
Add a new rule to CodingGuidelines asking for arrays to be named in singular instead of plural.
Signed-off-by Lucas Seiki Oshiro <[email protected]>---
Documentation/CodingGuidelines For C programs: · line 663
Quoted 8 lines
Documentation/CodingGuidelines +8
-0@@ -656,6 +656,14 @@ For C programs: + - Array names should be named in the singular form. E.g.: + + char *dog[] = ...; + + and not: + + char *dogs[] = ...; +
While this is generally true on this project, it is nevertheless incomplete. More specifically, the singular form is used for an array name in cases when the individual items of the array are the typical subject of use, for instance, when the consumer of the array is walking the dogs one at a time. However, there are cases in which the array is generally employed as a whole, rather than as its unit parts, in which the plural form for the name is preferable. An example would be when walking all the dogs at the same time.
Re: [PATCH 1/8] CodingGuidelines: instruct to name arrays in singular
Quoted 8 lines
While this is generally true on this project, it is nevertheless incomplete. More specifically, the singular form is used for an array name in cases when the individual items of the array are the typical subject of use, for instance, when the consumer of the array is walking the dogs one at a time. However, there are cases in which the array is generally employed as a whole, rather than as its unit parts, in which the plural form for the name is preferable. An example would be when walking all the dogs at the same time.
Thanks, Eric!
You explanation was very clear, and I'll use parts of it in the next version, giving credits to you, of course.
PATCH 2/8 repo: rename repo_info_fields to repo_info_field
In reply to Lucas Seiki OshiroRename repo_info_fields as repo_info_field, following the CodingGuidelines rule for naming arrays in singular. Rename all the references to that array accordingly.
--- builtin/repo.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
builtin/repo.c +10 -10
@@ -62,15 +62,15 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)return 0 ; } -/* repo_info_fields keys must be in lexicographical order */ -static const struct field repo_info_fields[] = { +/* repo_info_field keys must be in lexicographical order */ +static const struct field repo_info_field[] = { {"layout.bare" , get_layout_bare }, {"layout.shallow" , get_layout_shallow }, {"object.format" , get_object_format }, {"references.format" , get_references_format }, }; -static int repo_info_fields_cmp (const void *va,const void *vb) +static int repo_info_field_cmp (const void *va,const void *vb) {const struct field *a = va;const struct field *b = vb;
@@ -81,10 +81,10 @@ static int repo_info_fields_cmp(const void *va, const void *vb)static get_value_fn *get_value_fn_for_key (const char *key) {const struct field search_key = { key,NULL }; -const struct field *found =bsearch (&search_key, repo_info_fields, -ARRAY_SIZE (repo_info_fields), +const struct field *found =bsearch (&search_key, repo_info_field, +ARRAY_SIZE (repo_info_field),sizeof (*found), - repo_info_fields_cmp); + repo_info_field_cmp);return found ? found->get_value :NULL ; }
@@ -137,8 +137,8 @@ static int print_all_fields(struct repository *repo, {struct strbuf valbuf =STRBUF_INIT ; -for (size_t i =0 ; i <ARRAY_SIZE (repo_info_fields); i++) { -const struct field *field = &repo_info_fields[i]; +for (size_t i =0 ; i <ARRAY_SIZE (repo_info_field); i++) { +const struct field *field = &repo_info_field[i];strbuf_reset (&valbuf); field->get_value (repo, &valbuf);
@@ -164,8 +164,8 @@ static int print_keys(enum output_format format)die (_ ("--keys can only be used with --format=lines or --format=nul" )); } -for (size_t i =0 ; i <ARRAY_SIZE (repo_info_fields); i++) { -const struct field *field = &repo_info_fields[i]; +for (size_t i =0 ; i <ARRAY_SIZE (repo_info_field); i++) { +const struct field *field = &repo_info_field[i];printf ("%s%c" , field->key, sep); }
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 3/8 repo: replace get_value_fn_for_key by get_repo_info_field
In reply to Lucas Seiki OshiroRemove the function get_value_fn_for_key, which returns a function that retrieves a value for a certain repo info key. Introduce get_repo_info_field instead, which returns a struct field.
This refactor makes the structure of the function print_fields more consistent to the function print_all_fields, improving its readability.
--- builtin/repo.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
builtin/repo.c +6 -7
@@ -78,14 +78,15 @@ static int repo_info_field_cmp(const void *va, const void *vb)return strcmp (a->key, b->key); } -static get_value_fn *get_value_fn_for_key (const char *key) +static const struct field *get_repo_info_field (const char *key) {const struct field search_key = { key,NULL };const struct field *found =bsearch (&search_key, repo_info_field,ARRAY_SIZE (repo_info_field),sizeof (*found), repo_info_field_cmp); -return found ? found->get_value :NULL ; + +return found; } static void print_field(enum output_format format, const char *key,
@@ -113,18 +114,16 @@ static int print_fields(int argc, const char **argv,struct strbuf valbuf =STRBUF_INIT ;for (int i =0 ; i < argc; i++) { -get_value_fn *get_value;const char *key = argv[i]; +const struct field *field =get_repo_info_field (key); - get_value =get_value_fn_for_key (key); - -if (!get_value) { +if (!field) { ret =error (_ ("key '%s' not found" ), key);continue ; }strbuf_reset (&valbuf); -get_value (repo, &valbuf); + field->get_value (repo, &valbuf);print_field (format, key, valbuf.buf); }
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 4/8 repo: rename struct field to repo_info_field
In reply to Lucas Seiki OshiroChange the name of the struct field to repo_info_field, making it explicit that it is an internal data type of git-repo-info.
--- builtin/repo.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
builtin/repo.c +14 -13
@@ -31,7 +31,7 @@ enum output_format { FORMAT_NUL_TERMINATED, }; -struct field { +struct repo_info_field {const char *key;get_value_fn *get_value; };
@@ -63,7 +63,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf) }/* repo_info_field keys must be in lexicographical order */ -static const struct field repo_info_field[] = { +static const struct repo_info_field repo_info_field[] = { {"layout.bare" , get_layout_bare }, {"layout.shallow" , get_layout_shallow }, {"object.format" , get_object_format },
@@ -72,19 +72,20 @@ static const struct field repo_info_field[] = {static int repo_info_field_cmp (const void *va,const void *vb) { -const struct field *a = va; -const struct field *b = vb; +const struct repo_info_field *a = va; +const struct repo_info_field *b = vb;return strcmp (a->key, b->key); } -static const struct field *get_repo_info_field (const char *key) +static const struct repo_info_field *get_repo_info_field (const char *key) { -const struct field search_key = { key,NULL }; -const struct field *found =bsearch (&search_key, repo_info_field, -ARRAY_SIZE (repo_info_field), -sizeof (*found), - repo_info_field_cmp); +const struct repo_info_field search_key = { key,NULL }; +const struct repo_info_field *found =bsearch (&search_key, + repo_info_field, +ARRAY_SIZE (repo_info_field), +sizeof (*found), + repo_info_field_cmp);return found; }
@@ -115,7 +116,7 @@ static int print_fields(int argc, const char **argv,for (int i =0 ; i < argc; i++) {const char *key = argv[i]; -const struct field *field =get_repo_info_field (key); +const struct repo_info_field *field =get_repo_info_field (key);if (!field) { ret =error (_ ("key '%s' not found" ), key);
@@ -137,7 +138,7 @@ static int print_all_fields(struct repository *repo,struct strbuf valbuf =STRBUF_INIT ;for (size_t i =0 ; i <ARRAY_SIZE (repo_info_field); i++) { -const struct field *field = &repo_info_field[i]; +const struct repo_info_field *field = &repo_info_field[i];strbuf_reset (&valbuf); field->get_value (repo, &valbuf);
@@ -164,7 +165,7 @@ static int print_keys(enum output_format format) }for (size_t i =0 ; i <ARRAY_SIZE (repo_info_field); i++) { -const struct field *field = &repo_info_field[i]; +const struct repo_info_field *field = &repo_info_field[i];printf ("%s%c" , field->key, sep); }
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 5/8 t1900: rename t1900-repo to t1900-repo-info
In reply to Lucas Seiki OshiroSince the commit bbb2b93348 (builtin/repo: introduce structure subcommand, 2025-10-21), t1901 specifically tests git-repo-structure. Rename t1900-repo to t1900-repo-info to clarify that it focus solely on git-repo-info subcommand.
---
t/meson.build | 2 +-
t/{t1900-repo.sh => t1900-repo-info.sh} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename t/{t1900-repo.sh => t1900-repo-info.sh} (100%)t/meson.build +1 -1
@@ -240,7 +240,7 @@ integration_tests = [ 't1700-split-index.sh', 't1701-racy-split-index.sh', 't1800-hook.sh', - 't1900-repo.sh', + 't1900-repo-info.sh', 't1901-repo-structure.sh', 't2000-conflict-when-checking-files-out.sh', 't2002-checkout-cache-u.sh',
t/t1900-repo-info.sh renamed from t/t1900-repo.sh +0 -0
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 6/8 t1901: use tr in git repo structure output instead of expected value
In reply to Lucas Seiki OshiroThe test 'keyvalue and nul format', as it description says, test both keyvalue and nul format. These formats are similar, differing only in their field separator (= in the former, LF in the latter) and their record separator (LF in the former, NUL in the latter). This way, both formats can be tested using the same expected output and only replacing the separators in one of the output formats.
Adjust the output of git repo structure --format=nul in t1901, matching the --format=keyvalue ones. Compare this output against the same value expected from --format=keyvalue.
--- t/t1901-repo-structure.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
t/t1901-repo-structure.sh +4 -4
@@ -145,18 +145,18 @@ test_expect_success SHA1 'lines and nul format' ' test_cmp expect out && test_line_count = 0 err && - # Replace key and value delimiters for nul format. - tr "\n=" "\0\n" <expect >expect_nul && git repo structure --format=nul >out 2>err && + tr "\012" "=" <out | tr "\000" "\012" >actual && - test_cmp expect_nul out && + test_cmp expect actual && test_line_count = 0 err && # "-z", as a synonym to "--format=nul", participates in the # usual "last one wins" rule. git repo structure --format=table -z >out 2>err && + tr "\012" "=" <out | tr "\000" "\012" >actual && - test_cmp expect_nul out && + test_cmp expect actual && test_line_count = 0 err ) '
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH 6/8] t1901: use tr in git repo structure output instead of expected value
Quoted 6 lines · Lucas Seiki Oshiro
The test 'keyvalue and nul format', as it description says, test both keyvalue and nul format. These formats are similar, differing only in their field separator (= in the former, LF in the latter) and their record separator (LF in the former, NUL in the latter). This way, both formats can be tested using the same expected output and only replacing the separators in one of the output formats.
Hm, okay. I have to admit I don't quite understand what we gain here. We have to use tr(1) regardless of how we do it, and I cannot see that either of these alternatives is clearly superior compared to the other.
t/t1901-repo-structure.sh test_expect_success SHA1 'lines and nul format' ' · line 149
Quoted 12 lines
t/t1901-repo-structure.sh +1
-2@@ -145,18 +145,18 @@ test_expect_success SHA1 'lines and nul format' ' test_cmp expect out && test_line_count = 0 err && - # Replace key and value delimiters for nul format. - tr "\n=" "\0\n" <expect >expect_nul && git repo structure --format=nul >out 2>err && + tr "\012" "=" <out | tr "\000" "\012" >actual &&
We can combine the two calls to tr(1) to a single one.
t/t1901-repo-structure.sh test_expect_success SHA1 'lines and nul format' ' · line 157
Quoted 8 lines
t/t1901-repo-structure.sh +2
-1- test_cmp expect_nul out && + test_cmp expect actual && test_line_count = 0 err && # "-z", as a synonym to "--format=nul", participates in the # usual "last one wins" rule. git repo structure --format=table -z >out 2>err && + tr "\012" "=" <out | tr "\000" "\012" >actual &&
Same here.
Patrick
Re: [PATCH 6/8] t1901: use tr in git repo structure output instead of expected value
Quoted 11 lines
Quoted 7 lines
The test 'keyvalue and nul format', as it description says, test both keyvalue and nul format. These formats are similar, differing only in their field separator (= in the former, LF in the latter) and their record separator (LF in the former, NUL in the latter). This way, both formats can be tested using the same expected output and only replacing the separators in one of the output formats.
Hm, okay. I have to admit I don't quite understand what we gain here. We have to use tr(1) regardless of how we do it, and I cannot see that either of these alternatives is clearly superior compared to the other.
I should be clearer about this in my description. Of course, both approaches work here but this won't output a NUL character if the test fails, which could be considered as a binary file to diff.
Actually, this is something that Junio saw in a previous patch, and this was his comment about it [1]:
Quoted 7 lines
* Instead of munging the expected file so that it contains a NUL, and compare the actual output with it, munge the NUL terminated outout to make it text and compare with the expected file in text format. This matters when tests start to fail as
test_cmpwill show the "diff" output when it fails, and comparing NUL terminated files, which are "binary" in the eyes of the "diff" utility.
But anyway, I'll make it clear in my next version.
Thanks!
PATCH 7/8 Documentation/git-repo: replace 'NUL' with '_NUL_'
In reply to Lucas Seiki OshiroReplace all occurrences of "NUL" by "_NUL_" in git-repo.adoc, following the convention used by other documentation files.
--- Documentation/git-repo.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/git-repo.adoc +2 -2
@@ -40,7 +40,7 @@ supported: `nul`::: similar to `lines`, but using a newline character as the delimiter - between the key and the value and using a NUL character after each value. + between the key and the value and using a _NUL_ character after each value. This format is better suited for being parsed by another applications than `lines`. Unlike in the `lines` format, the values are never quoted. +
@@ -80,7 +80,7 @@ supported: configuration variable `core.quotePath` (see linkgit:git-config[1]). `nul`::: - Similar to `lines`, but uses a NUL character to delimit between + Similar to `lines`, but uses a _NUL_ character to delimit between key-value pairs instead of a newline. Also uses a newline character as the delimiter between the key and value instead of '='. Unlike the `lines` format, values containing "unusual" characters are never
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 8/8 Documentation/git-repo: capitalize format descriptions
In reply to Lucas Seiki OshiroThe descriptions for the git-repo output formats are in lowercase. Capitalize these descriptions, making them consistent with the rest of the documentation.
--- Documentation/git-repo.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/git-repo.adoc +2 -2
@@ -33,13 +33,13 @@ supported: + `lines`::: - output key-value pairs one per line using the `=` character as + Output key-value pairs one per line using the `=` character as the delimiter between the key and the value. Values containing "unusual" characters are quoted as explained for the configuration variable `core.quotePath` (see linkgit:git-config[1]). This is the default. `nul`::: - similar to `lines`, but using a newline character as the delimiter + Similar to `lines`, but using a newline character as the delimiter between the key and the value and using a _NUL_ character after each value. This format is better suited for being parsed by another applications than `lines`. Unlike in the `lines` format, the values are never quoted.
Signature · 1 line
2.50.1 (Apple Git-155)
v2 cover repo: refactoring leftover nits
In reply to Lucas Seiki OshiroHi!
There are only three changes in this version:
1. Applying Eric's suggestion of instructing to name array plural if we're dealing with the values as a whole
2. Making it clear why we should replace the NUL characters in the files consumed by tes_cmp
3. Replacing characters in just one tr call instead of two
Lucas Seiki Oshiro (8):
CodingGuidelines: instruct to name arrays in singular
repo: rename repo_info_fields to repo_info_field
repo: replace get_value_fn_for_key by get_repo_info_field
repo: rename struct field to repo_info_field
t1900: rename t1900-repo to t1900-repo-info
t1901: adjust nul format output instead of expected value Documentation/git-repo: replace 'NUL' with '_NUL_' Documentation/git-repo: capitalize format descriptions
Documentation/CodingGuidelines | 13 ++++++++
Documentation/git-repo.adoc | 8 ++---
builtin/repo.c | 44 ++++++++++++-------------
t/meson.build | 2 +-
t/{t1900-repo.sh => t1900-repo-info.sh} | 0
t/t1901-repo-structure.sh | 8 ++---
6 files changed, 44 insertions(+), 31 deletions(-)
rename t/{t1900-repo.sh => t1900-repo-info.sh} (100%)Range-diff against v1:
1: 041d00fdbf ! 1: 51cfa0901e CodingGuidelines: instruct to name arrays in singular
@@ Commit message
Add a new rule to CodingGuidelines asking for arrays to be named in singular instead of plural.
+ Helped-by: Eric Sunshine <[email protected]>
## Documentation/CodingGuidelines ##
@@ Documentation/CodingGuidelines: For C programs:
unsigned other_field:1;
unsigned field_with_longer_name:1;
-+ - Array names should be named in the singular form. E.g.:
++ - Array names should be named in the singular form if the individual items are
++ subject of use. E.g.:
+
+ char *dog[] = ...;
++ walk_dog(dog[0]);
++ walk_dog(dog[1]);
+
-+ and not:
++ Cases where the array is employed as a whole rather than as its unit parts,
++ the plural forms is preferable. E.g:
+
+ char *dogs[] = ...;
++ walk_all_dogs(dogs);
+
For Perl programs:
2: ccf0e85919 = 2: 35feb400af repo: rename repo_info_fields to repo_info_field 3: eccfcf8164 = 3: f2926725a2 repo: replace get_value_fn_for_key by get_repo_info_field 4: b360e3ea11 = 4: 03874e8021 repo: rename struct field to repo_info_field 5: 3c4ae0550d = 5: 02682a08e7 t1900: rename t1900-repo to t1900-repo-info 6: 63b516b424 ! 6: 10accd800a t1901: use tr in git repo structure output instead of expected value
@@ Metadata
Author: Lucas Seiki Oshiro <[email protected]>
## Commit message ##
- t1901: use tr in git repo structure output instead of expected value
+ t1901: adjust nul format output instead of expected value
The test 'keyvalue and nul format', as it description says, test both
- keyvalue and nul format. These formats are similar, differing only in
+ keyvalue and nul format. These formats are similar, differing only in
their field separator (= in the former, LF in the latter) and their record separator (LF in the former, NUL in the latter). This way, both formats can be tested using the same expected output and only replacing the separators in one of the output formats.
+ However, it is not desirable to have a NUL character in the files
+ compared by test_cmp because, if that assetion fails, diff will consider
+ them binary files and won't display the differences properly.
+
Adjust the output of git repo structure --format=nul in t1901, matching the --format=keyvalue ones. Compare this output against the same value expected
- from --format=keyvalue.
+ from --format=keyvalue, without using files with NUL characters in
+ test_cmp.
@@ t/t1901-repo-structure.sh: test_expect_success SHA1 'lines and nul format' '
- # Replace key and value delimiters for nul format.
- tr "\n=" "\0\n" <expect >expect_nul &&
git repo structure --format=nul >out 2>err &&
-+ tr "\012" "=" <out | tr "\000" "\012" >actual &&
++ tr "\012\000" "=\012" <out >actual &&
- test_cmp expect_nul out &&
+ test_cmp expect actual &&
@@ t/t1901-repo-structure.sh: test_expect_success SHA1 'lines and nul format' '
# "-z", as a synonym to "--format=nul", participates in the # usual "last one wins" rule.
git repo structure --format=table -z >out 2>err &&
-+ tr "\012" "=" <out | tr "\000" "\012" >actual &&
++ tr "\012\000" "=\012" <out >actual &&
- test_cmp expect_nul out &&
+ test_cmp expect actual &&
7: 6e0be4e746 = 7: 508a2af2e3 Documentation/git-repo: replace 'NUL' with '_NUL_' 8: e4125e2370 = 8: cbf17b7abd Documentation/git-repo: capitalize format descriptions
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 1/8 CodingGuidelines: instruct to name arrays in singular
Arrays should be named in the singular form, ensuring that when accessing an element within an array (e.g. dog[0]) it's clear that we're referring to an element instead of a collection.
Add a new rule to CodingGuidelines asking for arrays to be named in singular instead of plural.
--- Documentation/CodingGuidelines | 13 +++++++++++++ 1 file changed, 13 insertions(+)
Documentation/CodingGuidelines +13 -0
@@ -658,6 +658,19 @@ For C programs: unsigned other_field:1; unsigned field_with_longer_name:1; + - Array names should be named in the singular form if the individual items are + subject of use. E.g.: + + char *dog[] = ...; + walk_dog(dog[0]); + walk_dog(dog[1]); + + Cases where the array is employed as a whole rather than as its unit parts, + the plural forms is preferable. E.g: + + char *dogs[] = ...; + walk_all_dogs(dogs); + For Perl programs: - Most of the C guidelines above apply.
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 2/8 repo: rename repo_info_fields to repo_info_field
In reply to Lucas Seiki OshiroRename repo_info_fields as repo_info_field, following the CodingGuidelines rule for naming arrays in singular. Rename all the references to that array accordingly.
--- builtin/repo.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
builtin/repo.c +10 -10
@@ -62,15 +62,15 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)return 0 ; } -/* repo_info_fields keys must be in lexicographical order */ -static const struct field repo_info_fields[] = { +/* repo_info_field keys must be in lexicographical order */ +static const struct field repo_info_field[] = { {"layout.bare" , get_layout_bare }, {"layout.shallow" , get_layout_shallow }, {"object.format" , get_object_format }, {"references.format" , get_references_format }, }; -static int repo_info_fields_cmp (const void *va,const void *vb) +static int repo_info_field_cmp (const void *va,const void *vb) {const struct field *a = va;const struct field *b = vb;
@@ -81,10 +81,10 @@ static int repo_info_fields_cmp(const void *va, const void *vb)static get_value_fn *get_value_fn_for_key (const char *key) {const struct field search_key = { key,NULL }; -const struct field *found =bsearch (&search_key, repo_info_fields, -ARRAY_SIZE (repo_info_fields), +const struct field *found =bsearch (&search_key, repo_info_field, +ARRAY_SIZE (repo_info_field),sizeof (*found), - repo_info_fields_cmp); + repo_info_field_cmp);return found ? found->get_value :NULL ; }
@@ -137,8 +137,8 @@ static int print_all_fields(struct repository *repo, {struct strbuf valbuf =STRBUF_INIT ; -for (size_t i =0 ; i <ARRAY_SIZE (repo_info_fields); i++) { -const struct field *field = &repo_info_fields[i]; +for (size_t i =0 ; i <ARRAY_SIZE (repo_info_field); i++) { +const struct field *field = &repo_info_field[i];strbuf_reset (&valbuf); field->get_value (repo, &valbuf);
@@ -164,8 +164,8 @@ static int print_keys(enum output_format format)die (_ ("--keys can only be used with --format=lines or --format=nul" )); } -for (size_t i =0 ; i <ARRAY_SIZE (repo_info_fields); i++) { -const struct field *field = &repo_info_fields[i]; +for (size_t i =0 ; i <ARRAY_SIZE (repo_info_field); i++) { +const struct field *field = &repo_info_field[i];printf ("%s%c" , field->key, sep); }
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 3/8 repo: replace get_value_fn_for_key by get_repo_info_field
In reply to Lucas Seiki OshiroRemove the function get_value_fn_for_key, which returns a function that retrieves a value for a certain repo info key. Introduce get_repo_info_field instead, which returns a struct field.
This refactor makes the structure of the function print_fields more consistent to the function print_all_fields, improving its readability.
--- builtin/repo.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
builtin/repo.c +6 -7
@@ -78,14 +78,15 @@ static int repo_info_field_cmp(const void *va, const void *vb)return strcmp (a->key, b->key); } -static get_value_fn *get_value_fn_for_key (const char *key) +static const struct field *get_repo_info_field (const char *key) {const struct field search_key = { key,NULL };const struct field *found =bsearch (&search_key, repo_info_field,ARRAY_SIZE (repo_info_field),sizeof (*found), repo_info_field_cmp); -return found ? found->get_value :NULL ; + +return found; } static void print_field(enum output_format format, const char *key,
@@ -113,18 +114,16 @@ static int print_fields(int argc, const char **argv,struct strbuf valbuf =STRBUF_INIT ;for (int i =0 ; i < argc; i++) { -get_value_fn *get_value;const char *key = argv[i]; +const struct field *field =get_repo_info_field (key); - get_value =get_value_fn_for_key (key); - -if (!get_value) { +if (!field) { ret =error (_ ("key '%s' not found" ), key);continue ; }strbuf_reset (&valbuf); -get_value (repo, &valbuf); + field->get_value (repo, &valbuf);print_field (format, key, valbuf.buf); }
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 4/8 repo: rename struct field to repo_info_field
In reply to Lucas Seiki OshiroChange the name of the struct field to repo_info_field, making it explicit that it is an internal data type of git-repo-info.
--- builtin/repo.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
builtin/repo.c +14 -13
@@ -31,7 +31,7 @@ enum output_format { FORMAT_NUL_TERMINATED, }; -struct field { +struct repo_info_field {const char *key;get_value_fn *get_value; };
@@ -63,7 +63,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf) }/* repo_info_field keys must be in lexicographical order */ -static const struct field repo_info_field[] = { +static const struct repo_info_field repo_info_field[] = { {"layout.bare" , get_layout_bare }, {"layout.shallow" , get_layout_shallow }, {"object.format" , get_object_format },
@@ -72,19 +72,20 @@ static const struct field repo_info_field[] = {static int repo_info_field_cmp (const void *va,const void *vb) { -const struct field *a = va; -const struct field *b = vb; +const struct repo_info_field *a = va; +const struct repo_info_field *b = vb;return strcmp (a->key, b->key); } -static const struct field *get_repo_info_field (const char *key) +static const struct repo_info_field *get_repo_info_field (const char *key) { -const struct field search_key = { key,NULL }; -const struct field *found =bsearch (&search_key, repo_info_field, -ARRAY_SIZE (repo_info_field), -sizeof (*found), - repo_info_field_cmp); +const struct repo_info_field search_key = { key,NULL }; +const struct repo_info_field *found =bsearch (&search_key, + repo_info_field, +ARRAY_SIZE (repo_info_field), +sizeof (*found), + repo_info_field_cmp);return found; }
@@ -115,7 +116,7 @@ static int print_fields(int argc, const char **argv,for (int i =0 ; i < argc; i++) {const char *key = argv[i]; -const struct field *field =get_repo_info_field (key); +const struct repo_info_field *field =get_repo_info_field (key);if (!field) { ret =error (_ ("key '%s' not found" ), key);
@@ -137,7 +138,7 @@ static int print_all_fields(struct repository *repo,struct strbuf valbuf =STRBUF_INIT ;for (size_t i =0 ; i <ARRAY_SIZE (repo_info_field); i++) { -const struct field *field = &repo_info_field[i]; +const struct repo_info_field *field = &repo_info_field[i];strbuf_reset (&valbuf); field->get_value (repo, &valbuf);
@@ -164,7 +165,7 @@ static int print_keys(enum output_format format) }for (size_t i =0 ; i <ARRAY_SIZE (repo_info_field); i++) { -const struct field *field = &repo_info_field[i]; +const struct repo_info_field *field = &repo_info_field[i];printf ("%s%c" , field->key, sep); }
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 5/8 t1900: rename t1900-repo to t1900-repo-info
In reply to Lucas Seiki OshiroSince the commit bbb2b93348 (builtin/repo: introduce structure subcommand, 2025-10-21), t1901 specifically tests git-repo-structure. Rename t1900-repo to t1900-repo-info to clarify that it focus solely on git-repo-info subcommand.
---
t/meson.build | 2 +-
t/{t1900-repo.sh => t1900-repo-info.sh} | 0
2 files changed, 1 insertion(+), 1 deletion(-)
rename t/{t1900-repo.sh => t1900-repo-info.sh} (100%)t/meson.build +1 -1
@@ -240,7 +240,7 @@ integration_tests = [ 't1700-split-index.sh', 't1701-racy-split-index.sh', 't1800-hook.sh', - 't1900-repo.sh', + 't1900-repo-info.sh', 't1901-repo-structure.sh', 't2000-conflict-when-checking-files-out.sh', 't2002-checkout-cache-u.sh',
t/t1900-repo-info.sh renamed from t/t1900-repo.sh +0 -0
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 6/8 t1901: adjust nul format output instead of expected value
In reply to Lucas Seiki OshiroThe test 'keyvalue and nul format', as it description says, test both keyvalue and nul format. These formats are similar, differing only in their field separator (= in the former, LF in the latter) and their record separator (LF in the former, NUL in the latter). This way, both formats can be tested using the same expected output and only replacing the separators in one of the output formats.
However, it is not desirable to have a NUL character in the files compared by test_cmp because, if that assetion fails, diff will consider them binary files and won't display the differences properly.
Adjust the output of git repo structure --format=nul in t1901, matching the --format=keyvalue ones. Compare this output against the same value expected from --format=keyvalue, without using files with NUL characters in test_cmp.
--- t/t1901-repo-structure.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
t/t1901-repo-structure.sh +4 -4
@@ -145,18 +145,18 @@ test_expect_success SHA1 'lines and nul format' ' test_cmp expect out && test_line_count = 0 err && - # Replace key and value delimiters for nul format. - tr "\n=" "\0\n" <expect >expect_nul && git repo structure --format=nul >out 2>err && + tr "\012\000" "=\012" <out >actual && - test_cmp expect_nul out && + test_cmp expect actual && test_line_count = 0 err && # "-z", as a synonym to "--format=nul", participates in the # usual "last one wins" rule. git repo structure --format=table -z >out 2>err && + tr "\012\000" "=\012" <out >actual && - test_cmp expect_nul out && + test_cmp expect actual && test_line_count = 0 err ) '
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 7/8 Documentation/git-repo: replace 'NUL' with '_NUL_'
In reply to Lucas Seiki OshiroReplace all occurrences of "NUL" by "_NUL_" in git-repo.adoc, following the convention used by other documentation files.
--- Documentation/git-repo.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/git-repo.adoc +2 -2
@@ -40,7 +40,7 @@ supported: `nul`::: similar to `lines`, but using a newline character as the delimiter - between the key and the value and using a NUL character after each value. + between the key and the value and using a _NUL_ character after each value. This format is better suited for being parsed by another applications than `lines`. Unlike in the `lines` format, the values are never quoted. +
@@ -80,7 +80,7 @@ supported: configuration variable `core.quotePath` (see linkgit:git-config[1]). `nul`::: - Similar to `lines`, but uses a NUL character to delimit between + Similar to `lines`, but uses a _NUL_ character to delimit between key-value pairs instead of a newline. Also uses a newline character as the delimiter between the key and value instead of '='. Unlike the `lines` format, values containing "unusual" characters are never
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v2 8/8 Documentation/git-repo: capitalize format descriptions
In reply to Lucas Seiki OshiroThe descriptions for the git-repo output formats are in lowercase. Capitalize these descriptions, making them consistent with the rest of the documentation.
--- Documentation/git-repo.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/git-repo.adoc +2 -2
@@ -33,13 +33,13 @@ supported: + `lines`::: - output key-value pairs one per line using the `=` character as + Output key-value pairs one per line using the `=` character as the delimiter between the key and the value. Values containing "unusual" characters are quoted as explained for the configuration variable `core.quotePath` (see linkgit:git-config[1]). This is the default. `nul`::: - similar to `lines`, but using a newline character as the delimiter + Similar to `lines`, but using a newline character as the delimiter between the key and the value and using a _NUL_ character after each value. This format is better suited for being parsed by another applications than `lines`. Unlike in the `lines` format, the values are never quoted.
Signature · 1 line
2.50.1 (Apple Git-155)
I forgot to say in the cover letter, but this was built on top of the current master (7c02d39fc2 (The 6th batch, 2026-02-20)) with lo/repo-info-keys merge, which is already marked as "Will merge to 'master'".
Quoted 9 lines · Lucas Seiki Oshiro
Hi!
There are only three changes in this version:
1. Applying Eric's suggestion of instructing to name array plural if we're dealing with the values as a whole
2. Making it clear why we should replace the NUL characters in the files consumed bytes_cmp
3. Replacing characters in just one tr call instead of two
All look great. The first patch has still rooms to bikeshed, but let's take this iteration and mark it for 'next'.
Thanks.