--- linus.back/read-cache.c 2005-04-20 10:14:23.268310000 -0400 +++ linus/read-cache.c 2005-04-20 13:05:13.200083672 -0400 @@ -232,11 +232,12 @@ SHA_CTX c; struct cache_header hdr; int i; + char *buf; + int len = 0; hdr.hdr_signature = htonl(CACHE_SIGNATURE); hdr.hdr_version = htonl(1); hdr.hdr_entries = htonl(entries); - SHA1_Init(&c); SHA1_Update(&c, &hdr, offsetof(struct cache_header, sha1)); for (i = 0; i < entries; i++) { @@ -246,13 +247,31 @@ } SHA1_Final(hdr.sha1, &c); + buf = malloc(16384); + if (!buf) { + return -1; + } if (write(newfd, &hdr, sizeof(hdr)) != sizeof(hdr)) return -1; for (i = 0; i < entries; i++) { struct cache_entry *ce = cache[i]; int size = ce_size(ce); - if (write(newfd, ce, size) != size) + if (size > 16384) { + if (write(newfd, ce, size) != size) + return -1; + continue; + } + if (len + size > 16384) { + if (write(newfd, buf, len) != len) + return -1; + len = 0; + } + memcpy(buf + len, ce, size); + len += size; + } + if (len) { + if (write(newfd, buf, len) != len) return -1; } return 0;