Re: [PATCH v6 1/5] common-main: split init and exit code into new files
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 15, 2025, 22:40 UTC
- Message-ID
- <xmqqr053wvip.fsf@gitster.g>
- In-Reply-To
- <ff6cd62397ec2755d15e9d76f9af8a84b54a36c1.1736971328.git.steadmon@google.com>
Josh Steadmon <steadmon@google.com> writes:
Show 5 quoted lines
> 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.
Show 18 quoted lines
> 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.