6 const char *tree_type
= "tree";
8 struct tree
*lookup_tree(unsigned char *sha1
)
10 struct object
*obj
= lookup_object(sha1
);
12 struct tree
*ret
= malloc(sizeof(struct tree
));
13 memset(ret
, 0, sizeof(struct tree
));
14 created_object(sha1
, &ret
->object
);
17 if (obj
->parsed
&& obj
->type
!= tree_type
) {
18 error("Object %s is a %s, not a tree",
19 sha1_to_hex(sha1
), obj
->type
);
22 return (struct tree
*) obj
;
25 int parse_tree(struct tree
*item
)
28 void *buffer
, *bufptr
;
30 if (item
->object
.parsed
)
32 item
->object
.parsed
= 1;
33 item
->object
.type
= tree_type
;
34 buffer
= bufptr
= read_sha1_file(item
->object
.sha1
, type
, &size
);
36 return error("Could not read %s",
37 sha1_to_hex(item
->object
.sha1
));
38 if (strcmp(type
, tree_type
))
39 return error("Object %s not a tree",
40 sha1_to_hex(item
->object
.sha1
));
43 int len
= 1+strlen(bufptr
);
44 unsigned char *file_sha1
= bufptr
+ len
;
45 char *path
= strchr(bufptr
, ' ');
47 if (size
< len
+ 20 || !path
||
48 sscanf(bufptr
, "%o", &mode
) != 1)
51 /* Warn about trees that don't do the recursive thing.. */
52 if (strchr(path
, '/')) {
53 item
->has_full_path
= 1;
60 obj
= &lookup_tree(file_sha1
)->object
;
62 obj
= &lookup_blob(file_sha1
)->object
;
64 add_ref(&item
->object
, obj
);