blob.con commit completion: For consistency, change "git rev-parse" to __gitdir calls (fa26a40)
   1#include "cache.h"
   2#include "blob.h"
   3
   4const char *blob_type = "blob";
   5
   6struct blob *lookup_blob(const unsigned char *sha1)
   7{
   8        struct object *obj = lookup_object(sha1);
   9        if (!obj)
  10                return create_object(sha1, OBJ_BLOB, alloc_blob_node());
  11        if (!obj->type)
  12                obj->type = OBJ_BLOB;
  13        if (obj->type != OBJ_BLOB) {
  14                error("Object %s is a %s, not a blob",
  15                      sha1_to_hex(sha1), typename(obj->type));
  16                return NULL;
  17        }
  18        return (struct blob *) obj;
  19}
  20
  21int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
  22{
  23        item->object.parsed = 1;
  24        return 0;
  25}
  26
  27int parse_blob(struct blob *item)
  28{
  29        enum object_type type;
  30        void *buffer;
  31        unsigned long size;
  32        int ret;
  33
  34        if (item->object.parsed)
  35                return 0;
  36        buffer = read_sha1_file(item->object.sha1, &type, &size);
  37        if (!buffer)
  38                return error("Could not read %s",
  39                             sha1_to_hex(item->object.sha1));
  40        if (type != OBJ_BLOB)
  41                return error("Object %s not a blob",
  42                             sha1_to_hex(item->object.sha1));
  43        ret = parse_blob_buffer(item, buffer, size);
  44        free(buffer);
  45        return ret;
  46}