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