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

Re: [PATCH 3/6] shortlog: use designated initializer for "struct shortlog"

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 27, 2021, 10:52 UTC
Message-ID
<87lf3i1e7k.fsf@evledraar.gmail.com>
In-Reply-To
<94842a94-d168-2b61-4a44-0059ecbe1b36@gmail.com>
On Mon, Sep 27 2021, Phillip Wood wrote:
Show 39 quoted lines
> Hi Ævar
>
> On 27/09/2021 01:53, Ævar Arnfjörð Bjarmason wrote:
>> Change code added in 64093fc06a (blame,shortlog: don't make local
>> option variables static, 2016-06-13) to use a designated initializer
>> via a typical *_INIT macro pattern.
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>>   builtin/shortlog.c | 2 +-
>>   shortlog.h         | 4 ++++
>>   2 files changed, 5 insertions(+), 1 deletion(-)
>> diff --git a/builtin/shortlog.c b/builtin/shortlog.c
>> index 3e7ab1ca821..fa1f76cc51e 100644
>> --- a/builtin/shortlog.c
>> +++ b/builtin/shortlog.c
>> @@ -342,7 +342,7 @@ void shortlog_init(struct shortlog *log)
>>     int cmd_shortlog(int argc, const char **argv, const char
>> *prefix)
>>   {
>> -	struct shortlog log = { STRING_LIST_INIT_NODUP };
>> +	struct shortlog log = SHORTLOG_INIT;
>>   	struct rev_info rev;
>>   	int nongit = !startup_info->have_repository;
>>   diff --git a/shortlog.h b/shortlog.h
>> index 3f7e9aabcae..47892d6d604 100644
>> --- a/shortlog.h
>> +++ b/shortlog.h
>> @@ -28,6 +28,10 @@ struct shortlog {
>>   	FILE *file;
>>   };
>>   +#define SHORTLOG_INIT { \
>> +	.list = STRING_LIST_INIT_NODUP, \
>> +}
>> +
>>   void shortlog_init(struct shortlog *log);
>
> looking at this wouldn't it be better follow the pattern in the first
> patch in this series and replace shortlog_init() with a designated 
> initializer?

I've ejected this patch from a WIP re-roll, I don't know what I was thinking when I included it.

It's "correct", but one of those cases where we can't easily get rid of the not-a-macro init() function, so having a *_INIT macro that doesn't actually do the initialization for both users is just confusing.

Worse, that "nodup" is actually a like, the shortlog_init() function sets it to "dup", that issue pre-dated by change here, but I shouldn't have carried it forward.

Sorry!
Previous: Phillip WoodNext: Ævar Arnfjörð Bjarmason
Message 6 of 33 in “Non-trivial designated initializer conversion”
  1. 0/6 Non-trivial designated initializer conversionÆvar Arnfjörð Bjarmason, Sep 27, 2021
  2. 1/6 daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macroÆvar Arnfjörð Bjarmason, Sep 27, 2021
  3. 2/6 builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macroÆvar Arnfjörð Bjarmason, Sep 27, 2021
  4. 3/6 shortlog: use designated initializer for "struct shortlog"Ævar Arnfjörð Bjarmason, Sep 27, 2021
  5. Phillip WoodSep 27, 2021
  6. Ævar Arnfjörð BjarmasonSep 27, 2021
  7. 4/6 urlmatch.[ch]: add and use URLMATCH_CONFIG_INITÆvar Arnfjörð Bjarmason, Sep 27, 2021
  8. 5/6 builtin/remote.c: add and use a REF_STATES_INITÆvar Arnfjörð Bjarmason, Sep 27, 2021
  9. 6/6 builtin/remote.c: add and use SHOW_INFO_INITÆvar Arnfjörð Bjarmason, Sep 27, 2021
  10. 0/5 Non-trivial designated initializer conversionÆvar Arnfjörð Bjarmason, Sep 27, 2021
  11. 1/5 daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macroÆvar Arnfjörð Bjarmason, Sep 27, 2021
  12. 2/5 builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macroÆvar Arnfjörð Bjarmason, Sep 27, 2021
  13. 3/5 urlmatch.[ch]: add and use URLMATCH_CONFIG_INITÆvar Arnfjörð Bjarmason, Sep 27, 2021
  14. Junio C HamanoSep 27, 2021
  15. 4/5 builtin/remote.c: add and use a REF_STATES_INITÆvar Arnfjörð Bjarmason, Sep 27, 2021
  16. Junio C HamanoSep 27, 2021
  17. Ævar Arnfjörð BjarmasonSep 27, 2021
  18. Junio C HamanoSep 27, 2021
  19. 5/5 builtin/remote.c: add and use SHOW_INFO_INITÆvar Arnfjörð Bjarmason, Sep 27, 2021
  20. 0/6 Non-trivial designated initializer conversionÆvar Arnfjörð Bjarmason, Oct 1, 2021
  21. 1/6 daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macroÆvar Arnfjörð Bjarmason, Oct 1, 2021
  22. 2/6 builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macroÆvar Arnfjörð Bjarmason, Oct 1, 2021
  23. 3/6 urlmatch.[ch]: add and use URLMATCH_CONFIG_INITÆvar Arnfjörð Bjarmason, Oct 1, 2021
  24. 4/6 builtin/remote.c: add and use a REF_STATES_INITÆvar Arnfjörð Bjarmason, Oct 1, 2021
  25. 5/6 builtin/remote.c: add and use SHOW_INFO_INITÆvar Arnfjörð Bjarmason, Oct 1, 2021
  26. 6/6 unpack-trees.[ch]: define and use a UNPACK_TREES_OPTIONS_INITÆvar Arnfjörð Bjarmason, Oct 1, 2021
  27. Junio C HamanoOct 1, 2021
  28. 0/5 Non-trivial designated initializer conversionÆvar Arnfjörð Bjarmason, Oct 2, 2021
  29. 2/5 builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macroÆvar Arnfjörð Bjarmason, Oct 2, 2021
  30. 1/5 daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macroÆvar Arnfjörð Bjarmason, Oct 2, 2021
  31. 4/5 builtin/remote.c: add and use a REF_STATES_INITÆvar Arnfjörð Bjarmason, Oct 2, 2021
  32. 5/5 builtin/remote.c: add and use SHOW_INFO_INITÆvar Arnfjörð Bjarmason, Oct 2, 2021
  33. 3/5 urlmatch.[ch]: add and use URLMATCH_CONFIG_INITÆvar Arnfjörð Bjarmason, Oct 2, 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.