Fix rev-list when showing objects involving submodules
[git/git.git] / tree-walk.h
1 #ifndef TREE_WALK_H
2 #define TREE_WALK_H
3
4 struct name_entry {
5 const unsigned char *sha1;
6 const char *path;
7 unsigned int mode;
8 };
9
10 static 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
17 struct tree_desc {
18 const void *buffer;
19 struct name_entry entry;
20 unsigned int size;
21 };
22
23 static 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
30 static inline int tree_entry_len(const char *name, const unsigned char *sha1)
31 {
32 return (const char *)sha1 - name - 1;
33 }
34
35 void update_tree_entry(struct tree_desc *);
36 void 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 */
39 int tree_entry(struct tree_desc *, struct name_entry *);
40
41 void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1);
42
43 typedef void (*traverse_callback_t)(int n, unsigned long mask, struct name_entry *entry, const char *base);
44
45 void traverse_trees(int n, struct tree_desc *t, const char *base, traverse_callback_t callback);
46
47 int get_tree_entry(const unsigned char *, const char *, unsigned char *, unsigned *);
48
49 #endif