| Junio C Hamano | 1b0c717 | 2006-03-30 06:55:43 | [diff] [blame] | 1 | #ifndef TREE_WALK_H |
| 2 | #define TREE_WALK_H |
| 3 | |
| Elijah Newren | ef3ca95 | 2018-08-15 17:54:05 | [diff] [blame] | 4 | struct strbuf; |
| 5 | |
| Junio C Hamano | 1b0c717 | 2006-03-30 06:55:43 | [diff] [blame] | 6 | struct name_entry { |
| brian m. carlson | 7d924c9 | 2016-04-17 23:10:39 | [diff] [blame] | 7 | const struct object_id *oid; |
| Junio C Hamano | 1b0c717 | 2006-03-30 06:55:43 | [diff] [blame] | 8 | const char *path; |
| 9 | unsigned int mode; |
| Junio C Hamano | 1b0c717 | 2006-03-30 06:55:43 | [diff] [blame] | 10 | }; |
| 11 | |
| Linus Torvalds | 4651ece | 2007-03-21 17:09:56 | [diff] [blame] | 12 | struct tree_desc { |
| 13 | const void *buffer; |
| 14 | struct name_entry entry; |
| 15 | unsigned int size; |
| 16 | }; |
| 17 | |
| brian m. carlson | ce6663a | 2016-04-17 23:10:40 | [diff] [blame] | 18 | static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep) |
| Linus Torvalds | 4651ece | 2007-03-21 17:09:56 | [diff] [blame] | 19 | { |
| 20 | *pathp = desc->entry.path; |
| Kirill Smelkov | 7146e66 | 2014-02-06 11:36:31 | [diff] [blame] | 21 | *modep = desc->entry.mode; |
| brian m. carlson | ce6663a | 2016-04-17 23:10:40 | [diff] [blame] | 22 | return desc->entry.oid; |
| Linus Torvalds | 4651ece | 2007-03-21 17:09:56 | [diff] [blame] | 23 | } |
| 24 | |
| Nguyễn Thái Ngọc Duy | 0de1633 | 2011-10-24 06:36:09 | [diff] [blame] | 25 | static inline int tree_entry_len(const struct name_entry *ne) |
| Linus Torvalds | 304de2d | 2007-03-18 03:06:24 | [diff] [blame] | 26 | { |
| brian m. carlson | 7d924c9 | 2016-04-17 23:10:39 | [diff] [blame] | 27 | return (const char *)ne->oid - ne->path - 1; |
| Linus Torvalds | 304de2d | 2007-03-18 03:06:24 | [diff] [blame] | 28 | } |
| 29 | |
| David Turner | 8354fa3 | 2016-09-27 20:59:51 | [diff] [blame] | 30 | /* |
| 31 | * The _gently versions of these functions warn and return false on a |
| 32 | * corrupt tree entry rather than dying, |
| 33 | */ |
| 34 | |
| Junio C Hamano | 1b0c717 | 2006-03-30 06:55:43 | [diff] [blame] | 35 | void update_tree_entry(struct tree_desc *); |
| David Turner | 8354fa3 | 2016-09-27 20:59:51 | [diff] [blame] | 36 | int update_tree_entry_gently(struct tree_desc *); |
| Linus Torvalds | 6fda5e5 | 2007-03-21 17:08:25 | [diff] [blame] | 37 | void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size); |
| David Turner | 8354fa3 | 2016-09-27 20:59:51 | [diff] [blame] | 38 | int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long size); |
| Junio C Hamano | 1b0c717 | 2006-03-30 06:55:43 | [diff] [blame] | 39 | |
| Elijah Newren | 2244eab | 2010-08-25 02:53:11 | [diff] [blame] | 40 | /* |
| 41 | * Helper function that does both tree_entry_extract() and update_tree_entry() |
| 42 | * and returns true for success |
| 43 | */ |
| Linus Torvalds | 4c068a9 | 2006-05-30 16:45:45 | [diff] [blame] | 44 | int tree_entry(struct tree_desc *, struct name_entry *); |
| David Turner | 8354fa3 | 2016-09-27 20:59:51 | [diff] [blame] | 45 | int tree_entry_gently(struct tree_desc *, struct name_entry *); |
| Linus Torvalds | 4c068a9 | 2006-05-30 16:45:45 | [diff] [blame] | 46 | |
| René Scharfe | 5c377d3 | 2017-08-12 08:32:59 | [diff] [blame] | 47 | void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid); |
| Junio C Hamano | 1b0c717 | 2006-03-30 06:55:43 | [diff] [blame] | 48 | |
| Linus Torvalds | 40d934d | 2008-03-06 02:59:29 | [diff] [blame] | 49 | struct traverse_info; |
| Linus Torvalds | 91e4f03 | 2008-03-06 04:06:18 | [diff] [blame] | 50 | typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *); |
| Linus Torvalds | 5803c6f | 2008-03-06 03:44:06 | [diff] [blame] | 51 | int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info); |
| Junio C Hamano | 1b0c717 | 2006-03-30 06:55:43 | [diff] [blame] | 52 | |
| David Turner | 275721c | 2015-05-20 17:03:38 | [diff] [blame] | 53 | enum 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 | |
| brian m. carlson | 3b683bc | 2018-05-02 00:25:40 | [diff] [blame] | 69 | 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); |
| David Turner | 275721c | 2015-05-20 17:03:38 | [diff] [blame] | 70 | |
| Linus Torvalds | 40d934d | 2008-03-06 02:59:29 | [diff] [blame] | 71 | struct traverse_info { |
| David Turner | d9c2bd5 | 2015-12-21 22:34:20 | [diff] [blame] | 72 | const char *traverse_path; |
| Linus Torvalds | 40d934d | 2008-03-06 02:59:29 | [diff] [blame] | 73 | struct traverse_info *prev; |
| 74 | struct name_entry name; |
| 75 | int pathlen; |
| Junio C Hamano | 2842c0f | 2011-08-29 19:26:05 | [diff] [blame] | 76 | struct pathspec *pathspec; |
| Linus Torvalds | 40d934d | 2008-03-06 02:59:29 | [diff] [blame] | 77 | |
| René Scharfe | 603d249 | 2013-06-15 23:44:43 | [diff] [blame] | 78 | unsigned long df_conflicts; |
| Linus Torvalds | 40d934d | 2008-03-06 02:59:29 | [diff] [blame] | 79 | traverse_callback_t fn; |
| 80 | void *data; |
| Matthieu Moy | e6c111b | 2010-08-11 08:38:07 | [diff] [blame] | 81 | int show_all_errors; |
| Linus Torvalds | 40d934d | 2008-03-06 02:59:29 | [diff] [blame] | 82 | }; |
| Junio C Hamano | 1b0c717 | 2006-03-30 06:55:43 | [diff] [blame] | 83 | |
| brian m. carlson | 916bc35 | 2018-03-12 02:27:51 | [diff] [blame] | 84 | int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned *); |
| Linus Torvalds | 40d934d | 2008-03-06 02:59:29 | [diff] [blame] | 85 | extern char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n); |
| 86 | extern void setup_traverse_info(struct traverse_info *info, const char *base); |
| 87 | |
| 88 | static inline int traverse_path_len(const struct traverse_info *info, const struct name_entry *n) |
| 89 | { |
| Nguyễn Thái Ngọc Duy | 0de1633 | 2011-10-24 06:36:09 | [diff] [blame] | 90 | return info->pathlen + tree_entry_len(n); |
| Linus Torvalds | 40d934d | 2008-03-06 02:59:29 | [diff] [blame] | 91 | } |
| Junio C Hamano | 4dcff63 | 2006-04-19 21:05:47 | [diff] [blame] | 92 | |
| Nguyễn Thái Ngọc Duy | d688cf0 | 2011-10-24 06:36:10 | [diff] [blame] | 93 | /* in general, positive means "kind of interesting" */ |
| 94 | enum 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 | |
| 101 | extern enum interesting tree_entry_interesting(const struct name_entry *, |
| 102 | struct strbuf *, int, |
| 103 | const struct pathspec *ps); |
| Nguyễn Thái Ngọc Duy | 2c389fc | 2010-12-15 15:02:40 | [diff] [blame] | 104 | |
| Junio C Hamano | 1b0c717 | 2006-03-30 06:55:43 | [diff] [blame] | 105 | #endif |