blob: 97a7d6957e002e854d3b93831902776c994b6208 [file] [log] [blame]
Junio C Hamano1b0c7172006-03-29 22:55:43 -08001#ifndef TREE_WALK_H
2#define TREE_WALK_H
3
Junio C Hamano1b0c7172006-03-29 22:55:43 -08004struct name_entry {
brian m. carlson7d924c92016-04-17 23:10:39 +00005 const struct object_id *oid;
Junio C Hamano1b0c7172006-03-29 22:55:43 -08006 const char *path;
7 unsigned int mode;
Junio C Hamano1b0c7172006-03-29 22:55:43 -08008};
9
Linus Torvalds4651ece2007-03-21 10:09:56 -070010struct tree_desc {
11 const void *buffer;
12 struct name_entry entry;
13 unsigned int size;
14};
15
brian m. carlsonce6663a2016-04-17 23:10:40 +000016static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
Linus Torvalds4651ece2007-03-21 10:09:56 -070017{
18 *pathp = desc->entry.path;
Kirill Smelkov7146e662014-02-06 15:36:31 +040019 *modep = desc->entry.mode;
brian m. carlsonce6663a2016-04-17 23:10:40 +000020 return desc->entry.oid;
Linus Torvalds4651ece2007-03-21 10:09:56 -070021}
22
Nguyễn Thái Ngọc Duy0de16332011-10-24 17:36:09 +110023static inline int tree_entry_len(const struct name_entry *ne)
Linus Torvalds304de2d2007-03-17 20:06:24 -070024{
brian m. carlson7d924c92016-04-17 23:10:39 +000025 return (const char *)ne->oid - ne->path - 1;
Linus Torvalds304de2d2007-03-17 20:06:24 -070026}
27
Junio C Hamano1b0c7172006-03-29 22:55:43 -080028void update_tree_entry(struct tree_desc *);
Linus Torvalds6fda5e52007-03-21 10:08:25 -070029void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
Junio C Hamano1b0c7172006-03-29 22:55:43 -080030
Elijah Newren2244eab2010-08-24 20:53:11 -060031/*
32 * Helper function that does both tree_entry_extract() and update_tree_entry()
33 * and returns true for success
34 */
Linus Torvalds4c068a92006-05-30 09:45:45 -070035int tree_entry(struct tree_desc *, struct name_entry *);
36
Junio C Hamano1b0c7172006-03-29 22:55:43 -080037void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1);
38
Linus Torvalds40d934d2008-03-05 18:59:29 -080039struct traverse_info;
Linus Torvalds91e4f032008-03-05 20:06:18 -080040typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
Linus Torvalds5803c6f2008-03-05 19:44:06 -080041int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info);
Junio C Hamano1b0c7172006-03-29 22:55:43 -080042
David Turner275721c2015-05-20 13:03:38 -040043enum follow_symlinks_result {
44 FOUND = 0, /* This includes out-of-tree links */
45 MISSING_OBJECT = -1, /* The initial symlink is missing */
46 DANGLING_SYMLINK = -2, /*
47 * The initial symlink is there, but
48 * (transitively) points to a missing
49 * in-tree file
50 */
51 SYMLINK_LOOP = -3,
52 NOT_DIR = -4, /*
53 * Somewhere along the symlink chain, a path is
54 * requested which contains a file as a
55 * non-final element.
56 */
57};
58
59enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_sha1, const char *name, unsigned char *result, struct strbuf *result_path, unsigned *mode);
60
Linus Torvalds40d934d2008-03-05 18:59:29 -080061struct traverse_info {
David Turnerd9c2bd52015-12-21 17:34:20 -050062 const char *traverse_path;
Linus Torvalds40d934d2008-03-05 18:59:29 -080063 struct traverse_info *prev;
64 struct name_entry name;
65 int pathlen;
Junio C Hamano2842c0f2011-08-29 12:26:05 -070066 struct pathspec *pathspec;
Linus Torvalds40d934d2008-03-05 18:59:29 -080067
René Scharfe603d2492013-06-16 01:44:43 +020068 unsigned long df_conflicts;
Linus Torvalds40d934d2008-03-05 18:59:29 -080069 traverse_callback_t fn;
70 void *data;
Matthieu Moye6c111b2010-08-11 10:38:07 +020071 int show_all_errors;
Linus Torvalds40d934d2008-03-05 18:59:29 -080072};
Junio C Hamano1b0c7172006-03-29 22:55:43 -080073
Junio C Hamano4dcff632006-04-19 14:05:47 -070074int get_tree_entry(const unsigned char *, const char *, unsigned char *, unsigned *);
Linus Torvalds40d934d2008-03-05 18:59:29 -080075extern char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);
76extern void setup_traverse_info(struct traverse_info *info, const char *base);
77
78static inline int traverse_path_len(const struct traverse_info *info, const struct name_entry *n)
79{
Nguyễn Thái Ngọc Duy0de16332011-10-24 17:36:09 +110080 return info->pathlen + tree_entry_len(n);
Linus Torvalds40d934d2008-03-05 18:59:29 -080081}
Junio C Hamano4dcff632006-04-19 14:05:47 -070082
Nguyễn Thái Ngọc Duyd688cf02011-10-24 17:36:10 +110083/* in general, positive means "kind of interesting" */
84enum interesting {
85 all_entries_not_interesting = -1, /* no, and no subsequent entries will be either */
86 entry_not_interesting = 0,
87 entry_interesting = 1,
88 all_entries_interesting = 2 /* yes, and all subsequent entries will be */
89};
90
91extern enum interesting tree_entry_interesting(const struct name_entry *,
92 struct strbuf *, int,
93 const struct pathspec *ps);
Nguyễn Thái Ngọc Duy2c389fc2010-12-15 22:02:40 +070094
Junio C Hamano1b0c7172006-03-29 22:55:43 -080095#endif