Fix rev-list when showing objects involving submodules
[git/git.git] / tree-walk.h
CommitLineData
1b0c7174
JH
1#ifndef TREE_WALK_H
2#define TREE_WALK_H
3
1b0c7174
JH
4struct name_entry {
5 const unsigned char *sha1;
6 const char *path;
7 unsigned int mode;
1b0c7174
JH
8};
9
4d1012c3
LT
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
4651ece8
LT
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
304de2d2
LT
30static inline int tree_entry_len(const char *name, const unsigned char *sha1)
31{
63daae47 32 return (const char *)sha1 - name - 1;
304de2d2
LT
33}
34
1b0c7174 35void update_tree_entry(struct tree_desc *);
6fda5e51 36void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
1b0c7174 37
4c068a98
LT
38/* Helper function that does both of the above and returns true for success */
39int tree_entry(struct tree_desc *, struct name_entry *);
40
1b0c7174
JH
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
4dcff634
JH
47int get_tree_entry(const unsigned char *, const char *, unsigned char *, unsigned *);
48
1b0c7174 49#endif