@matheusbsbs / matheus-bagliano / commits / e050029385
Fork 0

Remove pack file handling dependency from wrapper.o

As v1.7.0-rc0~43 (slim down "git show-index", 2010-01-21) explains, use of xmalloc() brings in a dependency on zlib, the sha1 lib, and the rest of git's object file access machinery via try_to_free_pack_memory. That is overkill when xmalloc is just being used as a convenience wrapper to exit when no memory is available. So defer setting try_to_free_pack_memory as try_to_free_routine until the first packfile is opened in add_packed_git(). After this change, a simple program using xmalloc() and no other functions will not pull in any code from libgit.a aside from wrapper.o and usage.o. Improved-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Nov 6, 2010 at 14:00 UTC e0500293852910c2f44fce61e7eb856adbc20d8a
2 files changed +13 -3
sha1_file.c
+11
@@ -818,11 +818,22 @@ static struct packed_git *alloc_packed_git(int extra)
818 return p;
819 }
820
821 +static void try_to_free_pack_memory(size_t size)
822 +{
823 + release_pack_memory(size, -1);
824 +}
825 +
826 struct packed_git *add_packed_git(const char *path, int path_len, int local)
827 {
828 + static int have_set_try_to_free_routine;
829 struct stat st;
830 struct packed_git *p = alloc_packed_git(path_len + 2);
831
832 + if (!have_set_try_to_free_routine) {
833 + have_set_try_to_free_routine = 1;
834 + set_try_to_free_routine(try_to_free_pack_memory);
835 + }
836 +
837 /*
838 * Make sure a corresponding .pack file exists and that
839 * the index looks sane.
wrapper.c
+2 -3
@@ -3,12 +3,11 @@
3 */
4 #include "cache.h"
5
6 -static void try_to_free_builtin(size_t size)
6 +static void do_nothing(size_t size)
7 {
8 - release_pack_memory(size, -1);
8 }
9
11 -static void (*try_to_free_routine)(size_t size) = try_to_free_builtin;
10 +static void (*try_to_free_routine)(size_t size) = do_nothing;
11
12 try_to_free_t set_try_to_free_routine(try_to_free_t routine)
13 {