]> git.ipfire.org Git - thirdparty/git.git/commit
common-main: split init and exit code into new files
authorJosh Steadmon <steadmon@google.com>
Tue, 28 Jan 2025 22:01:37 +0000 (14:01 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Jan 2025 22:39:16 +0000 (14:39 -0800)
commit3f8f2abe05c0aeb0ea60768d44a99261ed456d44
tree99ae2334620ca9fae6b117e72c95d41d8f833a26
parent757161efcca150a9a96b312d9e780a071e601a03
common-main: split init and exit code into new files

Currently, object files in libgit.a reference common_exit(), which is
contained in common-main.o. However, common-main.o also includes main(),
which references cmd_main() in git.o, which in turn depends on all the
builtin/*.o objects.

We would like to allow external users to link libgit.a without needing
to include so many extra objects. Enable this by splitting common_exit()
and check_bug_if_BUG() into a new file common-exit.c, and add
common-exit.o to LIB_OBJS so that these are included in libgit.a.

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.

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().

[1] https://lore.kernel.org/git/Yp+wjCPhqieTku3X@google.com/
[2] https://lore.kernel.org/git/20230517-unit-tests-v2-v2-1-21b5b60f4b32@google.com/

Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
common-exit.c [new file with mode: 0644]
common-init.c [new file with mode: 0644]
common-init.h [new file with mode: 0644]
common-main.c
meson.build