diff options
author | Bryan Larsen <bryan.larsen@gmail.com> | 2005-07-08 16:51:55 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-07-08 17:07:37 -0700 |
commit | 7672db20c2060f20b01788e4a4289ebc5f818605 (patch) | |
tree | 0b5c5ed90d81628aa03df60ee5116d707f4a0803 /sha1_file.c | |
parent | 7558ef89edce07555c6436cfcb98c31388dd99b0 (diff) | |
download | git-7672db20c2060f20b01788e4a4289ebc5f818605.tar.gz git-7672db20c2060f20b01788e4a4289ebc5f818605.tar.xz |
[PATCH] Expose object ID computation functions.
This patch makes the first half of write_sha1_file() and
index_fd() externally visible, to allow callers to compute the
object ID without actually storing it in the object database.
[JC demangled the whitespaces himself because he liked the patch
so much, and reworked the interface to index_fd() slightly,
taking suggestion from Linus and of his own.]
Signed-off-by: Bryan Larsen <bryan.larsen@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
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; |