X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=sha1_file.c;h=b2074e7a8ee6d55fdb1094b93a2954bd164d5445;hb=7f3ed824a4ec15fc9725a4992b399ea4364c5adb;hp=28c056e074d1a89e4a3d266eff49c899bfd35e59;hpb=f78eeeaf55a4f60a05d3e6452f29a2214c29b6fd;p=git.git diff --git a/sha1_file.c b/sha1_file.c index 28c056e07..b2074e7a8 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2448,6 +2448,8 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, else ret = -1; strbuf_release(&sbuf); + } else if (!size) { + ret = index_mem(sha1, NULL, size, write_object, type, path); } else if (size <= SMALL_FILE_SIZE) { char *buf = xmalloc(size); if (size == read_in_full(fd, buf, size)) @@ -2456,12 +2458,11 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, else ret = error("short read %s", strerror(errno)); free(buf); - } else if (size) { + } else { void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); ret = index_mem(sha1, buf, size, write_object, type, path); munmap(buf, size); - } else - ret = index_mem(sha1, NULL, size, write_object, type, path); + } close(fd); return ret; }