Message ID | 20230908174443.1027716-5-calvinwan@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v3,1/6] hex-ll: split out functionality from hex | expand |
Hi Calvin On 08/09/2023 18:44, Calvin Wan wrote: > +ifndef GIT_STD_LIB > LIB_OBJS += abspath.o > LIB_OBJS += add-interactive.o > LIB_OBJS += add-patch.o > @@ -1196,6 +1198,27 @@ LIB_OBJS += write-or-die.o > LIB_OBJS += ws.o > LIB_OBJS += wt-status.o > LIB_OBJS += xdiff-interface.o > +else ifdef GIT_STD_LIB > +LIB_OBJS += abspath.o > +LIB_OBJS += ctype.o > +LIB_OBJS += date.o > +LIB_OBJS += hex-ll.o > +LIB_OBJS += parse.o > +LIB_OBJS += strbuf.o > +LIB_OBJS += usage.o > +LIB_OBJS += utf8.o > +LIB_OBJS += wrapper.o It is still not clear to me how re-using LIB_OBJS like this is compatible with building libgit.a and git-stb-lib.a in a single make process c.f. [1]. > +ifdef GIT_STD_LIB > + BASIC_CFLAGS += -DGIT_STD_LIB > + BASIC_CFLAGS += -DNO_GETTEXT As I've said before [2] I think that being able to built git-std-lib.a with gettext support is a prerequisite for using it to build git (just like trace2 support is). If we cannot build git using git-std-lib then the latter is likely to bit rot and so I don't think git-std-lib should be merged until there is a demonstration of building git using it. > +### Libified Git rules > + > +# git-std-lib > +# `make git-std-lib.a GIT_STD_LIB=YesPlease STUB_TRACE2=YesPlease STUB_PAGER=YesPlease` > +STD_LIB = git-std-lib.a > + > +$(STD_LIB): $(LIB_OBJS) $(COMPAT_OBJS) $(STUB_OBJS) > + $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^ This is much nicer that the previous version. > diff --git a/git-compat-util.h b/git-compat-util.h > index 3e7a59b5ff..14bf71c530 100644 > --- a/git-compat-util.h > +++ b/git-compat-util.h > @@ -455,8 +455,8 @@ static inline int noop_core_config(const char *var UNUSED, > #define platform_core_config noop_core_config > #endif > > +#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(GIT_STD_LIB) > int lstat_cache_aware_rmdir(const char *path); > -#if !defined(__MINGW32__) && !defined(_MSC_VER) > #define rmdir lstat_cache_aware_rmdir > #endif I thought we'd agreed that this represents a change in behavior that should be fixed c.f. [2] > @@ -1462,14 +1464,17 @@ static inline int is_missing_file_error(int errno_) > return (errno_ == ENOENT || errno_ == ENOTDIR); > } > > +#ifndef GIT_STD_LIB > int cmd_main(int, const char **); > > /* > * Intercept all calls to exit() and route them to trace2 to > * optionally emit a message before calling the real exit(). > */ > + Nit: this blank line seems unnecessary > int common_exit(const char *file, int line, int code); > #define exit(code) exit(common_exit(__FILE__, __LINE__, (code))) > +#endif > > /* > * You can mark a stack variable with UNLEAK(var) to avoid it being > diff --git a/stubs/pager.c b/stubs/pager.c > diff --git a/stubs/pager.h b/stubs/pager.h > new file mode 100644 > index 0000000000..b797910881 > --- /dev/null > +++ b/stubs/pager.h > @@ -0,0 +1,6 @@ > +#ifndef PAGER_H > +#define PAGER_H > + > +int pager_in_use(void); > + > +#endif /* PAGER_H */ Is this file actually used for anything? pager_in_use() is already declared in pager.h in the project root directory. > diff --git a/wrapper.c b/wrapper.c > index 7da15a56da..eeac3741cf 100644 > --- a/wrapper.c > +++ b/wrapper.c > @@ -5,7 +5,6 @@ > #include "abspath.h" > #include "parse.h" > #include "gettext.h" > -#include "repository.h" It is probably worth splitting this change out with a commit message explaining why the include is unneeded. This is looking good, it would be really nice to see a demonstration of building git using git-std-lib (with gettext support) in the next iteration. Best Wishes Phillip [1] https://lore.kernel.org/git/a0f04bd7-3a1e-b303-fd52-eee2af4d38b3@gmail.com/ [2] https://lore.kernel.org/git/CAFySSZBMng9nEdCkuT5+fc6rfFgaFfU2E0NP3=jUQC1yRcUE6Q@mail.gmail.com/
Calvin Wan <calvinwan@google.com> writes: > diff --git a/Makefile b/Makefile > index 9226c719a0..0a2d1ae3cc 100644 > --- a/Makefile > +++ b/Makefile > @@ -669,6 +669,7 @@ FUZZ_PROGRAMS = > GIT_OBJS = > LIB_OBJS = > SCALAR_OBJS = > +STUB_OBJS = > OBJECTS = > OTHER_PROGRAMS = > PROGRAM_OBJS = I don't think stubs should be compiled into git-std-lib.a - I would expect a consumer of this library to be able to specify their own implementations if needed (e.g. their own trace2). > @@ -956,6 +957,7 @@ COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES)) > > LIB_H = $(FOUND_H_SOURCES) > > +ifndef GIT_STD_LIB > LIB_OBJS += abspath.o > LIB_OBJS += add-interactive.o > LIB_OBJS += add-patch.o > @@ -1196,6 +1198,27 @@ LIB_OBJS += write-or-die.o > LIB_OBJS += ws.o > LIB_OBJS += wt-status.o > LIB_OBJS += xdiff-interface.o > +else ifdef GIT_STD_LIB > +LIB_OBJS += abspath.o > +LIB_OBJS += ctype.o > +LIB_OBJS += date.o > +LIB_OBJS += hex-ll.o > +LIB_OBJS += parse.o > +LIB_OBJS += strbuf.o > +LIB_OBJS += usage.o > +LIB_OBJS += utf8.o > +LIB_OBJS += wrapper.o This means that LIB_OBJS (in this patch, used both by git-std-lib and as part of compiling the regular Git binary) can differ based on the GIT_STD_LIB variable. It does seem that we cannot avoid GIT_STD_LIB for now, because the git-std-lib can only be compiled without GETTEXT (so we need a variable to make sure that none of these .o files are compiled with GETTEXT), but we should still minimize the changes between compiling with GIT_STD_LIB and without it, at least to minimize future work. Could we have two separate lists? So, leave LIB_OBJS alone and make a new STD_LIB_OBJS. > diff --git a/git-compat-util.h b/git-compat-util.h > index 3e7a59b5ff..14bf71c530 100644 > --- a/git-compat-util.h > +++ b/git-compat-util.h > @@ -455,8 +455,8 @@ static inline int noop_core_config(const char *var UNUSED, > #define platform_core_config noop_core_config > #endif > > +#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(GIT_STD_LIB) > int lstat_cache_aware_rmdir(const char *path); > -#if !defined(__MINGW32__) && !defined(_MSC_VER) > #define rmdir lstat_cache_aware_rmdir > #endif I think we still want to keep the idea of "the code should still be good even if we have no use for git-std-lib" as much as possible, so could we stub lstat_cache_aware_rmdir() instead? We could have a new git-compat- util-stub.c (or whatever we want to call it). > @@ -966,9 +966,11 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size); > #endif > > #ifdef NO_PTHREADS > +#ifdef GIT_STD_LIB > #define atexit git_atexit > int git_atexit(void (*handler)(void)); > #endif > +#endif > > static inline size_t st_add(size_t a, size_t b) > { Same for git_atexit(). > @@ -1462,14 +1464,17 @@ static inline int is_missing_file_error(int errno_) > return (errno_ == ENOENT || errno_ == ENOTDIR); > } > > +#ifndef GIT_STD_LIB > int cmd_main(int, const char **); > > /* > * Intercept all calls to exit() and route them to trace2 to > * optionally emit a message before calling the real exit(). > */ > + > int common_exit(const char *file, int line, int code); > #define exit(code) exit(common_exit(__FILE__, __LINE__, (code))) > +#endif > > /* > * You can mark a stack variable with UNLEAK(var) to avoid it being And for common_exit(). As for cmd_main(), that seems to be a convenience so that we can link common_main.o with various other files (e.g. http-backend.c). I think the right thing to do is to define a new cmd-main.h that declares only cmd_main(), and then have only the files that need it (common_main.c and all the files that define cmd_main()) include it. This cleanup patch can be done before this patch. I think this is a good change that we would want even without libification.
Hi Calvin On 08/09/2023 18:44, Calvin Wan wrote: > The Git Standard Library intends to serve as the foundational library > and root dependency that other libraries in Git will be built off of. > That is to say, suppose we have libraries X and Y; a user that wants to > use X and Y would need to include X, Y, and this Git Standard Library. > > Add Documentation/technical/git-std-lib.txt to further explain the > design and rationale. > > Signed-off-by: Calvin Wan <calvinwan@google.com> > Helped-by: Phillip Wood <phillip.wood123@gmail.com> > --- > Documentation/technical/git-std-lib.txt | 191 ++++++++++++++++++++++++ I need the following diff to build the html documentation. Best Wishes Phillip diff --git a/Documentation/Makefile b/Documentation/Makefile index 3f2383a12c..f1dc673838 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -110,6 +110,7 @@ TECH_DOCS += SubmittingPatches TECH_DOCS += ToolsForGit TECH_DOCS += technical/bitmap-format TECH_DOCS += technical/bundle-uri +TECH_DOCS += technical/git-std-lib TECH_DOCS += technical/hash-function-transition TECH_DOCS += technical/long-running-process-protocol TECH_DOCS += technical/multi-pack-index diff --git a/Documentation/technical/git-std-lib.txt b/Documentation/technical/git-std-lib.txt index d03b8565b4..28e6cdac2a 100644 --- a/Documentation/technical/git-std-lib.txt +++ b/Documentation/technical/git-std-lib.txt @@ -1,5 +1,4 @@ -Git Standard Library -================ += Git Standard Library The Git Standard Library intends to serve as the foundational library and root dependency that other libraries in Git will be built off of. @@ -9,8 +8,7 @@ This does not mean that the Git Standard Library will be the only possible root dependency in the future, but rather the most significant and widely used one. -Dependency graph in libified Git -================ +== Dependency graph in libified Git If you look in the Git Makefile, all of the objects defined in the Git library are compiled and archived into a singular file, libgit.a, which @@ -57,8 +55,7 @@ if someone wanted their own custom build of Git with their own custom implementation of the object store, they would only have to swap out object-store.a rather than do a hard fork of Git. -Rationale behind Git Standard Library -================ +== Rationale behind Git Standard Library The rationale behind what's in and what's not in the Git Standard Library essentially is the result of two observations within the Git @@ -67,8 +64,7 @@ in a couple of different files, and wrapper.c + usage.c have difficult-to-separate circular dependencies with each other and other files. -Ubiquity of git-compat-util.h and circular dependencies -======== +=== Ubiquity of git-compat-util.h and circular dependencies Every file in the Git codebase includes git-compat-util.h. It serves as "a compatibility aid that isolates the knowledge of platform specific @@ -79,10 +75,9 @@ for wrapper.c and usage.c to be a part of the root library. They have difficult to separate circular dependencies with each other so they can't be independent libraries. Wrapper.c has dependencies on parse.c, abspath.c, strbuf.c, which in turn also have dependencies on usage.c and -wrapper.c -- more circular dependencies. +wrapper.c - more circular dependencies. -Tradeoff between swappability and refactoring -======== +=== Tradeoff between swappability and refactoring From the above dependency graph, we can see that git-std-lib.a could be many smaller libraries rather than a singular library. So why choose a @@ -99,8 +94,7 @@ and change the API for the library if there becomes enough of a reason to do so (remember we are avoiding promising stability of the interfaces of those libraries). -Reuse of compatibility functions in git-compat-util.h -======== +=== Reuse of compatibility functions in git-compat-util.h Most functions defined in git-compat-util.h are implemented in compat/ and have dependencies limited to strbuf.h and wrapper.h so they can be @@ -110,8 +104,7 @@ compat/. The rest of the functions defined in git-compat-util.h are implemented in top level files and are hidden behind an #ifdef if their implementation is not in git-std-lib.a. -Rationale summary -======== +=== Rationale summary The Git Standard Library allows us to get the libification ball rolling with other libraries in Git. By not spending many @@ -123,8 +116,7 @@ the code cleanups that have happened so far have been minor and beneficial for the codebase. It is probable that making large movements would negatively affect code clarity. -Git Standard Library boundary -================ +== Git Standard Library boundary While I have described above some useful heuristics for identifying potential candidates for git-std-lib.a, a standard library should not @@ -150,8 +142,7 @@ to be able to trace functions in those files and other files in git-std-lib.a. In order for git-std-lib.a to compile with those dependencies, stubbed out versions of those files are implemented and swapped in during compilation time. -Files inside of Git Standard Library -================ +== Files inside of Git Standard Library The initial set of files in git-std-lib.a are: abspath.c @@ -171,21 +162,19 @@ complete library: stubs/pager.c stubs/trace2.c -Pitfalls -================ +== Pitfalls There are a small amount of files under compat/* that have dependencies not inside of git-std-lib.a. While those functions are not called on Linux, other OSes might call those problematic functions. I don't see this as a major problem, just moreso an observation that libification in general may also require some minor compatibility work in the future. -Testing -================ +== Testing Unit tests should catch any breakages caused by changes to files in git-std-lib.a (i.e. introduction of a out of scope dependency) and new functions introduced to git-std-lib.a will require unit tests written for them. -[1] https://lore.kernel.org/git/xmqqwn17sydw.fsf@gitster.g/ \ No newline at end of file +[1] https://lore.kernel.org/git/xmqqwn17sydw.fsf@gitster.g/
Hi Calvin On 11/09/2023 14:22, Phillip Wood wrote: > This is looking good, it would be really nice to see a demonstration of > building git using git-std-lib (with gettext support) in the next > iteration. I've just pushed a couple of patches on top of this series to https://github.com/phillipwood/git/tree/cw/git-std-lib/v3 that show a possible way to do that. Rather than re-using LIB_OBJS when building git-std-lib.a it uses a separate variable to hold the list of sources. git is linked against git-std-lib.a so we don't have to worry about having the same source file in two different libraries. The stub objects are moved into their own library. This enables git to be built using git-std-lib.a with make git which will link git against git-std-lib.a built with gettext and tracing support. To use git-std-lib.a in other programs compile it and git-stub-lib.a with make NO_GETTEXT=YesPlease git-std-lib.a git-stub-lib.a and link your program against both libraries. The GIT_STD_LIB define is also removed in favor of more stubbing to avoid the complications of conditional compilation. Best Wishes Phillip
diff --git a/Documentation/technical/git-std-lib.txt b/Documentation/technical/git-std-lib.txt new file mode 100644 index 0000000000..397c1da8c8 --- /dev/null +++ b/Documentation/technical/git-std-lib.txt @@ -0,0 +1,191 @@ +Git Standard Library +================ + +The Git Standard Library intends to serve as the foundational library +and root dependency that other libraries in Git will be built off of. +That is to say, suppose we have libraries X and Y; a user that wants to +use X and Y would need to include X, Y, and this Git Standard Library. +This does not mean that the Git Standard Library will be the only +possible root dependency in the future, but rather the most significant +and widely used one. + +Dependency graph in libified Git +================ + +If you look in the Git Makefile, all of the objects defined in the Git +library are compiled and archived into a singular file, libgit.a, which +is linked against by common-main.o with other external dependencies and +turned into the Git executable. In other words, the Git executable has +dependencies on libgit.a and a couple of external libraries. The +libfication of Git will not affect this current build flow, but instead +will provide an alternate method for building Git. + +With our current method of building Git, we can imagine the dependency +graph as such: + + Git + /\ + / \ + / \ + libgit.a ext deps + +In libifying parts of Git, we want to shrink the dependency graph to +only the minimal set of dependencies, so libraries should not use +libgit.a. Instead, it would look like: + + Git + /\ + / \ + / \ + libgit.a ext deps + /\ + / \ + / \ +object-store.a (other lib) + | / + | / + | / + config.a / + | / + | / + | / +git-std-lib.a + +Instead of containing all of the objects in Git, libgit.a would contain +objects that are not built by libraries it links against. Consequently, +if someone wanted their own custom build of Git with their own custom +implementation of the object store, they would only have to swap out +object-store.a rather than do a hard fork of Git. + +Rationale behind Git Standard Library +================ + +The rationale behind what's in and what's not in the Git Standard +Library essentially is the result of two observations within the Git +codebase: every file includes git-compat-util.h which defines functions +in a couple of different files, and wrapper.c + usage.c have +difficult-to-separate circular dependencies with each other and other +files. + +Ubiquity of git-compat-util.h and circular dependencies +======== + +Every file in the Git codebase includes git-compat-util.h. It serves as +"a compatibility aid that isolates the knowledge of platform specific +inclusion order and what feature macros to define before including which +system header" (Junio[1]). Since every file includes git-compat-util.h, and +git-compat-util.h includes wrapper.h and usage.h, it would make sense +for wrapper.c and usage.c to be a part of the root library. They have +difficult to separate circular dependencies with each other so they +can't be independent libraries. Wrapper.c has dependencies on parse.c, +abspath.c, strbuf.c, which in turn also have dependencies on usage.c and +wrapper.c -- more circular dependencies. + +Tradeoff between swappability and refactoring +======== + +From the above dependency graph, we can see that git-std-lib.a could be +many smaller libraries rather than a singular library. So why choose a +singular library when multiple libraries can be individually easier to +swap and are more modular? A singular library requires less work to +separate out circular dependencies within itself so it becomes a +tradeoff question between work and reward. While there may be a point in +the future where a file like usage.c would want its own library so that +someone can have custom die() or error(), the work required to refactor +out the circular dependencies in some files would be enormous due to +their ubiquity so therefore I believe it is not worth the tradeoff +currently. Additionally, we can in the future choose to do this refactor +and change the API for the library if there becomes enough of a reason +to do so (remember we are avoiding promising stability of the interfaces +of those libraries). + +Reuse of compatibility functions in git-compat-util.h +======== + +Most functions defined in git-compat-util.h are implemented in compat/ +and have dependencies limited to strbuf.h and wrapper.h so they can be +easily included in git-std-lib.a, which as a root dependency means that +higher level libraries do not have to worry about compatibility files in +compat/. The rest of the functions defined in git-compat-util.h are +implemented in top level files and are hidden behind +an #ifdef if their implementation is not in git-std-lib.a. + +Rationale summary +======== + +The Git Standard Library allows us to get the libification ball rolling +with other libraries in Git. By not spending many +more months attempting to refactor difficult circular dependencies and +instead spending that time getting to a state where we can test out +swapping a library out such as config or object store, we can prove the +viability of Git libification on a much faster time scale. Additionally +the code cleanups that have happened so far have been minor and +beneficial for the codebase. It is probable that making large movements +would negatively affect code clarity. + +Git Standard Library boundary +================ + +While I have described above some useful heuristics for identifying +potential candidates for git-std-lib.a, a standard library should not +have a shaky definition for what belongs in it. + + - Low-level files (aka operates only on other primitive types) that are + used everywhere within the codebase (wrapper.c, usage.c, strbuf.c) + - Dependencies that are low-level and widely used + (abspath.c, date.c, hex-ll.c, parse.c, utf8.c) + - low-level git/* files with functions defined in git-compat-util.h + (ctype.c) + - compat/* + - stubbed out dependencies in stubs/ (stubs/pager.c, stubs/trace2.c) + +There are other files that might fit this definition, but that does not +mean it should belong in git-std-lib.a. Those files should start as +their own separate library since any file added to git-std-lib.a loses +its flexibility of being easily swappable. + +Wrapper.c and usage.c have dependencies on pager and trace2 that are +possible to remove at the cost of sacrificing the ability for standard Git +to be able to trace functions in those files and other files in git-std-lib.a. +In order for git-std-lib.a to compile with those dependencies, stubbed out +versions of those files are implemented and swapped in during compilation time. + +Files inside of Git Standard Library +================ + +The initial set of files in git-std-lib.a are: +abspath.c +ctype.c +date.c +hex-ll.c +parse.c +strbuf.c +usage.c +utf8.c +wrapper.c +relevant compat/ files + +When these files are compiled together with the following files (or +user-provided files that provide the same functions), they form a +complete library: +stubs/pager.c +stubs/trace2.c + +Pitfalls +================ + +There are a small amount of files under compat/* that have dependencies +not inside of git-std-lib.a. While those functions are not called on +Linux, other OSes might call those problematic functions. I don't see +this as a major problem, just moreso an observation that libification in +general may also require some minor compatibility work in the future. + +Testing +================ + +Unit tests should catch any breakages caused by changes to files in +git-std-lib.a (i.e. introduction of a out of scope dependency) and new +functions introduced to git-std-lib.a will require unit tests written +for them. + +[1] https://lore.kernel.org/git/xmqqwn17sydw.fsf@gitster.g/ \ No newline at end of file diff --git a/Makefile b/Makefile index 9226c719a0..0a2d1ae3cc 100644 --- a/Makefile +++ b/Makefile @@ -669,6 +669,7 @@ FUZZ_PROGRAMS = GIT_OBJS = LIB_OBJS = SCALAR_OBJS = +STUB_OBJS = OBJECTS = OTHER_PROGRAMS = PROGRAM_OBJS = @@ -956,6 +957,7 @@ COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES)) LIB_H = $(FOUND_H_SOURCES) +ifndef GIT_STD_LIB LIB_OBJS += abspath.o LIB_OBJS += add-interactive.o LIB_OBJS += add-patch.o @@ -1196,6 +1198,27 @@ LIB_OBJS += write-or-die.o LIB_OBJS += ws.o LIB_OBJS += wt-status.o LIB_OBJS += xdiff-interface.o +else ifdef GIT_STD_LIB +LIB_OBJS += abspath.o +LIB_OBJS += ctype.o +LIB_OBJS += date.o +LIB_OBJS += hex-ll.o +LIB_OBJS += parse.o +LIB_OBJS += strbuf.o +LIB_OBJS += usage.o +LIB_OBJS += utf8.o +LIB_OBJS += wrapper.o + +ifdef STUB_TRACE2 +STUB_OBJS += stubs/trace2.o +endif + +ifdef STUB_PAGER +STUB_OBJS += stubs/pager.o +endif + +LIB_OBJS += $(STUB_OBJS) +endif BUILTIN_OBJS += builtin/add.o BUILTIN_OBJS += builtin/am.o @@ -2162,6 +2185,11 @@ ifdef FSMONITOR_OS_SETTINGS COMPAT_OBJS += compat/fsmonitor/fsm-path-utils-$(FSMONITOR_OS_SETTINGS).o endif +ifdef GIT_STD_LIB + BASIC_CFLAGS += -DGIT_STD_LIB + BASIC_CFLAGS += -DNO_GETTEXT +endif + ifeq ($(TCLTK_PATH),) NO_TCLTK = NoThanks endif @@ -3668,7 +3696,7 @@ clean: profile-clean coverage-clean cocciclean $(RM) git.res $(RM) $(OBJECTS) $(RM) headless-git.o - $(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB) + $(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB) $(STD_LIB_FILE) $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS) $(RM) $(TEST_PROGRAMS) $(RM) $(FUZZ_PROGRAMS) @@ -3849,3 +3877,12 @@ $(FUZZ_PROGRAMS): all $(XDIFF_OBJS) $(EXTLIBS) git.o $@.o $(LIB_FUZZING_ENGINE) -o $@ fuzz-all: $(FUZZ_PROGRAMS) + +### Libified Git rules + +# git-std-lib +# `make git-std-lib.a GIT_STD_LIB=YesPlease STUB_TRACE2=YesPlease STUB_PAGER=YesPlease` +STD_LIB = git-std-lib.a + +$(STD_LIB): $(LIB_OBJS) $(COMPAT_OBJS) $(STUB_OBJS) + $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^ diff --git a/git-compat-util.h b/git-compat-util.h index 3e7a59b5ff..14bf71c530 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -455,8 +455,8 @@ static inline int noop_core_config(const char *var UNUSED, #define platform_core_config noop_core_config #endif +#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(GIT_STD_LIB) int lstat_cache_aware_rmdir(const char *path); -#if !defined(__MINGW32__) && !defined(_MSC_VER) #define rmdir lstat_cache_aware_rmdir #endif @@ -966,9 +966,11 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size); #endif #ifdef NO_PTHREADS +#ifdef GIT_STD_LIB #define atexit git_atexit int git_atexit(void (*handler)(void)); #endif +#endif static inline size_t st_add(size_t a, size_t b) { @@ -1462,14 +1464,17 @@ static inline int is_missing_file_error(int errno_) return (errno_ == ENOENT || errno_ == ENOTDIR); } +#ifndef GIT_STD_LIB int cmd_main(int, const char **); /* * Intercept all calls to exit() and route them to trace2 to * optionally emit a message before calling the real exit(). */ + int common_exit(const char *file, int line, int code); #define exit(code) exit(common_exit(__FILE__, __LINE__, (code))) +#endif /* * You can mark a stack variable with UNLEAK(var) to avoid it being diff --git a/stubs/pager.c b/stubs/pager.c new file mode 100644 index 0000000000..4f575cada7 --- /dev/null +++ b/stubs/pager.c @@ -0,0 +1,6 @@ +#include "pager.h" + +int pager_in_use(void) +{ + return 0; +} diff --git a/stubs/pager.h b/stubs/pager.h new file mode 100644 index 0000000000..b797910881 --- /dev/null +++ b/stubs/pager.h @@ -0,0 +1,6 @@ +#ifndef PAGER_H +#define PAGER_H + +int pager_in_use(void); + +#endif /* PAGER_H */ diff --git a/stubs/trace2.c b/stubs/trace2.c new file mode 100644 index 0000000000..7d89482228 --- /dev/null +++ b/stubs/trace2.c @@ -0,0 +1,27 @@ +#include "git-compat-util.h" +#include "trace2.h" + +struct child_process { int stub; }; +struct repository { int stub; }; +struct json_writer { int stub; }; + +void trace2_region_enter_fl(const char *file, int line, const char *category, + const char *label, const struct repository *repo, ...) { } +void trace2_region_leave_fl(const char *file, int line, const char *category, + const char *label, const struct repository *repo, ...) { } +void trace2_data_string_fl(const char *file, int line, const char *category, + const struct repository *repo, const char *key, + const char *value) { } +void trace2_cmd_ancestry_fl(const char *file, int line, const char **parent_names) { } +void trace2_cmd_error_va_fl(const char *file, int line, const char *fmt, + va_list ap) { } +void trace2_cmd_name_fl(const char *file, int line, const char *name) { } +void trace2_thread_start_fl(const char *file, int line, + const char *thread_base_name) { } +void trace2_thread_exit_fl(const char *file, int line) { } +void trace2_data_intmax_fl(const char *file, int line, const char *category, + const struct repository *repo, const char *key, + intmax_t value) { } +int trace2_is_enabled(void) { return 0; } +void trace2_counter_add(enum trace2_counter_id cid, uint64_t value) { } +void trace2_collect_process_info(enum trace2_process_info_reason reason) { } diff --git a/symlinks.c b/symlinks.c index b29e340c2d..bced721a0c 100644 --- a/symlinks.c +++ b/symlinks.c @@ -337,6 +337,7 @@ void invalidate_lstat_cache(void) reset_lstat_cache(&default_cache); } +#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(GIT_STD_LIB) #undef rmdir int lstat_cache_aware_rmdir(const char *path) { @@ -348,3 +349,4 @@ int lstat_cache_aware_rmdir(const char *path) return ret; } +#endif diff --git a/wrapper.c b/wrapper.c index 7da15a56da..eeac3741cf 100644 --- a/wrapper.c +++ b/wrapper.c @@ -5,7 +5,6 @@ #include "abspath.h" #include "parse.h" #include "gettext.h" -#include "repository.h" #include "strbuf.h" #include "trace2.h"
The Git Standard Library intends to serve as the foundational library and root dependency that other libraries in Git will be built off of. That is to say, suppose we have libraries X and Y; a user that wants to use X and Y would need to include X, Y, and this Git Standard Library. Add Documentation/technical/git-std-lib.txt to further explain the design and rationale. Signed-off-by: Calvin Wan <calvinwan@google.com> Helped-by: Phillip Wood <phillip.wood123@gmail.com> --- Documentation/technical/git-std-lib.txt | 191 ++++++++++++++++++++++++ Makefile | 39 ++++- git-compat-util.h | 7 +- stubs/pager.c | 6 + stubs/pager.h | 6 + stubs/trace2.c | 27 ++++ symlinks.c | 2 + wrapper.c | 1 - 8 files changed, 276 insertions(+), 3 deletions(-) create mode 100644 Documentation/technical/git-std-lib.txt create mode 100644 stubs/pager.c create mode 100644 stubs/pager.h create mode 100644 stubs/trace2.c