Skip to content

Commit

Permalink
Merge branch 'dp/read-not-mmap-small-loose-object' into maint
Browse files Browse the repository at this point in the history
* dp/read-not-mmap-small-loose-object:
  hash-object: don't use mmap() for small files
  • Loading branch information
Junio C Hamano committed Mar 5, 2010
2 parents 035aa76 + ea68b0c commit 780fc9a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2439,6 +2439,8 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,
return ret;
}

#define SMALL_FILE_SIZE (32*1024)

int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
enum object_type type, const char *path)
{
Expand All @@ -2453,6 +2455,14 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
else
ret = -1;
strbuf_release(&sbuf);
} else if (size <= SMALL_FILE_SIZE) {
char *buf = xmalloc(size);
if (size == read_in_full(fd, buf, size))
ret = index_mem(sha1, buf, size, write_object, type,
path);
else
ret = error("short read %s", strerror(errno));
free(buf);
} else if (size) {
void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
ret = index_mem(sha1, buf, size, write_object, type, path);
Expand Down

0 comments on commit 780fc9a

Please sign in to comment.