Re: [GSoC RFC PATCH v3 0/5] repo-info: add new command for retrieving repository info
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Jul 10, 2025, 13:15 UTC
- Message-ID
- <35ba62ab-19c3-4092-aa7c-9043b898e284@gmail.com>
- In-Reply-To
- <C1991C27-9F57-47F7-A622-B3777BCFACCA@gmail.com>
Hi Lucas
On 08/07/2025 20:27, Lucas Seiki Oshiro wrote:
Show 7 quoted lines
> >> These all look like good changes. Looking through this series I do think that >> it would be more readable and maintainable if you adopted the table drive >> approach suggested by Junio. > > Today I had a meeting with my mentors (Karthik and Patrick), and yeah, this is > something that I'll change in v4.
That's great
Show 13 quoted lines
> Returning the keys in the same order as they were requested in the > null-terminated format is not so useful now that I'm keeping the keys in the > output. Dropping this assumption allows me to make this code simpler. > >> That way we would avoid the nested switch statements and each piece of >> information only needs to be retrieved once rather that having to retrieve it >> separately for the JSON and plaintext output. Below is a sketch of might look. >> Each key is handled by a callback and we have a table that maps key names to >> callbacks. For the json output we use one json writer per category to build >> output for each category. > > At first glance it looks good to me. It still seems to me that it needs to > somehow treat duplicated keys.
We can detect duplicate keys by adding an array
char seen_key[ARRAY_SIZE(handle)];
and checking to see if we've already set `seen_key[j]` in the inner loop. We should also detect invalid keys which we can do by setting a flag when we find the key or by moving the declaration of `j` into the outer loop and checking that `j < ARRAY_SIZE(handle)` at the end of the inner loop.
Thanks
Phillip