eefd26bb6214916f7c451d97710b5ee443e52088
1#ifndef TREE_WALK_H
2#define TREE_WALK_H
3
4struct index_state;
5struct strbuf;
6
7struct name_entry {
8 const struct object_id *oid;
9 const char *path;
10 unsigned int mode;
11};
12
13struct tree_desc {
14 const void *buffer;
15 struct name_entry entry;
16 unsigned int size;
17};
18
19static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
20{
21 *pathp = desc->entry.path;
22 *modep = desc->entry.mode;
23 return desc->entry.oid;
24}
25
26static inline int tree_entry_len(const struct name_entry *ne)
27{
28 return (const char *)ne->oid - ne->path - 1;
29}
30
31/*
32 * The _gently versions of these functions warn and return false on a
33 * corrupt tree entry rather than dying,
34 */
35
36void update_tree_entry(struct tree_desc *);
37int update_tree_entry_gently(struct tree_desc *);
38void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
39int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long size);
40
41/*
42 * Helper function that does both tree_entry_extract() and update_tree_entry()
43 * and returns true for success
44 */
45int tree_entry(struct tree_desc *, struct name_entry *);
46int tree_entry_gently(struct tree_desc *, struct name_entry *);
47
48void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);
49
50struct traverse_info;
51typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
52int traverse_trees(struct index_state *istate, int n, struct tree_desc *t, struct traverse_info *info);
53
54enum follow_symlinks_result {
55 FOUND = 0, /* This includes out-of-tree links */
56 MISSING_OBJECT = -1, /* The initial symlink is missing */
57 DANGLING_SYMLINK = -2, /*
58 * The initial symlink is there, but
59 * (transitively) points to a missing
60 * in-tree file
61 */
62 SYMLINK_LOOP = -3,
63 NOT_DIR = -4, /*
64 * Somewhere along the symlink chain, a path is
65 * requested which contains a file as a
66 * non-final element.
67 */
68};
69
70enum follow_symlinks_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned *mode);
71
72struct traverse_info {
73 const char *traverse_path;
74 struct traverse_info *prev;
75 struct name_entry name;
76 int pathlen;
77 struct pathspec *pathspec;
78
79 unsigned long df_conflicts;
80 traverse_callback_t fn;
81 void *data;
82 int show_all_errors;
83};
84
85int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned *);
86extern char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);
87extern void setup_traverse_info(struct traverse_info *info, const char *base);
88
89static inline int traverse_path_len(const struct traverse_info *info, const struct name_entry *n)
90{
91 return info->pathlen + tree_entry_len(n);
92}
93
94/* in general, positive means "kind of interesting" */
95enum interesting {
96 all_entries_not_interesting = -1, /* no, and no subsequent entries will be either */
97 entry_not_interesting = 0,
98 entry_interesting = 1,
99 all_entries_interesting = 2 /* yes, and all subsequent entries will be */
100};
101
102enum interesting tree_entry_interesting(struct index_state *istate,
103 const struct name_entry *,
104 struct strbuf *, int,
105 const struct pathspec *ps);
106
107#endif