[PATCH/RFC 0/8] Remove various dependencies from wrapper.o
From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:49:59
Hi,
Ram noticed that using any function from strbuf.c results in a larger
binary that requires -lz to link, which is pretty far from ideal.
This patch series moves code around to make that no longer the case.
Vaguely inspired by [1].
After applying these patches, you can write:
#define SHA1_HEADER "block-sha1/sha1.h"
#include "cache.h"
int main(void)
{
volatile char *p = xmalloc(5);
return 0;
}
and build it with
cc -Wall -W test.c wrapper.o usage.o
-- no libz needed, no sha1 library, no environment.c, small binary.
Of course, making the linker happy tends to make the code clearer,
too.
Patch 1 moves xmmap to sha1_file.c, where release_pack_memory()
is defined. If xmmap were used by tiny programs, maybe it would
make sense to replace release_pack_memory() with a callback,
but this is simpler.
Patch 2 moves odb_mkstemp and odb_pack_keep to environment.c,
were they have access to the cached value of $GIT_OBJECT_DIRECTORY.
Patch 3 moves git_mkstemps_mode et al from path.c to wrapper.c,
so xmkstemp_mode does not have to depend on path.c.
Patch 4 moves some refname-related functions from strbuf.c to
sha1_name.c.
Patch 5 moves git_inflate et al to a new zlib.c, so wrapper.o does
not have to depend directly on libz.
Patch 6 is a missing "static" keyword. It probably doesn't belong
in this series, but it fits okay.
Patch 7 moves try_to_free_builtin to sha1_file.c and adds a
declaration for it to git-compat-util.h.
Patch 8 stops referring to try_to_free_builtin from wrapper.c,
completing the project.
Thoughts? Improvements? Benchmarks?
[1] http://thread.gmane.org/gmane.comp.version-control.git/137686/focus=137737
Jonathan Nieder (8):
wrapper: move xmmap() to sha1_file.c
wrapper: move odb_* to environment.c
path helpers: move git_mkstemp* to wrapper.c
strbuf: move strbuf_branchname to sha1_name.c
wrapper: give zlib wrappers their own translation unit
pack-objects: mark file-local variable static
wrapper: expose try_to_free_pack_memory()
Remove pack file handling dependency from wrapper.o
Makefile | 1 +
builtin/pack-objects.c | 2 +-
check-racy.c | 1 +
contrib/convert-objects/convert-objects.c | 1 +
daemon.c | 1 +
environment.c | 37 ++++++
fast-import.c | 1 +
git-compat-util.h | 2 +
git.c | 2 +
http-backend.c | 1 +
http-fetch.c | 1 +
http-push.c | 1 +
imap-send.c | 1 +
path.c | 113 ----------------
remote-curl.c | 1 +
sha1_file.c | 20 +++
sha1_name.c | 16 +++
strbuf.c | 16 ---
test-dump-cache-tree.c | 4 +-
test-match-trees.c | 1 +
upload-pack.c | 1 +
wrapper.c | 198 ++++++++++++++--------------
zlib.c | 61 +++++++++
23 files changed, 253 insertions(+), 230 deletions(-)
create mode 100644 zlib.c
--
1.7.2.3.557.gab647.dirty