1#ifndef TREE_WALK_H
2#define TREE_WALK_H
3
4struct name_entry {
5 const unsigned char *sha1;
6 const char *path;
7 unsigned int mode;
8};
9
10static inline enum object_type object_type(unsigned int mode)
11{
12 return S_ISDIR(mode) ? OBJ_TREE :
13 S_ISGITLINK(mode) ? OBJ_COMMIT :
14 OBJ_BLOB;
15}
16
17struct tree_desc {
18 const void *buffer;
19 struct name_entry entry;
20 unsigned int size;
21};
22
23static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
24{
25 *pathp = desc->entry.path;
26 *modep = canon_mode(desc->entry.mode);
27 return desc->entry.sha1;
28}
29
30static inline int tree_entry_len(const char *name, const unsigned char *sha1)
31{
32 return (const char *)sha1 - name - 1;
33}
34
35void update_tree_entry(struct tree_desc *);
36void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
37
38/* Helper function that does both of the above and returns true for success */
39int tree_entry(struct tree_desc *, struct name_entry *);
40
41void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1);
42
43typedef void (*traverse_callback_t)(int n, unsigned long mask, struct name_entry *entry, const char *base);
44
45void traverse_trees(int n, struct tree_desc *t, const char *base, traverse_callback_t callback);
46
47int get_tree_entry(const unsigned char *, const char *, unsigned char *, unsigned *);
48
49#endif