🌐 AI搜索 & 代理 主页
blob: 196831007e618f808661bf4b7f54030890f48563 [file] [log] [blame]
Junio C Hamano1b0c7172006-03-30 06:55:431#ifndef TREE_WALK_H
2#define TREE_WALK_H
3
Elijah Newrenef3ca952018-08-15 17:54:054struct strbuf;
5
Junio C Hamano1b0c7172006-03-30 06:55:436struct name_entry {
brian m. carlson7d924c92016-04-17 23:10:397 const struct object_id *oid;
Junio C Hamano1b0c7172006-03-30 06:55:438 const char *path;
9 unsigned int mode;
Junio C Hamano1b0c7172006-03-30 06:55:4310};
11
Linus Torvalds4651ece2007-03-21 17:09:5612struct tree_desc {
13 const void *buffer;
14 struct name_entry entry;
15 unsigned int size;
16};
17
brian m. carlsonce6663a2016-04-17 23:10:4018static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
Linus Torvalds4651ece2007-03-21 17:09:5619{
20 *pathp = desc->entry.path;
Kirill Smelkov7146e662014-02-06 11:36:3121 *modep = desc->entry.mode;
brian m. carlsonce6663a2016-04-17 23:10:4022 return desc->entry.oid;
Linus Torvalds4651ece2007-03-21 17:09:5623}
24
Nguyễn Thái Ngọc Duy0de16332011-10-24 06:36:0925static inline int tree_entry_len(const struct name_entry *ne)
Linus Torvalds304de2d2007-03-18 03:06:2426{
brian m. carlson7d924c92016-04-17 23:10:3927 return (const char *)ne->oid - ne->path - 1;
Linus Torvalds304de2d2007-03-18 03:06:2428}
29
David Turner8354fa32016-09-27 20:59:5130/*
31 * The _gently versions of these functions warn and return false on a
32 * corrupt tree entry rather than dying,
33 */
34
Junio C Hamano1b0c7172006-03-30 06:55:4335void update_tree_entry(struct tree_desc *);
David Turner8354fa32016-09-27 20:59:5136int update_tree_entry_gently(struct tree_desc *);
Linus Torvalds6fda5e52007-03-21 17:08:2537void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
David Turner8354fa32016-09-27 20:59:5138int init_tree_desc_gently(struct tree_desc *desc, const void *buf, unsigned long size);
Junio C Hamano1b0c7172006-03-30 06:55:4339
Elijah Newren2244eab2010-08-25 02:53:1140/*
41 * Helper function that does both tree_entry_extract() and update_tree_entry()
42 * and returns true for success
43 */
Linus Torvalds4c068a92006-05-30 16:45:4544int tree_entry(struct tree_desc *, struct name_entry *);
David Turner8354fa32016-09-27 20:59:5145int tree_entry_gently(struct tree_desc *, struct name_entry *);
Linus Torvalds4c068a92006-05-30 16:45:4546
René Scharfe5c377d32017-08-12 08:32:5947void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid);
Junio C Hamano1b0c7172006-03-30 06:55:4348
Linus Torvalds40d934d2008-03-06 02:59:2949struct traverse_info;
Linus Torvalds91e4f032008-03-06 04:06:1850typedef int (*traverse_callback_t)(int n, unsigned long mask, unsigned long dirmask, struct name_entry *entry, struct traverse_info *);
Linus Torvalds5803c6f2008-03-06 03:44:0651int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info);
Junio C Hamano1b0c7172006-03-30 06:55:4352
David Turner275721c2015-05-20 17:03:3853enum 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. carlson3b683bc2018-05-02 00:25:4069enum 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 Turner275721c2015-05-20 17:03:3870
Linus Torvalds40d934d2008-03-06 02:59:2971struct traverse_info {
David Turnerd9c2bd52015-12-21 22:34:2072 const char *traverse_path;
Linus Torvalds40d934d2008-03-06 02:59:2973 struct traverse_info *prev;
74 struct name_entry name;
75 int pathlen;
Junio C Hamano2842c0f2011-08-29 19:26:0576 struct pathspec *pathspec;
Linus Torvalds40d934d2008-03-06 02:59:2977
René Scharfe603d2492013-06-15 23:44:4378 unsigned long df_conflicts;
Linus Torvalds40d934d2008-03-06 02:59:2979 traverse_callback_t fn;
80 void *data;
Matthieu Moye6c111b2010-08-11 08:38:0781 int show_all_errors;
Linus Torvalds40d934d2008-03-06 02:59:2982};
Junio C Hamano1b0c7172006-03-30 06:55:4383
brian m. carlson916bc352018-03-12 02:27:5184int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned *);
Linus Torvalds40d934d2008-03-06 02:59:2985extern 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{
Nguyễn Thái Ngọc Duy0de16332011-10-24 06:36:0990 return info->pathlen + tree_entry_len(n);
Linus Torvalds40d934d2008-03-06 02:59:2991}
Junio C Hamano4dcff632006-04-19 21:05:4792
Nguyễn Thái Ngọc Duyd688cf02011-10-24 06:36:1093/* 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);
Nguyễn Thái Ngọc Duy2c389fc2010-12-15 15:02:40104
Junio C Hamano1b0c7172006-03-30 06:55:43105#endif