{"thread":{"id":"59737","subject":"[PATCH] lib: add new libgit-builtin","startedAt":"2023-05-12T22:52:06Z","lastAt":"2023-05-12T22:52:06Z","messageCount":1,"participants":["Felipe Contreras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"477236","messageId":"20230512225200.2214534-1-felipe.contreras@gmail.com","threadId":"59737","inReplyTo":null,"subject":"[PATCH] lib: add new libgit-builtin","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2023-05-12T22:52:00Z","receivedAt":"2023-05-12T22:52:06Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Since its creation in 0a02ce72d9 (Clean up the Makefile a bit.,\n2005-04-18), libgit.a has been used as dumping ground for everything all\ngit commands use.\n\nWhen the code was split between `*.c` and `builtin/*.c` it was never\nclarified what belongs in what category.\n\nThe code in `*.c` can be shared by all builtins, but so can the code in\n`builtin/*.c`.\n\nThere's no practical difference.\n\nIn order to attempt to start decoupling libgit.a from the `git` binary,\nlet's create a new libgit-builtin.a library meant only for the code in\n`builtin/*.c`.\n\nIdeally eventually libgit.a would not contain code that is specific to\n`git`, only code that is generic and could be used by projects outside\ngit.git.\n\nThis is an essential step that has to be done if there's any hope of\never having a public libgit.so library.\n\nThe choice of notes-utils.c is mostly arbitrary, but its functions had\nbeen discussed before as a roadblock for a proper libgit. In particular\nsomething like `init_copy_notes_for_rewrite(\"am\")` does not seem like\nsomething anyone outside `git` would want to call.\n\nCc: Emily Shaffer <nasamuffin@google.com>\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n\nAfter re-reading a previous thread about the lbification of git [1], I\nrealized `init_copy_notes_for_rewrite()` and others which now belong in\nnotes-utils.c are good candidates to start splitting away from what\neventually should be a public libgit.so library.\n\n[1] https://lore.kernel.org/git/1370712574-27688-1-git-send-email-felipe.contreras@gmail.com/\n\n Makefile | 13 ++++++++++---\n 1 file changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex e440728c24..84cbb35828 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -668,6 +668,7 @@ FUZZ_OBJS =\n FUZZ_PROGRAMS =\n GIT_OBJS =\n LIB_OBJS =\n+BUILTIN_LIB_OBJS =\n SCALAR_OBJS =\n OBJECTS =\n OTHER_PROGRAMS =\n@@ -916,6 +917,7 @@ export PYTHON_PATH\n TEST_SHELL_PATH = $(SHELL_PATH)\n \n LIB_FILE = libgit.a\n+BUILTIN_LIB_FILE = libgit-builtin.a\n XDIFF_LIB = xdiff/lib.a\n REFTABLE_LIB = reftable/libreftable.a\n REFTABLE_TEST_LIB = reftable/libreftable_test.a\n@@ -1071,7 +1073,6 @@ LIB_OBJS += negotiator/noop.o\n LIB_OBJS += negotiator/skipping.o\n LIB_OBJS += notes-cache.o\n LIB_OBJS += notes-merge.o\n-LIB_OBJS += notes-utils.o\n LIB_OBJS += notes.o\n LIB_OBJS += object-file.o\n LIB_OBJS += object-name.o\n@@ -1194,6 +1195,8 @@ LIB_OBJS += ws.o\n LIB_OBJS += wt-status.o\n LIB_OBJS += xdiff-interface.o\n \n+BUILTIN_LIB_OBJS += notes-utils.o\n+\n BUILTIN_OBJS += builtin/add.o\n BUILTIN_OBJS += builtin/am.o\n BUILTIN_OBJS += builtin/annotate.o\n@@ -1332,7 +1335,7 @@ THIRD_PARTY_SOURCES += sha1collisiondetection/%\n THIRD_PARTY_SOURCES += sha1dc/%\n \n # xdiff and reftable libs may in turn depend on what is in libgit.a\n-GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)\n+GITLIBS = common-main.o $(LIB_FILE) $(BUILTIN_LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)\n EXTLIBS =\n \n GIT_USER_AGENT = git/$(GIT_VERSION)\n@@ -2655,6 +2658,7 @@ TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST\n test-objs: $(TEST_OBJS)\n \n GIT_OBJS += $(LIB_OBJS)\n+GIT_OBJS += $(BUILTIN_LIB_OBJS)\n GIT_OBJS += $(BUILTIN_OBJS)\n GIT_OBJS += common-main.o\n GIT_OBJS += git.o\n@@ -2809,6 +2813,9 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)\n $(LIB_FILE): $(LIB_OBJS)\n \t$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^\n \n+$(BUILTIN_LIB_FILE): $(BUILTIN_LIB_OBJS)\n+\t$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^\n+\n $(XDIFF_LIB): $(XDIFF_OBJS)\n \t$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^\n \n@@ -3651,7 +3658,7 @@ clean: profile-clean coverage-clean cocciclean\n \t$(RM) po/git.pot po/git-core.pot\n \t$(RM) git.res\n \t$(RM) $(OBJECTS)\n-\t$(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)\n+\t$(RM) $(LIB_FILE) $(BUILTIN_LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)\n \t$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS)\n \t$(RM) $(TEST_PROGRAMS)\n \t$(RM) $(FUZZ_PROGRAMS)\n-- \n2.40.0+fc1\n\n"}]}