1#ifndef TREE_WALK_H
2#define TREE_WALK_H
34
struct strbuf;
56
struct name_entry {
7const struct object_id *oid;
8const char *path;
9unsigned int mode;
10};
1112
struct tree_desc {
13const void *buffer;
14struct name_entry entry;
15unsigned int size;
16};
1718
static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
19{
20*pathp = desc->entry.path;
21*modep = desc->entry.mode;
22return desc->entry.oid;
23}
2425
static inline int tree_entry_len(const struct name_entry *ne)
26{
27return (const char *)ne->oid - ne->path - 1;
28}
2930
/*
31* The _gently versions of these functions warn and return false on a
32* corrupt tree entry rather than dying,
33*/
3435
void update_tree_entry(struct tree_desc *);
36int update_tree_entry_gently(struct tree_desc *);
37void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
38int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long size);
3940
/*
41* Helper function that does both tree_entry_extract() and update_tree_entry()
42* and returns true for success
43*/
44int tree_entry(struct tree_desc *, struct name_entry *);
45int tree_entry_gently(struct tree_desc *, struct name_entry *);
4647
void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);
4849
struct traverse_info;
50typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
51int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info);
5253
enum follow_symlinks_result {
54FOUND = 0, /* This includes out-of-tree links */
55MISSING_OBJECT = -1, /* The initial symlink is missing */
56DANGLING_SYMLINK = -2, /*
57* The initial symlink is there, but
58* (transitively) points to a missing
59* in-tree file
60*/
61SYMLINK_LOOP = -3,
62NOT_DIR = -4, /*
63* Somewhere along the symlink chain, a path is
64* requested which contains a file as a
65* non-final element.
66*/
67};
6869
enum 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);
7071
struct traverse_info {
72const char *traverse_path;
73struct traverse_info *prev;
74struct name_entry name;
75int pathlen;
76struct pathspec *pathspec;
7778
unsigned long df_conflicts;
79traverse_callback_t fn;
80void *data;
81int show_all_errors;
82};
8384
int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned *);
85extern char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);
86extern void setup_traverse_info(struct traverse_info *info, const char *base);
8788
static inline int traverse_path_len(const struct traverse_info *info, const struct name_entry *n)
89{
90return info->pathlen + tree_entry_len(n);
91}
9293
/* in general, positive means "kind of interesting" */
94enum interesting {
95all_entries_not_interesting = -1, /* no, and no subsequent entries will be either */
96entry_not_interesting = 0,
97entry_interesting = 1,
98all_entries_interesting = 2 /* yes, and all subsequent entries will be */
99};
100101
extern enum interesting tree_entry_interesting(const struct name_entry *,
102struct strbuf *, int,
103const struct pathspec *ps);
104105
#endif