2006-05-17 10:02:14 +08:00
|
|
|
#ifndef DIR_H
|
|
|
|
#define DIR_H
|
|
|
|
|
2012-12-27 10:32:21 +08:00
|
|
|
/* See Documentation/technical/api-directory-listing.txt */
|
|
|
|
|
2012-06-02 02:28:00 +08:00
|
|
|
#include "strbuf.h"
|
|
|
|
|
2006-05-17 10:02:14 +08:00
|
|
|
struct dir_entry {
|
builtin-add: simplify (and increase accuracy of) exclude handling
Previously, the code would always set up the excludes, and then manually
pick through the pathspec we were given, assuming that non-added but
existing paths were just ignored. This was mostly correct, but would
erroneously mark a totally empty directory as 'ignored'.
Instead, we now use the collect_ignored option of dir_struct, which
unambiguously tells us whether a path was ignored. This simplifies the
code, and means empty directories are now just not mentioned at all.
Furthermore, we now conditionally ask dir_struct to respect excludes,
depending on whether the '-f' flag has been set. This means we don't have
to pick through the result, checking for an 'ignored' flag; ignored entries
were either added or not in the first place.
We can safely get rid of the special 'ignored' flags to dir_entry, which
were not used anywhere else.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-06-13 05:42:14 +08:00
|
|
|
unsigned int len;
|
2006-05-17 10:02:14 +08:00
|
|
|
char name[FLEX_ARRAY]; /* more */
|
|
|
|
};
|
|
|
|
|
2007-10-29 04:27:13 +08:00
|
|
|
#define EXC_FLAG_NODIR 1
|
|
|
|
#define EXC_FLAG_ENDSWITH 4
|
2008-01-31 17:17:48 +08:00
|
|
|
#define EXC_FLAG_MUSTBEDIR 8
|
2012-10-15 14:24:38 +08:00
|
|
|
#define EXC_FLAG_NEGATIVE 16
|
2007-10-29 04:27:13 +08:00
|
|
|
|
2012-12-27 10:32:21 +08:00
|
|
|
/*
|
2013-01-07 00:58:03 +08:00
|
|
|
* Each excludes file will be parsed into a fresh exclude_list which
|
|
|
|
* is appended to the relevant exclude_list_group (either EXC_DIRS or
|
|
|
|
* EXC_FILE). An exclude_list within the EXC_CMDL exclude_list_group
|
|
|
|
* can also be used to represent the list of --exclude values passed
|
|
|
|
* via CLI args.
|
2012-12-27 10:32:21 +08:00
|
|
|
*/
|
2006-05-17 10:02:14 +08:00
|
|
|
struct exclude_list {
|
|
|
|
int nr;
|
|
|
|
int alloc;
|
2013-01-07 00:58:04 +08:00
|
|
|
|
2013-01-07 00:58:03 +08:00
|
|
|
/* remember pointer to exclude file contents so we can free() */
|
|
|
|
char *filebuf;
|
|
|
|
|
2013-01-07 00:58:04 +08:00
|
|
|
/* origin of list, e.g. path to filename, or descriptive string */
|
|
|
|
const char *src;
|
|
|
|
|
2006-05-17 10:02:14 +08:00
|
|
|
struct exclude {
|
2013-01-07 00:58:04 +08:00
|
|
|
/*
|
|
|
|
* This allows callers of last_exclude_matching() etc.
|
|
|
|
* to determine the origin of the matching pattern.
|
|
|
|
*/
|
|
|
|
struct exclude_list *el;
|
|
|
|
|
2006-05-17 10:02:14 +08:00
|
|
|
const char *pattern;
|
2007-10-29 04:27:13 +08:00
|
|
|
int patternlen;
|
2012-06-07 15:53:36 +08:00
|
|
|
int nowildcardlen;
|
2006-05-17 10:02:14 +08:00
|
|
|
const char *base;
|
|
|
|
int baselen;
|
2007-10-29 04:27:13 +08:00
|
|
|
int flags;
|
2013-01-07 00:58:04 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Counting starts from 1 for line numbers in ignore files,
|
|
|
|
* and from -1 decrementing for patterns from CLI args.
|
|
|
|
*/
|
|
|
|
int srcpos;
|
2006-05-17 10:02:14 +08:00
|
|
|
} **excludes;
|
|
|
|
};
|
|
|
|
|
2012-12-27 10:32:21 +08:00
|
|
|
/*
|
|
|
|
* The contents of the per-directory exclude files are lazily read on
|
|
|
|
* demand and then cached in memory, one per exclude_stack struct, in
|
|
|
|
* order to avoid opening and parsing each one every time that
|
|
|
|
* directory is traversed.
|
|
|
|
*/
|
2007-11-29 18:17:44 +08:00
|
|
|
struct exclude_stack {
|
2012-12-27 10:32:21 +08:00
|
|
|
struct exclude_stack *prev; /* the struct exclude_stack for the parent directory */
|
2007-11-29 18:17:44 +08:00
|
|
|
int baselen;
|
2013-01-07 00:58:03 +08:00
|
|
|
int exclude_ix; /* index of exclude_list within EXC_DIRS exclude_list_group */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct exclude_list_group {
|
|
|
|
int nr, alloc;
|
|
|
|
struct exclude_list *el;
|
2007-11-29 18:17:44 +08:00
|
|
|
};
|
|
|
|
|
2006-05-17 10:02:14 +08:00
|
|
|
struct dir_struct {
|
|
|
|
int nr, alloc;
|
2007-06-11 21:39:50 +08:00
|
|
|
int ignored_nr, ignored_alloc;
|
2009-02-16 20:20:25 +08:00
|
|
|
enum {
|
|
|
|
DIR_SHOW_IGNORED = 1<<0,
|
|
|
|
DIR_SHOW_OTHER_DIRECTORIES = 1<<1,
|
|
|
|
DIR_HIDE_EMPTY_DIRECTORIES = 1<<2,
|
|
|
|
DIR_NO_GITLINKS = 1<<3,
|
|
|
|
DIR_COLLECT_IGNORED = 1<<4
|
|
|
|
} flags;
|
2006-05-17 10:02:14 +08:00
|
|
|
struct dir_entry **entries;
|
2007-06-11 21:39:50 +08:00
|
|
|
struct dir_entry **ignored;
|
2006-05-17 10:02:14 +08:00
|
|
|
|
|
|
|
/* Exclude info */
|
|
|
|
const char *exclude_per_dir;
|
2013-01-07 00:58:03 +08:00
|
|
|
|
2007-11-29 18:17:44 +08:00
|
|
|
/*
|
2013-01-07 00:58:03 +08:00
|
|
|
* We maintain three groups of exclude pattern lists:
|
|
|
|
*
|
2007-11-29 18:17:44 +08:00
|
|
|
* EXC_CMDL lists patterns explicitly given on the command line.
|
|
|
|
* EXC_DIRS lists patterns obtained from per-directory ignore files.
|
2013-01-07 00:58:03 +08:00
|
|
|
* EXC_FILE lists patterns from fallback ignore files, e.g.
|
|
|
|
* - .git/info/exclude
|
|
|
|
* - core.excludesfile
|
|
|
|
*
|
|
|
|
* Each group contains multiple exclude lists, a single list
|
|
|
|
* per source.
|
2007-11-29 18:17:44 +08:00
|
|
|
*/
|
|
|
|
#define EXC_CMDL 0
|
|
|
|
#define EXC_DIRS 1
|
|
|
|
#define EXC_FILE 2
|
2013-01-07 00:58:03 +08:00
|
|
|
struct exclude_list_group exclude_list_group[3];
|
2007-11-29 18:17:44 +08:00
|
|
|
|
2012-12-27 10:32:21 +08:00
|
|
|
/*
|
|
|
|
* Temporary variables which are used during loading of the
|
|
|
|
* per-directory exclude lists.
|
|
|
|
*
|
|
|
|
* exclude_stack points to the top of the exclude_stack, and
|
|
|
|
* basebuf contains the full path to the current
|
|
|
|
* (sub)directory in the traversal.
|
|
|
|
*/
|
2007-11-29 18:17:44 +08:00
|
|
|
struct exclude_stack *exclude_stack;
|
|
|
|
char basebuf[PATH_MAX];
|
2006-05-17 10:02:14 +08:00
|
|
|
};
|
|
|
|
|
2006-12-25 19:09:52 +08:00
|
|
|
#define MATCHED_RECURSIVELY 1
|
|
|
|
#define MATCHED_FNMATCH 2
|
|
|
|
#define MATCHED_EXACTLY 3
|
2011-09-04 18:42:01 +08:00
|
|
|
extern char *common_prefix(const char **pathspec);
|
2006-05-20 07:07:51 +08:00
|
|
|
extern int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen);
|
2010-12-15 23:02:48 +08:00
|
|
|
extern int match_pathspec_depth(const struct pathspec *pathspec,
|
|
|
|
const char *name, int namelen,
|
|
|
|
int prefix, char *seen);
|
2010-12-15 23:02:44 +08:00
|
|
|
extern int within_depth(const char *name, int namelen, int depth, int max_depth);
|
2006-05-20 07:07:51 +08:00
|
|
|
|
2009-05-15 04:22:36 +08:00
|
|
|
extern int fill_directory(struct dir_struct *dir, const char **pathspec);
|
2009-07-09 10:24:39 +08:00
|
|
|
extern int read_directory(struct dir_struct *, const char *path, int len, const char **pathspec);
|
2006-12-05 08:00:46 +08:00
|
|
|
|
2012-12-27 10:32:24 +08:00
|
|
|
extern int is_excluded_from_list(const char *pathname, int pathlen, const char *basename,
|
|
|
|
int *dtype, struct exclude_list *el);
|
2010-07-10 06:18:38 +08:00
|
|
|
struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len);
|
2012-06-02 02:28:00 +08:00
|
|
|
|
2012-10-15 14:24:39 +08:00
|
|
|
/*
|
|
|
|
* these implement the matching logic for dir.c:excluded_from_list and
|
|
|
|
* attr.c:path_matches()
|
|
|
|
*/
|
|
|
|
extern int match_basename(const char *, int,
|
|
|
|
const char *, int, int, int);
|
|
|
|
extern int match_pathname(const char *, int,
|
|
|
|
const char *, int,
|
|
|
|
const char *, int, int, int);
|
|
|
|
|
2012-06-02 02:28:00 +08:00
|
|
|
/*
|
2012-12-27 10:32:25 +08:00
|
|
|
* The is_excluded() API is meant for callers that check each level of leading
|
|
|
|
* directory hierarchies with is_excluded() to avoid recursing into excluded
|
2012-06-02 02:28:00 +08:00
|
|
|
* directories. Callers that do not do so should use this API instead.
|
|
|
|
*/
|
|
|
|
struct path_exclude_check {
|
|
|
|
struct dir_struct *dir;
|
2012-12-27 10:32:28 +08:00
|
|
|
struct exclude *exclude;
|
2012-06-02 02:28:00 +08:00
|
|
|
struct strbuf path;
|
|
|
|
};
|
|
|
|
extern void path_exclude_check_init(struct path_exclude_check *, struct dir_struct *);
|
|
|
|
extern void path_exclude_check_clear(struct path_exclude_check *);
|
2012-12-27 10:32:28 +08:00
|
|
|
extern struct exclude *last_exclude_matching_path(struct path_exclude_check *, const char *,
|
|
|
|
int namelen, int *dtype);
|
2012-12-27 10:32:23 +08:00
|
|
|
extern int is_path_excluded(struct path_exclude_check *, const char *, int namelen, int *dtype);
|
2012-06-06 12:17:52 +08:00
|
|
|
|
2012-06-02 02:28:00 +08:00
|
|
|
|
2013-01-07 00:58:04 +08:00
|
|
|
extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
|
|
|
|
int group_type, const char *src);
|
2009-08-20 21:47:04 +08:00
|
|
|
extern int add_excludes_from_file_to_list(const char *fname, const char *base, int baselen,
|
2013-01-07 00:58:03 +08:00
|
|
|
struct exclude_list *el, int check_index);
|
2006-05-17 10:02:14 +08:00
|
|
|
extern void add_excludes_from_file(struct dir_struct *, const char *fname);
|
2012-10-15 14:24:39 +08:00
|
|
|
extern void parse_exclude_pattern(const char **string, int *patternlen, int *flags, int *nowildcardlen);
|
2006-05-17 10:02:14 +08:00
|
|
|
extern void add_exclude(const char *string, const char *base,
|
2013-01-07 00:58:04 +08:00
|
|
|
int baselen, struct exclude_list *el, int srcpos);
|
2012-12-27 10:32:29 +08:00
|
|
|
extern void clear_exclude_list(struct exclude_list *el);
|
2013-01-07 00:58:05 +08:00
|
|
|
extern void clear_directory(struct dir_struct *dir);
|
2006-09-08 16:05:34 +08:00
|
|
|
extern int file_exists(const char *);
|
2006-05-17 10:02:14 +08:00
|
|
|
|
2007-08-01 08:29:17 +08:00
|
|
|
extern int is_inside_dir(const char *dir);
|
2011-03-26 17:04:24 +08:00
|
|
|
extern int dir_inside_of(const char *subdir, const char *dir);
|
2007-08-01 08:29:17 +08:00
|
|
|
|
2009-01-10 20:07:50 +08:00
|
|
|
static inline int is_dot_or_dotdot(const char *name)
|
|
|
|
{
|
|
|
|
return (name[0] == '.' &&
|
|
|
|
(name[1] == '\0' ||
|
|
|
|
(name[1] == '.' && name[2] == '\0')));
|
|
|
|
}
|
|
|
|
|
2009-01-11 20:19:12 +08:00
|
|
|
extern int is_empty_dir(const char *dir);
|
|
|
|
|
core.excludesfile clean-up
There are inconsistencies in the way commands currently handle
the core.excludesfile configuration variable. The problem is
the variable is too new to be noticed by anything other than
git-add and git-status.
* git-ls-files does not notice any of the "ignore" files by
default, as it predates the standardized set of ignore files.
The calling scripts established the convention to use
.git/info/exclude, .gitignore, and later core.excludesfile.
* git-add and git-status know about it because they call
add_excludes_from_file() directly with their own notion of
which standard set of ignore files to use. This is just a
stupid duplication of code that need to be updated every time
the definition of the standard set of ignore files is
changed.
* git-read-tree takes --exclude-per-directory=<gitignore>,
not because the flexibility was needed. Again, this was
because the option predates the standardization of the ignore
files.
* git-merge-recursive uses hardcoded per-directory .gitignore
and nothing else. git-clean (scripted version) does not
honor core.* because its call to underlying ls-files does not
know about it. git-clean in C (parked in 'pu') doesn't either.
We probably could change git-ls-files to use the standard set
when no excludes are specified on the command line and ignore
processing was asked, or something like that, but that will be a
change in semantics and might break people's scripts in a subtle
way. I am somewhat reluctant to make such a change.
On the other hand, I think it makes perfect sense to fix
git-read-tree, git-merge-recursive and git-clean to follow the
same rule as other commands. I do not think of a valid use case
to give an exclude-per-directory that is nonstandard to
read-tree command, outside a "negative" test in the t1004 test
script.
This patch is the first step to untangle this mess.
The next step would be to teach read-tree, merge-recursive and
clean (in C) to use setup_standard_excludes().
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-14 16:05:00 +08:00
|
|
|
extern void setup_standard_excludes(struct dir_struct *dir);
|
2009-07-01 06:33:45 +08:00
|
|
|
|
|
|
|
#define REMOVE_DIR_EMPTY_ONLY 01
|
|
|
|
#define REMOVE_DIR_KEEP_NESTED_GIT 02
|
2012-03-15 22:58:54 +08:00
|
|
|
#define REMOVE_DIR_KEEP_TOPLEVEL 04
|
2009-07-01 06:33:45 +08:00
|
|
|
extern int remove_dir_recursively(struct strbuf *path, int flag);
|
2007-09-28 23:28:54 +08:00
|
|
|
|
2008-09-27 06:56:46 +08:00
|
|
|
/* tries to remove the path with empty directories along it, ignores ENOENT */
|
|
|
|
extern int remove_path(const char *path);
|
|
|
|
|
2010-10-03 17:56:41 +08:00
|
|
|
extern int strcmp_icase(const char *a, const char *b);
|
|
|
|
extern int strncmp_icase(const char *a, const char *b, size_t count);
|
|
|
|
extern int fnmatch_icase(const char *pattern, const char *string, int flags);
|
|
|
|
|
2006-05-17 10:02:14 +08:00
|
|
|
#endif
|