tree.c: make read_tree*() take 'struct repository *'
[git/git.git] / tree-walk.h
CommitLineData
1b0c7174
JH
1#ifndef TREE_WALK_H
2#define TREE_WALK_H
3
ef3ca954
EN
4struct strbuf;
5
1b0c7174 6struct name_entry {
7d924c91 7 const struct object_id *oid;
1b0c7174
JH
8 const char *path;
9 unsigned int mode;
1b0c7174
JH
10};
11
4651ece8
LT
12struct tree_desc {
13 const void *buffer;
14 struct name_entry entry;
15 unsigned int size;
16};
17
ce6663a9 18static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
4651ece8
LT
19{
20 *pathp = desc->entry.path;
7146e66f 21 *modep = desc->entry.mode;
ce6663a9 22 return desc->entry.oid;
4651ece8
LT
23}
24
0de16337 25static inline int tree_entry_len(const struct name_entry *ne)
304de2d2 26{
7d924c91 27 return (const char *)ne->oid - ne->path - 1;
304de2d2
LT
28}
29
8354fa3d
DT
30/*
31 * The _gently versions of these functions warn and return false on a
32 * corrupt tree entry rather than dying,
33 */
34
1b0c7174 35void update_tree_entry(struct tree_desc *);
8354fa3d 36int update_tree_entry_gently(struct tree_desc *);
6fda5e51 37void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
8354fa3d 38int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long size);
1b0c7174 39
2244eab0
EN
40/*
41 * Helper function that does both tree_entry_extract() and update_tree_entry()
42 * and returns true for success
43 */
4c068a98 44int tree_entry(struct tree_desc *, struct name_entry *);
8354fa3d 45int tree_entry_gently(struct tree_desc *, struct name_entry *);
4c068a98 46
5c377d3d 47void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);
1b0c7174 48
40d934df 49struct traverse_info;
91e4f036 50typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
5803c6f8 51int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info);
1b0c7174 52
275721c2
DT
53enum follow_symlinks_result {
54 FOUND = 0, /* This includes out-of-tree links */
55 MISSING_OBJECT = -1, /* The initial symlink is missing */
56 DANGLING_SYMLINK = -2, /*
57 * The initial symlink is there, but
58 * (transitively) points to a missing
59 * in-tree file
60 */
61 SYMLINK_LOOP = -3,
62 NOT_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};
68
3b683bcf 69enum 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);
275721c2 70
40d934df 71struct traverse_info {
d9c2bd56 72 const char *traverse_path;
40d934df
LT
73 struct traverse_info *prev;
74 struct name_entry name;
75 int pathlen;
2842c0f9 76 struct pathspec *pathspec;
40d934df 77
603d2498 78 unsigned long df_conflicts;
40d934df
LT
79 traverse_callback_t fn;
80 void *data;
e6c111b4 81 int show_all_errors;
40d934df 82};
1b0c7174 83
916bc35b 84int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned *);
40d934df
LT
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);
87
88static inline int traverse_path_len(const struct traverse_info *info, const struct name_entry *n)
89{
0de16337 90 return info->pathlen + tree_entry_len(n);
40d934df 91}
4dcff634 92
d688cf07
NTND
93/* in general, positive means "kind of interesting" */
94enum interesting {
95 all_entries_not_interesting = -1, /* no, and no subsequent entries will be either */
96 entry_not_interesting = 0,
97 entry_interesting = 1,
98 all_entries_interesting = 2 /* yes, and all subsequent entries will be */
99};
100
101extern enum interesting tree_entry_interesting(const struct name_entry *,
102 struct strbuf *, int,
103 const struct pathspec *ps);
2c389fc8 104
1b0c7174 105#endif