diff options
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/sha1_file.c b/sha1_file.c index fc4e6bf91..b2914dd2e 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1100,12 +1100,12 @@ void *read_object_with_reference(const unsigned char *sha1, } } -static char *write_sha1_file_prepare(void *buf, - unsigned long len, - const char *type, - unsigned char *sha1, - unsigned char *hdr, - int *hdrlen) +char *write_sha1_file_prepare(void *buf, + unsigned long len, + const char *type, + unsigned char *sha1, + unsigned char *hdr, + int *hdrlen) { SHA_CTX c; @@ -1299,11 +1299,13 @@ int has_sha1_file(const unsigned char *sha1) return find_pack_entry(sha1, &e); } -int index_fd(unsigned char *sha1, int fd, struct stat *st) +int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, const char *type) { unsigned long size = st->st_size; void *buf; int ret; + unsigned char hdr[50]; + int hdrlen; buf = ""; if (size) @@ -1312,7 +1314,14 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st) if ((int)(long)buf == -1) return -1; - ret = write_sha1_file(buf, size, "blob", sha1); + if (!type) + type = "blob"; + if (write_object) + ret = write_sha1_file(buf, size, type, sha1); + else { + write_sha1_file_prepare(buf, size, type, sha1, hdr, &hdrlen); + ret = 0; + } if (size) munmap(buf, size); return ret; |