🌐 AI搜索 & 代理 主页
blob: ae7fb3a824a960c6c03efae799683cd7e18d402c [file] [log] [blame]
Junio C Hamano1b0c7172006-03-30 06:55:431#ifndef TREE_WALK_H
2#define TREE_WALK_H
3
Junio C Hamano1b0c7172006-03-30 06:55:434struct name_entry {
5 const unsigned char *sha1;
6 const char *path;
7 unsigned int mode;
Junio C Hamano1b0c7172006-03-30 06:55:438};
9
Linus Torvalds4651ece2007-03-21 17:09:5610struct tree_desc {
11 const void *buffer;
12 struct name_entry entry;
13 unsigned int size;
14};
15
16static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
17{
18 *pathp = desc->entry.path;
Kirill Smelkov7146e662014-02-06 11:36:3119 *modep = desc->entry.mode;
Linus Torvalds4651ece2007-03-21 17:09:5620 return desc->entry.sha1;
21}
22
Nguyễn Thái Ngọc Duy0de16332011-10-24 06:36:0923static inline int tree_entry_len(const struct name_entry *ne)
Linus Torvalds304de2d2007-03-18 03:06:2424{
Nguyễn Thái Ngọc Duy0de16332011-10-24 06:36:0925 return (const char *)ne->sha1 - ne->path - 1;
Linus Torvalds304de2d2007-03-18 03:06:2426}
27
Junio C Hamano1b0c7172006-03-30 06:55:4328void update_tree_entry(struct tree_desc *);
Linus Torvalds6fda5e52007-03-21 17:08:2529void init_tree_desc(struct tree_desc *desc, const void *buf, unsigned long size);
Junio C Hamano1b0c7172006-03-30 06:55:4330
Elijah Newren2244eab2010-08-25 02:53:1131/*
32 * Helper function that does both tree_entry_extract() and update_tree_entry()
33 * and returns true for success
34 */
Linus Torvalds4c068a92006-05-30 16:45:4535int tree_entry(struct tree_desc *, struct name_entry *);
36
Junio C Hamano1b0c7172006-03-30 06:55:4337void *fill_tree_descriptor(struct tree_desc *desc, const unsigned char *sha1);
38
Linus Torvalds40d934d2008-03-06 02:59:2939struct traverse_info;
Linus Torvalds91e4f032008-03-06 04:06:1840typedef 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:0641int traverse_trees(int n, struct tree_desc *t, struct traverse_info *info);
Junio C Hamano1b0c7172006-03-30 06:55:4342
Linus Torvalds40d934d2008-03-06 02:59:2943struct traverse_info {
44 struct traverse_info *prev;
45 struct name_entry name;
46 int pathlen;
Junio C Hamano2842c0f2011-08-29 19:26:0547 struct pathspec *pathspec;
Linus Torvalds40d934d2008-03-06 02:59:2948
René Scharfe603d2492013-06-15 23:44:4349 unsigned long df_conflicts;
Linus Torvalds40d934d2008-03-06 02:59:2950 traverse_callback_t fn;
51 void *data;
Matthieu Moye6c111b2010-08-11 08:38:0752 int show_all_errors;
Linus Torvalds40d934d2008-03-06 02:59:2953};
Junio C Hamano1b0c7172006-03-30 06:55:4354
Junio C Hamano4dcff632006-04-19 21:05:4755int get_tree_entry(const unsigned char *, const char *, unsigned char *, unsigned *);
Linus Torvalds40d934d2008-03-06 02:59:2956extern char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);
57extern void setup_traverse_info(struct traverse_info *info, const char *base);
58
59static inline int traverse_path_len(const struct traverse_info *info, const struct name_entry *n)
60{
Nguyễn Thái Ngọc Duy0de16332011-10-24 06:36:0961 return info->pathlen + tree_entry_len(n);
Linus Torvalds40d934d2008-03-06 02:59:2962}
Junio C Hamano4dcff632006-04-19 21:05:4763
Nguyễn Thái Ngọc Duyd688cf02011-10-24 06:36:1064/* in general, positive means "kind of interesting" */
65enum interesting {
66 all_entries_not_interesting = -1, /* no, and no subsequent entries will be either */
67 entry_not_interesting = 0,
68 entry_interesting = 1,
69 all_entries_interesting = 2 /* yes, and all subsequent entries will be */
70};
71
72extern enum interesting tree_entry_interesting(const struct name_entry *,
73 struct strbuf *, int,
74 const struct pathspec *ps);
Nguyễn Thái Ngọc Duy2c389fc2010-12-15 15:02:4075
Junio C Hamano1b0c7172006-03-30 06:55:4376#endif