Git Mailing List Archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib: add new libgit-builtin
@ 2023-05-12 22:52 Felipe Contreras
  0 siblings, 0 replies; only message in thread
From: Felipe Contreras @ 2023-05-12 22:52 UTC (permalink / raw)
  To: git; +Cc: Felipe Contreras, Emily Shaffer

Since its creation in 0a02ce72d9 (Clean up the Makefile a bit.,
2005-04-18), libgit.a has been used as dumping ground for everything all
git commands use.

When the code was split between `*.c` and `builtin/*.c` it was never
clarified what belongs in what category.

The code in `*.c` can be shared by all builtins, but so can the code in
`builtin/*.c`.

There's no practical difference.

In order to attempt to start decoupling libgit.a from the `git` binary,
let's create a new libgit-builtin.a library meant only for the code in
`builtin/*.c`.

Ideally eventually libgit.a would not contain code that is specific to
`git`, only code that is generic and could be used by projects outside
git.git.

This is an essential step that has to be done if there's any hope of
ever having a public libgit.so library.

The choice of notes-utils.c is mostly arbitrary, but its functions had
been discussed before as a roadblock for a proper libgit. In particular
something like `init_copy_notes_for_rewrite("am")` does not seem like
something anyone outside `git` would want to call.

Cc: Emily Shaffer <nasamuffin@google.com>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---

After re-reading a previous thread about the lbification of git [1], I
realized `init_copy_notes_for_rewrite()` and others which now belong in
notes-utils.c are good candidates to start splitting away from what
eventually should be a public libgit.so library.

[1] https://lore.kernel.org/git/1370712574-27688-1-git-send-email-felipe.contreras@gmail.com/

 Makefile | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index e440728c24..84cbb35828 100644
--- a/Makefile
+++ b/Makefile
@@ -668,6 +668,7 @@ FUZZ_OBJS =
 FUZZ_PROGRAMS =
 GIT_OBJS =
 LIB_OBJS =
+BUILTIN_LIB_OBJS =
 SCALAR_OBJS =
 OBJECTS =
 OTHER_PROGRAMS =
@@ -916,6 +917,7 @@ export PYTHON_PATH
 TEST_SHELL_PATH = $(SHELL_PATH)
 
 LIB_FILE = libgit.a
+BUILTIN_LIB_FILE = libgit-builtin.a
 XDIFF_LIB = xdiff/lib.a
 REFTABLE_LIB = reftable/libreftable.a
 REFTABLE_TEST_LIB = reftable/libreftable_test.a
@@ -1071,7 +1073,6 @@ LIB_OBJS += negotiator/noop.o
 LIB_OBJS += negotiator/skipping.o
 LIB_OBJS += notes-cache.o
 LIB_OBJS += notes-merge.o
-LIB_OBJS += notes-utils.o
 LIB_OBJS += notes.o
 LIB_OBJS += object-file.o
 LIB_OBJS += object-name.o
@@ -1194,6 +1195,8 @@ LIB_OBJS += ws.o
 LIB_OBJS += wt-status.o
 LIB_OBJS += xdiff-interface.o
 
+BUILTIN_LIB_OBJS += notes-utils.o
+
 BUILTIN_OBJS += builtin/add.o
 BUILTIN_OBJS += builtin/am.o
 BUILTIN_OBJS += builtin/annotate.o
@@ -1332,7 +1335,7 @@ THIRD_PARTY_SOURCES += sha1collisiondetection/%
 THIRD_PARTY_SOURCES += sha1dc/%
 
 # xdiff and reftable libs may in turn depend on what is in libgit.a
-GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)
+GITLIBS = common-main.o $(LIB_FILE) $(BUILTIN_LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)
 EXTLIBS =
 
 GIT_USER_AGENT = git/$(GIT_VERSION)
@@ -2655,6 +2658,7 @@ TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST
 test-objs: $(TEST_OBJS)
 
 GIT_OBJS += $(LIB_OBJS)
+GIT_OBJS += $(BUILTIN_LIB_OBJS)
 GIT_OBJS += $(BUILTIN_OBJS)
 GIT_OBJS += common-main.o
 GIT_OBJS += git.o
@@ -2809,6 +2813,9 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
 $(LIB_FILE): $(LIB_OBJS)
 	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
 
+$(BUILTIN_LIB_FILE): $(BUILTIN_LIB_OBJS)
+	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
+
 $(XDIFF_LIB): $(XDIFF_OBJS)
 	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
 
@@ -3651,7 +3658,7 @@ clean: profile-clean coverage-clean cocciclean
 	$(RM) po/git.pot po/git-core.pot
 	$(RM) git.res
 	$(RM) $(OBJECTS)
-	$(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)
+	$(RM) $(LIB_FILE) $(BUILTIN_LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)
 	$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS)
 	$(RM) $(TEST_PROGRAMS)
 	$(RM) $(FUZZ_PROGRAMS)
-- 
2.40.0+fc1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-12 22:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-12 22:52 [PATCH] lib: add new libgit-builtin Felipe Contreras

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).