summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2010-11-06 06:44:11 -0500
committerJunio C Hamano <gitster@pobox.com>2010-11-10 11:03:13 -0800
commit58ecbd5edeb2357c313db75bc49d45981a2061b7 (patch)
tree2b1c2369102ae51b351bdbb2a0a3ad837bb4bdaf /sha1_file.c
parent6f10c4103dc7506623f89520ad03517b40788259 (diff)
downloadgit-58ecbd5edeb2357c313db75bc49d45981a2061b7.tar.gz
wrapper: move xmmap() to sha1_file.c
wrapper.o depends on sha1_file.o for a number of reasons. One is release_pack_memory(). xmmap function calls mmap, discarding unused pack windows when necessary to relieve memory pressure. Simple git programs using wrapper.o as a friendly libc do not need this functionality. So move xmmap to sha1_file.o, where release_pack_memory() is. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 0cd9435619..8e299ae85c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -576,6 +576,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) {