summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-12-03 16:13:06 -0800
committerJunio C Hamano <gitster@pobox.com>2010-12-03 16:13:06 -0800
commit39f04dbaacbb21864547c8cf087697469666d21e (patch)
tree260c02b84f44d35e91284e4771ff238c26805830 /sha1_file.c
parent9bec60d3a52fa10b276214f8d255d6ff05a04b77 (diff)
parente0500293852910c2f44fce61e7eb856adbc20d8a (diff)
downloadgit-39f04dbaacbb21864547c8cf087697469666d21e.tar.gz
Merge branch 'jn/thinner-wrapper'
* jn/thinner-wrapper: Remove pack file handling dependency from wrapper.o pack-objects: mark file-local variable static wrapper: give zlib wrappers their own translation unit strbuf: move strbuf_branchname to sha1_name.c path helpers: move git_mkstemp* to wrapper.c wrapper: move odb_* to environment.c wrapper: move xmmap() to sha1_file.c
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c
index c5023703c9..1cafdfa617 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -578,6 +578,21 @@ void release_pack_memory(size_t need, int fd)
; /* nothing */
}
+void *xmmap(void *start, size_t length,
+ int prot, int flags, int fd, off_t offset)
+{
+ void *ret = mmap(start, length, prot, flags, fd, offset);
+ if (ret == MAP_FAILED) {
+ if (!length)
+ return NULL;
+ release_pack_memory(length, fd);
+ ret = mmap(start, length, prot, flags, fd, offset);
+ if (ret == MAP_FAILED)
+ die_errno("Out of memory? mmap failed");
+ }
+ return ret;
+}
+
void close_pack_windows(struct packed_git *p)
{
while (p->windows) {
@@ -803,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.