X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=tree.c;h=aa55ddb6846bdc33abf9d41424d105e1b2331640;hb=c4483576b8d30fadcae208d8f12383febd060d0a;hp=a978c53a308fa36fd4c666c3035bc17626fdc871;hpb=192268c197c0f143989662f648b1d900014e7d89;p=git.git diff --git a/tree.c b/tree.c index a978c53a..aa55ddb6 100644 --- a/tree.c +++ b/tree.c @@ -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] = '/'; @@ -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; }