blob: d8814dccb2dd57af21d75c91a52026e09fdf1b95 [file] [log] [blame]
Linus Torvalds453ec4b2006-05-16 19:02:14 -07001#ifndef DIR_H
2#define DIR_H
3
Linus Torvalds453ec4b2006-05-16 19:02:14 -07004struct dir_entry {
Jeff Kinge96980e2007-06-12 23:42:14 +02005 unsigned int len;
Linus Torvalds453ec4b2006-05-16 19:02:14 -07006 char name[FLEX_ARRAY]; /* more */
7};
8
Lars Knoll68492fc2007-10-28 21:27:13 +01009#define EXC_FLAG_NODIR 1
10#define EXC_FLAG_NOWILDCARD 2
11#define EXC_FLAG_ENDSWITH 4
12
Linus Torvalds453ec4b2006-05-16 19:02:14 -070013struct exclude_list {
14 int nr;
15 int alloc;
16 struct exclude {
17 const char *pattern;
Lars Knoll68492fc2007-10-28 21:27:13 +010018 int patternlen;
Linus Torvalds453ec4b2006-05-16 19:02:14 -070019 const char *base;
20 int baselen;
Lars Knoll68492fc2007-10-28 21:27:13 +010021 int to_exclude;
22 int flags;
Linus Torvalds453ec4b2006-05-16 19:02:14 -070023 } **excludes;
24};
25
Junio C Hamano63d285c2007-11-29 02:17:44 -080026struct exclude_stack {
27 struct exclude_stack *prev;
28 char *filebuf;
29 int baselen;
30 int exclude_ix;
31};
32
Linus Torvalds453ec4b2006-05-16 19:02:14 -070033struct dir_struct {
34 int nr, alloc;
Jeff King2abd31b2007-06-11 09:39:50 -040035 int ignored_nr, ignored_alloc;
Junio C Hamanoc8897632006-12-29 10:08:19 -080036 unsigned int show_ignored:1,
Linus Torvalds453ec4b2006-05-16 19:02:14 -070037 show_other_directories:1,
Linus Torvalds09595252007-04-11 14:49:44 -070038 hide_empty_directories:1,
Jeff King2abd31b2007-06-11 09:39:50 -040039 no_gitlinks:1,
40 collect_ignored:1;
Linus Torvalds453ec4b2006-05-16 19:02:14 -070041 struct dir_entry **entries;
Jeff King2abd31b2007-06-11 09:39:50 -040042 struct dir_entry **ignored;
Linus Torvalds453ec4b2006-05-16 19:02:14 -070043
44 /* Exclude info */
45 const char *exclude_per_dir;
46 struct exclude_list exclude_list[3];
Junio C Hamano63d285c2007-11-29 02:17:44 -080047 /*
48 * We maintain three exclude pattern lists:
49 * EXC_CMDL lists patterns explicitly given on the command line.
50 * EXC_DIRS lists patterns obtained from per-directory ignore files.
51 * EXC_FILE lists patterns from fallback ignore files.
52 */
53#define EXC_CMDL 0
54#define EXC_DIRS 1
55#define EXC_FILE 2
56
57 struct exclude_stack *exclude_stack;
58 char basebuf[PATH_MAX];
Linus Torvalds453ec4b2006-05-16 19:02:14 -070059};
60
Linus Torvalds3c6a3702006-05-19 16:07:51 -070061extern int common_prefix(const char **pathspec);
Junio C Hamanoe813d502006-12-25 03:09:52 -080062
63#define MATCHED_RECURSIVELY 1
64#define MATCHED_FNMATCH 2
65#define MATCHED_EXACTLY 3
Linus Torvalds3c6a3702006-05-19 16:07:51 -070066extern int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen);
67
Linus Torvalds9fc42d62007-03-30 20:39:30 -070068extern int read_directory(struct dir_struct *, const char *path, const char *base, int baselen, const char **pathspec);
Junio C Hamanof8a9d422006-12-04 16:00:46 -080069
Linus Torvalds453ec4b2006-05-16 19:02:14 -070070extern int excluded(struct dir_struct *, const char *);
71extern void add_excludes_from_file(struct dir_struct *, const char *fname);
72extern void add_exclude(const char *string, const char *base,
73 int baselen, struct exclude_list *which);
Jeff Kingc91f0d92006-09-08 04:05:34 -040074extern int file_exists(const char *);
Junio C Hamano4d06f8a2006-12-29 11:01:31 -080075extern struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len);
Linus Torvalds453ec4b2006-05-16 19:02:14 -070076
Johannes Schindeline6636742007-08-01 01:29:17 +010077extern char *get_relative_cwd(char *buffer, int size, const char *dir);
78extern int is_inside_dir(const char *dir);
79
Junio C Hamano039bc642007-11-14 00:05:00 -080080extern void setup_standard_excludes(struct dir_struct *dir);
Johannes Schindelin7155b722007-09-28 16:28:54 +010081extern int remove_dir_recursively(struct strbuf *path, int only_empty);
82
Linus Torvalds453ec4b2006-05-16 19:02:14 -070083#endif