Re: [PATCH v6 1/5] common-main: split init and exit code into new files
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 16, 2025, 02:46 UTC
- Message-ID
- <xmqq34hjv5kw.fsf@gitster.g>
- In-Reply-To
- <xmqqr053wvip.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 41 quoted lines
> Josh Steadmon <steadmon@google.com> writes:
>
>> This split has previously been proposed ([1], [2]) to support fuzz tests
>> and unit tests by avoiding conflicting definitions for main(). However,
>> both of those issues were resolved by other methods of avoiding symbol
>> conflicts. Now we are trying to make libgit.a more self-contained, so
>> hopefully we can revisit this approach.
>
> Yay!
>
>> Additionally, move the initialization code out of main() into a new
>> init_git() function in its own file. Include this in libgit.a as well,
>> so that external users can share our setup code without calling our
>> main().
>
> Sounds good.
>
>> diff --git a/common-main.c b/common-main.c
>> index 8e68ac9e42..6b7ab077b0 100644
>> --- a/common-main.c
>> +++ b/common-main.c
>> @@ -1,92 +1,13 @@
>> ...
>> +#include "common-init.h"
>>
>> int main(int argc, const char **argv)
>> {
>> int result;
>>
>> + init_git(argv);
>> result = cmd_main(argc, argv);
>>
>> /* Not exit(3), but a wrapper calling our common_exit() */
>> exit(result);
>> }
>
> Nice. Very nice. I wasn't too carefully validating what we lost
> here is identical to what we added to init_git(), but hopefully
> others would spot and stop us if that is not the case.
>
> Thanks.Unfortunately, build based on meson does not seem to like the init_git() thing. Perhaps we need to add some missing files to relevant lists in meson.build file or something silly like that?
https://github.com/git/git/actions/runs/12800227601/job/35687658673#step:8:961