X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=tree.c;h=96f78f6a3407ee86ab73de736e0485614017cb92;hb=eb019375abf545ec644e043f830ab573c2a4cd74;hp=d9777bf810af18be5e54b730bc057d6b3a554470;hpb=bd2c39f58f915af532b488c5bda753314f0db603;p=git.git diff --git a/tree.c b/tree.c index d9777bf8..96f78f6a 100644 --- a/tree.c +++ b/tree.c @@ -18,7 +18,7 @@ static int read_one_entry(unsigned char *sha1, const char *base, int baselen, co memcpy(ce->name, base, baselen); memcpy(ce->name + baselen, pathname, len+1); memcpy(ce->sha1, sha1, 20); - return add_cache_entry(ce, 1); + return add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); } static int read_tree_recursive(void *buffer, unsigned long size, @@ -39,14 +39,17 @@ static int read_tree_recursive(void *buffer, unsigned long size, if (S_ISDIR(mode)) { int retval; int pathlen = strlen(path); - char *newbase = xmalloc(baselen + 1 + pathlen); + char *newbase; void *eltbuf; char elttype[20]; unsigned long eltsize; eltbuf = read_sha1_file(sha1, elttype, &eltsize); - if (!eltbuf || strcmp(elttype, "tree")) + if (!eltbuf || strcmp(elttype, "tree")) { + if (eltbuf) free(eltbuf); return -1; + } + newbase = xmalloc(baselen + 1 + pathlen); memcpy(newbase, base, baselen); memcpy(newbase + baselen, path, pathlen); newbase[baselen + pathlen] = '/'; @@ -70,7 +73,7 @@ int read_tree(void *buffer, unsigned long size, int stage) return read_tree_recursive(buffer, size, "", 0, stage); } -struct tree *lookup_tree(unsigned char *sha1) +struct tree *lookup_tree(const unsigned char *sha1) { struct object *obj = lookup_object(sha1); if (!obj) { @@ -80,6 +83,8 @@ struct tree *lookup_tree(unsigned char *sha1) ret->object.type = tree_type; return ret; } + if (!obj->type) + obj->type = tree_type; if (obj->type != tree_type) { error("Object %s is a %s, not a tree", sha1_to_hex(sha1), obj->type); @@ -128,7 +133,7 @@ int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size) } if (obj) add_ref(&item->object, obj); - + entry->parent = NULL; /* needs to be filled by the user */ *list_p = entry; list_p = &entry->next; }