summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2012-03-07 10:54:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-03-07 17:07:38 (GMT)
commit090ea12671b2971b1c613f0a3d2657e8cdd35134 (patch)
treef5a3fdf42e7baf22513bf7700de6693a4b4fe651 /object.c
parent00c8fd493afbd1620febf2b895fb2365f76d5875 (diff)
downloadgit-090ea12671b2971b1c613f0a3d2657e8cdd35134.zip
git-090ea12671b2971b1c613f0a3d2657e8cdd35134.tar.gz
git-090ea12671b2971b1c613f0a3d2657e8cdd35134.tar.bz2
parse_object: avoid putting whole blob in core
Traditionally, all the callers of check_sha1_signature() first called read_sha1_file() to prepare the whole object data in core, and called this function. The function is used to revalidate what we read from the object database actually matches the object name we used to ask for the data from the object database. Update the API to allow callers to pass NULL as the object data, and have the function read and hash the object data using streaming API to recompute the object name, without having to hold everything in core at the same time. This is most useful in parse_object() that parses a blob object, because this caller does not have to keep the actual blob data around in memory after a "struct blob" is returned. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object.c')
-rw-r--r--object.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/object.c b/object.c
index 6b06297..0498b18 100644
--- a/object.c
+++ b/object.c
@@ -198,6 +198,17 @@ struct object *parse_object(const unsigned char *sha1)
if (obj && obj->parsed)
return obj;
+ if ((obj && obj->type == OBJ_BLOB) ||
+ (!obj && has_sha1_file(sha1) &&
+ sha1_object_info(sha1, NULL) == OBJ_BLOB)) {
+ if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
+ error("sha1 mismatch %s\n", sha1_to_hex(repl));
+ return NULL;
+ }
+ parse_blob_buffer(lookup_blob(sha1), NULL, 0);
+ return lookup_object(sha1);
+ }
+
buffer = read_sha1_file(sha1, &type, &size);
if (buffer) {
if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) {