[PATCH] Mark blobs as parsed when they're actually parsed
authorDaniel Barkalow <barkalow@iabervon.org>
Thu, 28 Apr 2005 14:46:33 +0000 (07:46 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Thu, 28 Apr 2005 14:46:33 +0000 (07:46 -0700)
This eliminates the special case for blobs versus other types of
objects. Now the scheme is entirely regular and I won't introduce stupid
bugs. (And fsck-cache doesn't have to do the do-nothing parse)

Signed-Off-By: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
blob.c
blob.h

diff --git a/blob.c b/blob.c
index 3d99b93f020d84c5410c2b1056f2d7446b647d1e..d4af4a309433744d2fe819886d66741ab016f62b 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -14,10 +14,28 @@ struct blob *lookup_blob(unsigned char *sha1)
                ret->object.type = blob_type;
                return ret;
        }
-       if (obj->parsed && obj->type != blob_type) {
+       if (obj->type != blob_type) {
                error("Object %s is a %s, not a blob", 
                      sha1_to_hex(sha1), obj->type);
                return NULL;
        }
        return (struct blob *) obj;
 }
+
+int parse_blob(struct blob *item)
+{
+        char type[20];
+        void *buffer;
+        unsigned long size;
+        if (item->object.parsed)
+                return 0;
+        item->object.parsed = 1;
+        buffer = read_sha1_file(item->object.sha1, type, &size);
+        if (!buffer)
+                return error("Could not read %s",
+                             sha1_to_hex(item->object.sha1));
+        if (strcmp(type, blob_type))
+                return error("Object %s not a blob",
+                             sha1_to_hex(item->object.sha1));
+       return 0;
+}
diff --git a/blob.h b/blob.h
index 5cbf6d65ee88e1e0c0f1153af4aa7f80c3c48c16..4afad0f067e1979d7ccc4778e254cce6962ad136 100644 (file)
--- a/blob.h
+++ b/blob.h
@@ -11,4 +11,6 @@ struct blob {
 
 struct blob *lookup_blob(unsigned char *sha1);
 
+int parse_blob(struct blob *item);
+
 #endif /* BLOB_H */