git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
Cc: git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>,
	David Barr <david.barr@cordelta.com>
Subject: Re: [PATCH 8/8] Remove pack file handling dependency from wrapper.o
Date: Sat, 6 Nov 2010 14:00:38 -0500	[thread overview]
Message-ID: <20101106190038.GB14288@burratino> (raw)
In-Reply-To: <4CD5996F.6010809@lsrfire.ath.cx>

René Scharfe wrote:

> Can it be set automatically once the first pack is loaded?  A quick look
> suggests that use_pack() would be the right place to do it.

How about this?  Replaces patches 7 and 8.

--8 <--
Subject: 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>
---
 sha1_file.c |   11 +++++++++++
 wrapper.c   |    5 ++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 8e299ae..e0d2496 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -818,11 +818,22 @@ static struct packed_git *alloc_packed_git(int extra)
 	return p;
 }
 
+static void try_to_free_pack_memory(size_t size)
+{
+	release_pack_memory(size, -1);
+}
+
 struct packed_git *add_packed_git(const char *path, int path_len, int local)
 {
+	static int have_set_try_to_free_routine;
 	struct stat st;
 	struct packed_git *p = alloc_packed_git(path_len + 2);
 
+	if (!have_set_try_to_free_routine) {
+		have_set_try_to_free_routine = 1;
+		set_try_to_free_routine(try_to_free_pack_memory);
+	}
+
 	/*
 	 * Make sure a corresponding .pack file exists and that
 	 * the index looks sane.
diff --git a/wrapper.c b/wrapper.c
index 185dfbc..4c1639f 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -3,12 +3,11 @@
  */
 #include "cache.h"
 
-static void try_to_free_builtin(size_t size)
+static void do_nothing(size_t size)
 {
-	release_pack_memory(size, -1);
 }
 
-static void (*try_to_free_routine)(size_t size) = try_to_free_builtin;
+static void (*try_to_free_routine)(size_t size) = do_nothing;
 
 try_to_free_t set_try_to_free_routine(try_to_free_t routine)
 {
-- 
1.7.2.3.557.gab647.dirty

      parent reply	other threads:[~2010-11-06 19:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-06 11:39 [PATCH/RFC 0/8] Remove various dependencies from wrapper.o Jonathan Nieder
2010-11-06 11:44 ` [PATCH 1/8] wrapper: move xmmap() to sha1_file.c Jonathan Nieder
2010-11-06 11:45 ` [PATCH 2/8] wrapper: move odb_* to environment.c Jonathan Nieder
2010-11-06 11:46 ` [PATCH 3/8] path helpers: move git_mkstemp* to wrapper.c Jonathan Nieder
2010-11-06 11:46 ` [PATCH 4/8] strbuf: move strbuf_branchname to sha1_name.c Jonathan Nieder
2010-11-06 11:47 ` [PATCH 5/8] wrapper: give zlib wrappers their own translation unit Jonathan Nieder
2010-11-06 11:47 ` [PATCH 6/8] pack-objects: mark file-local variable static Jonathan Nieder
2010-11-06 11:48 ` [PATCH 7/8] wrapper: expose try_to_free_pack_memory() Jonathan Nieder
2010-11-06 11:52 ` [PATCH 8/8] Remove pack file handling dependency from wrapper.o Jonathan Nieder
2010-11-06 18:07   ` René Scharfe
2010-11-06 18:42     ` Jonathan Nieder
2010-11-07 16:10       ` René Scharfe
2010-11-07 18:23         ` Jonathan Nieder
2010-11-06 19:00     ` Jonathan Nieder [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101106190038.GB14288@burratino \
    --to=jrnieder@gmail.com \
    --cc=artagnon@gmail.com \
    --cc=david.barr@cordelta.com \
    --cc=git@vger.kernel.org \
    --cc=rene.scharfe@lsrfire.ath.cx \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).