blob: ae7fb3a824a960c6c03efae799683cd7e18d402c [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 {
5 const unsigned char *sha1;
6 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
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 15:36:31 +040019 *modep = desc->entry.mode;
Linus Torvalds4651ece2007-03-21 10:09:56 -070020 return desc->entry.sha1;
21}
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{
Nguyễn Thái Ngọc Duy0de16332011-10-24 17:36:09 +110025 return (const char *)ne->sha1 - 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
Linus Torvalds40d934d2008-03-05 18:59:29 -080043struct traverse_info {
44 struct traverse_info *prev;
45 struct name_entry name;
46 int pathlen;
Junio C Hamano2842c0f2011-08-29 12:26:05 -070047 struct pathspec *pathspec;
Linus Torvalds40d934d2008-03-05 18:59:29 -080048
René Scharfe603d2492013-06-16 01:44:43 +020049 unsigned long df_conflicts;
Linus Torvalds40d934d2008-03-05 18:59:29 -080050 traverse_callback_t fn;
51 void *data;
Matthieu Moye6c111b2010-08-11 10:38:07 +020052 int show_all_errors;
Linus Torvalds40d934d2008-03-05 18:59:29 -080053};
Junio C Hamano1b0c7172006-03-29 22:55:43 -080054
Junio C Hamano4dcff632006-04-19 14:05:47 -070055int get_tree_entry(const unsigned char *, const char *, unsigned char *, unsigned *);
Linus Torvalds40d934d2008-03-05 18:59:29 -080056extern 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 17:36:09 +110061 return info->pathlen + tree_entry_len(n);
Linus Torvalds40d934d2008-03-05 18:59:29 -080062}
Junio C Hamano4dcff632006-04-19 14:05:47 -070063
Nguyễn Thái Ngọc Duyd688cf02011-10-24 17:36:10 +110064/* 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 22:02:40 +070075
Junio C Hamano1b0c7172006-03-29 22:55:43 -080076#endif