summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorBryan Larsen <bryan.larsen@gmail.com>2005-07-08 23:51:55 (GMT)
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-09 00:07:37 (GMT)
commit7672db20c2060f20b01788e4a4289ebc5f818605 (patch)
tree0b5c5ed90d81628aa03df60ee5116d707f4a0803 /sha1_file.c
parent7558ef89edce07555c6436cfcb98c31388dd99b0 (diff)
downloadgit-7672db20c2060f20b01788e4a4289ebc5f818605.zip
git-7672db20c2060f20b01788e4a4289ebc5f818605.tar.gz
git-7672db20c2060f20b01788e4a4289ebc5f818605.tar.bz2
[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.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/sha1_file.c b/sha1_file.c
index fc4e6bf..b2914dd 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;