if (parse_tree(tree))
return -1;
- desc.buf = tree->buffer;
- desc.size = tree->size;
+ init_tree_desc(&desc, tree->buffer, tree->size);
while (tree_entry(&desc, &entry)) {
if (!match_tree_entry(base, baselen, entry.path, entry.mode, match))
if (S_ISDIR(entry.mode)) {
int retval;
char *newbase;
+ unsigned int pathlen = tree_entry_len(entry.path, entry.sha1);
- newbase = xmalloc(baselen + 1 + entry.pathlen);
+ newbase = xmalloc(baselen + 1 + pathlen);
memcpy(newbase, base, baselen);
- memcpy(newbase + baselen, entry.path, entry.pathlen);
- newbase[baselen + entry.pathlen] = '/';
+ memcpy(newbase + baselen, entry.path, pathlen);
+ newbase[baselen + pathlen] = '/';
retval = read_tree_recursive(lookup_tree(entry.sha1),
newbase,
- baselen + entry.pathlen + 1,
+ baselen + pathlen + 1,
stage, match, fn);
free(newbase);
if (retval)
struct name_entry entry;
/* Count how many entries there are.. */
- desc.buf = item->buffer;
- desc.size = item->size;
- while (desc.size) {
+ init_tree_desc(&desc, item->buffer, item->size);
+ while (tree_entry(&desc, &entry))
n_refs++;
- update_tree_entry(&desc);
- }
/* Allocate object refs and walk it again.. */
i = 0;
refs = alloc_object_refs(n_refs);
- desc.buf = item->buffer;
- desc.size = item->size;
+ init_tree_desc(&desc, item->buffer, item->size);
while (tree_entry(&desc, &entry)) {
struct object *obj;
int parse_tree(struct tree *item)
{
- char type[20];
+ enum object_type type;
void *buffer;
unsigned long size;
if (item->object.parsed)
return 0;
- buffer = read_sha1_file(item->object.sha1, type, &size);
+ 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, tree_type)) {
+ if (type != OBJ_TREE) {
free(buffer);
return error("Object %s not a tree",
sha1_to_hex(item->object.sha1));