blob: 2df15defb6720a742282f24721233c4816deceb6 [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
Junio C Hamanod6b8fc32008-01-31 01:17:48 -080012#define EXC_FLAG_MUSTBEDIR 8
Lars Knoll68492fc2007-10-28 21:27:13 +010013
Linus Torvalds453ec4b2006-05-16 19:02:14 -070014struct exclude_list {
15 int nr;
16 int alloc;
17 struct exclude {
18 const char *pattern;
Lars Knoll68492fc2007-10-28 21:27:13 +010019 int patternlen;
Linus Torvalds453ec4b2006-05-16 19:02:14 -070020 const char *base;
21 int baselen;
Lars Knoll68492fc2007-10-28 21:27:13 +010022 int to_exclude;
23 int flags;
Linus Torvalds453ec4b2006-05-16 19:02:14 -070024 } **excludes;
25};
26
Junio C Hamano63d285c2007-11-29 02:17:44 -080027struct exclude_stack {
28 struct exclude_stack *prev;
29 char *filebuf;
30 int baselen;
31 int exclude_ix;
32};
33
Linus Torvalds453ec4b2006-05-16 19:02:14 -070034struct dir_struct {
35 int nr, alloc;
Jeff King2abd31b2007-06-11 09:39:50 -040036 int ignored_nr, ignored_alloc;
Junio C Hamanoc8897632006-12-29 10:08:19 -080037 unsigned int show_ignored:1,
Linus Torvalds453ec4b2006-05-16 19:02:14 -070038 show_other_directories:1,
Linus Torvalds09595252007-04-11 14:49:44 -070039 hide_empty_directories:1,
Jeff King2abd31b2007-06-11 09:39:50 -040040 no_gitlinks:1,
41 collect_ignored:1;
Linus Torvalds453ec4b2006-05-16 19:02:14 -070042 struct dir_entry **entries;
Jeff King2abd31b2007-06-11 09:39:50 -040043 struct dir_entry **ignored;
Linus Torvalds453ec4b2006-05-16 19:02:14 -070044
45 /* Exclude info */
46 const char *exclude_per_dir;
47 struct exclude_list exclude_list[3];
Junio C Hamano63d285c2007-11-29 02:17:44 -080048 /*
49 * We maintain three exclude pattern lists:
50 * EXC_CMDL lists patterns explicitly given on the command line.
51 * EXC_DIRS lists patterns obtained from per-directory ignore files.
52 * EXC_FILE lists patterns from fallback ignore files.
53 */
54#define EXC_CMDL 0
55#define EXC_DIRS 1
56#define EXC_FILE 2
57
58 struct exclude_stack *exclude_stack;
59 char basebuf[PATH_MAX];
Linus Torvalds453ec4b2006-05-16 19:02:14 -070060};
61
Linus Torvalds3c6a3702006-05-19 16:07:51 -070062extern int common_prefix(const char **pathspec);
Junio C Hamanoe813d502006-12-25 03:09:52 -080063
64#define MATCHED_RECURSIVELY 1
65#define MATCHED_FNMATCH 2
66#define MATCHED_EXACTLY 3
Linus Torvalds3c6a3702006-05-19 16:07:51 -070067extern int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen);
68
Linus Torvalds9fc42d62007-03-30 20:39:30 -070069extern 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 -080070
Junio C Hamano6831a882008-01-31 20:23:25 -080071extern int excluded(struct dir_struct *, const char *, int *);
Linus Torvalds453ec4b2006-05-16 19:02:14 -070072extern void add_excludes_from_file(struct dir_struct *, const char *fname);
73extern void add_exclude(const char *string, const char *base,
74 int baselen, struct exclude_list *which);
Jeff Kingc91f0d92006-09-08 04:05:34 -040075extern int file_exists(const char *);
Junio C Hamano4d06f8a2006-12-29 11:01:31 -080076extern struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathname, int len);
Linus Torvalds453ec4b2006-05-16 19:02:14 -070077
Johannes Schindeline6636742007-08-01 01:29:17 +010078extern char *get_relative_cwd(char *buffer, int size, const char *dir);
79extern int is_inside_dir(const char *dir);
80
Junio C Hamano039bc642007-11-14 00:05:00 -080081extern void setup_standard_excludes(struct dir_struct *dir);
Johannes Schindelin7155b722007-09-28 16:28:54 +010082extern int remove_dir_recursively(struct strbuf *path, int only_empty);
83
Linus Torvalds453ec4b2006-05-16 19:02:14 -070084#endif