tree-walk: drop oid from traverse_info
[git/git.git] / tree-walk.h
CommitLineData
1b0c7174
JH
1#ifndef TREE_WALK_H
2#define TREE_WALK_H
3
ea82b2a0 4#include "cache.h"
ef3ca954 5
1b0c7174 6struct name_entry {
ea82b2a0 7 struct object_id oid;
1b0c7174 8 const char *path;
ea82b2a0 9 int pathlen;
1b0c7174 10 unsigned int mode;
1b0c7174
JH
11};
12
4651ece8
LT
13struct tree_desc {
14 const void *buffer;
15 struct name_entry entry;
16 unsigned int size;
17};
18
5ec1e728 19static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned short *modep)
4651ece8
LT
20{
21 *pathp = desc->entry.path;
7146e66f 22 *modep = desc->entry.mode;
ea82b2a0 23 return &desc->entry.oid;
4651ece8
LT
24}
25
0de16337 26static inline int tree_entry_len(const struct name_entry *ne)
304de2d2 27{
ea82b2a0 28 return ne->pathlen;
304de2d2
LT
29}
30
8354fa3d
DT
31/*
32 * The _gently versions of these functions warn and return false on a
33 * corrupt tree entry rather than dying,
34 */
35
1b0c7174 36void update_tree_entry(struct tree_desc *);
8354fa3d 37int update_tree_entry_gently(struct tree_desc *);
6fda5e51 38void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
8354fa3d 39int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long size);
1b0c7174 40
2244eab0
EN
41/*
42 * Helper function that does both tree_entry_extract() and update_tree_entry()
43 * and returns true for success
44 */
4c068a98 45int tree_entry(struct tree_desc *, struct name_entry *);
8354fa3d 46int tree_entry_gently(struct tree_desc *, struct name_entry *);
4c068a98 47
5c377d3d 48void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);
1b0c7174 49
40d934df 50struct traverse_info;
91e4f036 51typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
67022e02 52int traverse_trees(struct index_state *istate, int n, struct tree_desc *t, struct traverse_info *info);
1b0c7174 53
5ec1e728 54enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, const char *name, struct object_id *result, struct strbuf *result_path, unsigned short *mode);
275721c2 55
40d934df 56struct traverse_info {
d9c2bd56 57 const char *traverse_path;
40d934df 58 struct traverse_info *prev;
90553847
JK
59 const char *name;
60 size_t namelen;
61 unsigned mode;
62
40d934df 63 int pathlen;
2842c0f9 64 struct pathspec *pathspec;
40d934df 65
603d2498 66 unsigned long df_conflicts;
40d934df
LT
67 traverse_callback_t fn;
68 void *data;
e6c111b4 69 int show_all_errors;
40d934df 70};
1b0c7174 71
5ec1e728 72int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned short *);
90553847
JK
73char *make_traverse_path(char *path, const struct traverse_info *info,
74 const char *name, size_t namelen);
55454427 75void setup_traverse_info(struct traverse_info *info, const char *base);
40d934df
LT
76
77static inline int traverse_path_len(const struct traverse_info *info, const struct name_entry *n)
78{
0de16337 79 return info->pathlen + tree_entry_len(n);
40d934df 80}
4dcff634 81
d688cf07
NTND
82/* in general, positive means "kind of interesting" */
83enum interesting {
84 all_entries_not_interesting = -1, /* no, and no subsequent entries will be either */
85 entry_not_interesting = 0,
86 entry_interesting = 1,
87 all_entries_interesting = 2 /* yes, and all subsequent entries will be */
88};
89
67022e02
NTND
90enum interesting tree_entry_interesting(struct index_state *istate,
91 const struct name_entry *,
92 struct strbuf *, int,
93 const struct pathspec *ps);
2c389fc8 94
1b0c7174 95#endif