diff options
author | Junio C Hamano <junkio@cox.net> | 2005-06-27 19:03:13 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-27 19:40:21 -0700 |
commit | d410c0f5a99637e1859bb276409d29e8cde10800 (patch) | |
tree | 1a89f8fd43b865c0721223bab2d033ce12b44181 | |
parent | [PATCH] replace sha1sum with sum in t/t1002 (diff) | |
download | tgif-d410c0f5a99637e1859bb276409d29e8cde10800.tar.xz |
[PATCH] Skip writing out sha1 files for objects in packed git.
Now, there's still a misfeature there, which is that when you
create a new object, it doesn't check whether that object
already exists in the pack-file, so you'll end up with a few
recent objects that you really don't need (notably tree
objects), and this patch fixes it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | sha1_file.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/sha1_file.c b/sha1_file.c index 7e4a3df3ad..698b43cfcb 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -891,31 +891,46 @@ 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) +{ + SHA_CTX c; + + /* Generate the header */ + *hdrlen = sprintf((char *)hdr, "%s %lu", type, len)+1; + + /* Sha1.. */ + SHA1_Init(&c); + SHA1_Update(&c, hdr, *hdrlen); + SHA1_Update(&c, buf, len); + SHA1_Final(sha1, &c); + + return sha1_file_name(sha1); +} + int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *returnsha1) { int size; unsigned char *compressed; z_stream stream; unsigned char sha1[20]; - SHA_CTX c; char *filename; static char tmpfile[PATH_MAX]; unsigned char hdr[50]; int fd, hdrlen, ret; - /* Generate the header */ - hdrlen = sprintf((char *)hdr, "%s %lu", type, len)+1; - - /* Sha1.. */ - SHA1_Init(&c); - SHA1_Update(&c, hdr, hdrlen); - SHA1_Update(&c, buf, len); - SHA1_Final(sha1, &c); - + /* Normally if we have it in the pack then we do not bother writing + * it out into .git/objects/??/?{38} file. + */ + filename = write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen); if (returnsha1) memcpy(returnsha1, sha1, 20); - - filename = sha1_file_name(sha1); + if (has_sha1_file(sha1)) + return 0; fd = open(filename, O_RDONLY); if (fd >= 0) { /* |