blob.con commit [PATCH] diff-tree-helper: do not report unmerged path outside specification. (91a6eaa)
   1#include "blob.h"
   2#include "cache.h"
   3#include <stdlib.h>
   4
   5const char *blob_type = "blob";
   6
   7struct blob *lookup_blob(unsigned char *sha1)
   8{
   9        struct object *obj = lookup_object(sha1);
  10        if (!obj) {
  11                struct blob *ret = xmalloc(sizeof(struct blob));
  12                memset(ret, 0, sizeof(struct blob));
  13                created_object(sha1, &ret->object);
  14                ret->object.type = blob_type;
  15                return ret;
  16        }
  17        if (obj->type != blob_type) {
  18                error("Object %s is a %s, not a blob", 
  19                      sha1_to_hex(sha1), obj->type);
  20                return NULL;
  21        }
  22        return (struct blob *) obj;
  23}
  24
  25int parse_blob(struct blob *item)
  26{
  27        char type[20];
  28        void *buffer;
  29        unsigned long size;
  30        if (item->object.parsed)
  31                return 0;
  32        item->object.parsed = 1;
  33        buffer = read_sha1_file(item->object.sha1, type, &size);
  34        if (!buffer)
  35                return error("Could not read %s",
  36                             sha1_to_hex(item->object.sha1));
  37        if (strcmp(type, blob_type))
  38                return error("Object %s not a blob",
  39                             sha1_to_hex(item->object.sha1));
  40        return 0;
  41}