зеркало из https://github.com/microsoft/git.git
dir.c: replace is_path_excluded with now equivalent is_excluded API
Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
95c6f27164
Коммит
b07bc8c8c3
|
@ -444,9 +444,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
|
||||||
|
|
||||||
if (pathspec) {
|
if (pathspec) {
|
||||||
int i;
|
int i;
|
||||||
struct path_exclude_check check;
|
|
||||||
|
|
||||||
path_exclude_check_init(&check, &dir);
|
|
||||||
if (!seen)
|
if (!seen)
|
||||||
seen = find_pathspecs_matching_against_index(pathspec);
|
seen = find_pathspecs_matching_against_index(pathspec);
|
||||||
for (i = 0; pathspec[i]; i++) {
|
for (i = 0; pathspec[i]; i++) {
|
||||||
|
@ -454,7 +452,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
|
||||||
&& !file_exists(pathspec[i])) {
|
&& !file_exists(pathspec[i])) {
|
||||||
if (ignore_missing) {
|
if (ignore_missing) {
|
||||||
int dtype = DT_UNKNOWN;
|
int dtype = DT_UNKNOWN;
|
||||||
if (is_path_excluded(&check, pathspec[i], -1, &dtype))
|
if (is_excluded(&dir, pathspec[i], &dtype))
|
||||||
dir_add_ignored(&dir, pathspec[i], strlen(pathspec[i]));
|
dir_add_ignored(&dir, pathspec[i], strlen(pathspec[i]));
|
||||||
} else
|
} else
|
||||||
die(_("pathspec '%s' did not match any files"),
|
die(_("pathspec '%s' did not match any files"),
|
||||||
|
@ -462,7 +460,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(seen);
|
free(seen);
|
||||||
path_exclude_check_clear(&check);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
plug_bulk_checkin();
|
plug_bulk_checkin();
|
||||||
|
|
|
@ -59,7 +59,6 @@ static int check_ignore(const char *prefix, const char **pathspec)
|
||||||
const char *path, *full_path;
|
const char *path, *full_path;
|
||||||
char *seen;
|
char *seen;
|
||||||
int num_ignored = 0, dtype = DT_UNKNOWN, i;
|
int num_ignored = 0, dtype = DT_UNKNOWN, i;
|
||||||
struct path_exclude_check check;
|
|
||||||
struct exclude *exclude;
|
struct exclude *exclude;
|
||||||
|
|
||||||
/* read_cache() is only necessary so we can watch out for submodules. */
|
/* read_cache() is only necessary so we can watch out for submodules. */
|
||||||
|
@ -76,7 +75,6 @@ static int check_ignore(const char *prefix, const char **pathspec)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
path_exclude_check_init(&check, &dir);
|
|
||||||
/*
|
/*
|
||||||
* look for pathspecs matching entries in the index, since these
|
* look for pathspecs matching entries in the index, since these
|
||||||
* should not be ignored, in order to be consistent with
|
* should not be ignored, in order to be consistent with
|
||||||
|
@ -90,8 +88,7 @@ static int check_ignore(const char *prefix, const char **pathspec)
|
||||||
full_path = check_path_for_gitlink(full_path);
|
full_path = check_path_for_gitlink(full_path);
|
||||||
die_if_path_beyond_symlink(full_path, prefix);
|
die_if_path_beyond_symlink(full_path, prefix);
|
||||||
if (!seen[i]) {
|
if (!seen[i]) {
|
||||||
exclude = last_exclude_matching_path(&check, full_path,
|
exclude = last_exclude_matching(&dir, full_path, &dtype);
|
||||||
-1, &dtype);
|
|
||||||
if (exclude) {
|
if (exclude) {
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
output_exclude(path, exclude);
|
output_exclude(path, exclude);
|
||||||
|
@ -101,7 +98,6 @@ static int check_ignore(const char *prefix, const char **pathspec)
|
||||||
}
|
}
|
||||||
free(seen);
|
free(seen);
|
||||||
clear_directory(&dir);
|
clear_directory(&dir);
|
||||||
path_exclude_check_clear(&check);
|
|
||||||
|
|
||||||
return num_ignored;
|
return num_ignored;
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,19 +201,15 @@ static void show_ru_info(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ce_excluded(struct path_exclude_check *check, struct cache_entry *ce)
|
static int ce_excluded(struct dir_struct *dir, struct cache_entry *ce)
|
||||||
{
|
{
|
||||||
int dtype = ce_to_dtype(ce);
|
int dtype = ce_to_dtype(ce);
|
||||||
return is_path_excluded(check, ce->name, ce_namelen(ce), &dtype);
|
return is_excluded(dir, ce->name, &dtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_files(struct dir_struct *dir)
|
static void show_files(struct dir_struct *dir)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct path_exclude_check check;
|
|
||||||
|
|
||||||
if ((dir->flags & DIR_SHOW_IGNORED))
|
|
||||||
path_exclude_check_init(&check, dir);
|
|
||||||
|
|
||||||
/* For cached/deleted files we don't need to even do the readdir */
|
/* For cached/deleted files we don't need to even do the readdir */
|
||||||
if (show_others || show_killed) {
|
if (show_others || show_killed) {
|
||||||
|
@ -227,7 +223,7 @@ static void show_files(struct dir_struct *dir)
|
||||||
for (i = 0; i < active_nr; i++) {
|
for (i = 0; i < active_nr; i++) {
|
||||||
struct cache_entry *ce = active_cache[i];
|
struct cache_entry *ce = active_cache[i];
|
||||||
if ((dir->flags & DIR_SHOW_IGNORED) &&
|
if ((dir->flags & DIR_SHOW_IGNORED) &&
|
||||||
!ce_excluded(&check, ce))
|
!ce_excluded(dir, ce))
|
||||||
continue;
|
continue;
|
||||||
if (show_unmerged && !ce_stage(ce))
|
if (show_unmerged && !ce_stage(ce))
|
||||||
continue;
|
continue;
|
||||||
|
@ -243,7 +239,7 @@ static void show_files(struct dir_struct *dir)
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int err;
|
int err;
|
||||||
if ((dir->flags & DIR_SHOW_IGNORED) &&
|
if ((dir->flags & DIR_SHOW_IGNORED) &&
|
||||||
!ce_excluded(&check, ce))
|
!ce_excluded(dir, ce))
|
||||||
continue;
|
continue;
|
||||||
if (ce->ce_flags & CE_UPDATE)
|
if (ce->ce_flags & CE_UPDATE)
|
||||||
continue;
|
continue;
|
||||||
|
@ -256,9 +252,6 @@ static void show_files(struct dir_struct *dir)
|
||||||
show_ce_entry(tag_modified, ce);
|
show_ce_entry(tag_modified, ce);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dir->flags & DIR_SHOW_IGNORED))
|
|
||||||
path_exclude_check_clear(&check);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
77
dir.c
77
dir.c
|
@ -843,7 +843,7 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
|
||||||
* Returns the exclude_list element which matched, or NULL for
|
* Returns the exclude_list element which matched, or NULL for
|
||||||
* undecided.
|
* undecided.
|
||||||
*/
|
*/
|
||||||
static struct exclude *last_exclude_matching(struct dir_struct *dir,
|
struct exclude *last_exclude_matching(struct dir_struct *dir,
|
||||||
const char *pathname,
|
const char *pathname,
|
||||||
int *dtype_p)
|
int *dtype_p)
|
||||||
{
|
{
|
||||||
|
@ -865,7 +865,7 @@ static struct exclude *last_exclude_matching(struct dir_struct *dir,
|
||||||
* scans all exclude lists to determine whether pathname is excluded.
|
* scans all exclude lists to determine whether pathname is excluded.
|
||||||
* Returns 1 if true, otherwise 0.
|
* Returns 1 if true, otherwise 0.
|
||||||
*/
|
*/
|
||||||
static int is_excluded(struct dir_struct *dir, const char *pathname, int *dtype_p)
|
int is_excluded(struct dir_struct *dir, const char *pathname, int *dtype_p)
|
||||||
{
|
{
|
||||||
struct exclude *exclude =
|
struct exclude *exclude =
|
||||||
last_exclude_matching(dir, pathname, dtype_p);
|
last_exclude_matching(dir, pathname, dtype_p);
|
||||||
|
@ -874,47 +874,6 @@ static int is_excluded(struct dir_struct *dir, const char *pathname, int *dtype_
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void path_exclude_check_init(struct path_exclude_check *check,
|
|
||||||
struct dir_struct *dir)
|
|
||||||
{
|
|
||||||
check->dir = dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
void path_exclude_check_clear(struct path_exclude_check *check)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* For each subdirectory in name, starting with the top-most, checks
|
|
||||||
* to see if that subdirectory is excluded, and if so, returns the
|
|
||||||
* corresponding exclude structure. Otherwise, checks whether name
|
|
||||||
* itself (which is presumably a file) is excluded.
|
|
||||||
*
|
|
||||||
* A path to a directory known to be excluded is left in check->path to
|
|
||||||
* optimize for repeated checks for files in the same excluded directory.
|
|
||||||
*/
|
|
||||||
struct exclude *last_exclude_matching_path(struct path_exclude_check *check,
|
|
||||||
const char *name, int namelen,
|
|
||||||
int *dtype)
|
|
||||||
{
|
|
||||||
return last_exclude_matching(check->dir, name, dtype);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Is this name excluded? This is for a caller like show_files() that
|
|
||||||
* do not honor directory hierarchy and iterate through paths that are
|
|
||||||
* possibly in an ignored directory.
|
|
||||||
*/
|
|
||||||
int is_path_excluded(struct path_exclude_check *check,
|
|
||||||
const char *name, int namelen, int *dtype)
|
|
||||||
{
|
|
||||||
struct exclude *exclude =
|
|
||||||
last_exclude_matching_path(check, name, namelen, dtype);
|
|
||||||
if (exclude)
|
|
||||||
return exclude->flags & EXC_FLAG_NEGATIVE ? 0 : 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct dir_entry *dir_entry_new(const char *pathname, int len)
|
static struct dir_entry *dir_entry_new(const char *pathname, int len)
|
||||||
{
|
{
|
||||||
struct dir_entry *ent;
|
struct dir_entry *ent;
|
||||||
|
@ -1086,15 +1045,6 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
|
||||||
|
|
||||||
/* This is the "show_other_directories" case */
|
/* This is the "show_other_directories" case */
|
||||||
|
|
||||||
/* might be a sub directory in an excluded directory */
|
|
||||||
if (!exclude) {
|
|
||||||
struct path_exclude_check check;
|
|
||||||
int dt = DT_DIR;
|
|
||||||
path_exclude_check_init(&check, dir);
|
|
||||||
exclude = is_path_excluded(&check, dirname, len, &dt);
|
|
||||||
path_exclude_check_clear(&check);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We are looking for ignored files and our directory is not ignored,
|
* We are looking for ignored files and our directory is not ignored,
|
||||||
* check if it contains untracked files (i.e. is listed as untracked)
|
* check if it contains untracked files (i.e. is listed as untracked)
|
||||||
|
@ -1129,27 +1079,13 @@ static enum directory_treatment treat_directory(struct dir_struct *dir,
|
||||||
*
|
*
|
||||||
* Return 1 for exclude, 0 for include.
|
* Return 1 for exclude, 0 for include.
|
||||||
*/
|
*/
|
||||||
static int treat_file(struct dir_struct *dir, struct strbuf *path, int exclude, int *dtype)
|
static int treat_file(struct dir_struct *dir, struct strbuf *path, int exclude)
|
||||||
{
|
{
|
||||||
struct path_exclude_check check;
|
|
||||||
int exclude_file = 0;
|
|
||||||
|
|
||||||
/* Always exclude indexed files */
|
/* Always exclude indexed files */
|
||||||
if (index_name_exists(&the_index, path->buf, path->len, ignore_case))
|
if (index_name_exists(&the_index, path->buf, path->len, ignore_case))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (exclude)
|
return exclude == !(dir->flags & DIR_SHOW_IGNORED);
|
||||||
exclude_file = !(dir->flags & DIR_SHOW_IGNORED);
|
|
||||||
else if (dir->flags & DIR_SHOW_IGNORED) {
|
|
||||||
path_exclude_check_init(&check, dir);
|
|
||||||
|
|
||||||
if (!is_path_excluded(&check, path->buf, path->len, dtype))
|
|
||||||
exclude_file = 1;
|
|
||||||
|
|
||||||
path_exclude_check_clear(&check);
|
|
||||||
}
|
|
||||||
|
|
||||||
return exclude_file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1306,13 +1242,10 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
|
||||||
break;
|
break;
|
||||||
case DT_REG:
|
case DT_REG:
|
||||||
case DT_LNK:
|
case DT_LNK:
|
||||||
switch (treat_file(dir, path, exclude, &dtype)) {
|
if (treat_file(dir, path, exclude))
|
||||||
case 1:
|
|
||||||
return path_ignored;
|
return path_ignored;
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return path_handled;
|
return path_handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
dir.h
16
dir.h
|
@ -151,20 +151,10 @@ extern int match_pathname(const char *, int,
|
||||||
const char *, int,
|
const char *, int,
|
||||||
const char *, int, int, int);
|
const char *, int, int, int);
|
||||||
|
|
||||||
/*
|
extern struct exclude *last_exclude_matching(struct dir_struct *dir,
|
||||||
* The is_excluded() API is meant for callers that check each level of leading
|
const char *name, int *dtype);
|
||||||
* directory hierarchies with is_excluded() to avoid recursing into excluded
|
|
||||||
* directories. Callers that do not do so should use this API instead.
|
|
||||||
*/
|
|
||||||
struct path_exclude_check {
|
|
||||||
struct dir_struct *dir;
|
|
||||||
};
|
|
||||||
extern void path_exclude_check_init(struct path_exclude_check *, struct dir_struct *);
|
|
||||||
extern void path_exclude_check_clear(struct path_exclude_check *);
|
|
||||||
extern struct exclude *last_exclude_matching_path(struct path_exclude_check *, const char *,
|
|
||||||
int namelen, int *dtype);
|
|
||||||
extern int is_path_excluded(struct path_exclude_check *, const char *, int namelen, int *dtype);
|
|
||||||
|
|
||||||
|
extern int is_excluded(struct dir_struct *dir, const char *name, int *dtype);
|
||||||
|
|
||||||
extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
|
extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
|
||||||
int group_type, const char *src);
|
int group_type, const char *src);
|
||||||
|
|
|
@ -1026,10 +1026,6 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
|
||||||
o->el = ⪙
|
o->el = ⪙
|
||||||
}
|
}
|
||||||
|
|
||||||
if (o->dir) {
|
|
||||||
o->path_exclude_check = xmalloc(sizeof(struct path_exclude_check));
|
|
||||||
path_exclude_check_init(o->path_exclude_check, o->dir);
|
|
||||||
}
|
|
||||||
memset(&o->result, 0, sizeof(o->result));
|
memset(&o->result, 0, sizeof(o->result));
|
||||||
o->result.initialized = 1;
|
o->result.initialized = 1;
|
||||||
o->result.timestamp.sec = o->src_index->timestamp.sec;
|
o->result.timestamp.sec = o->src_index->timestamp.sec;
|
||||||
|
@ -1155,10 +1151,6 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
|
||||||
|
|
||||||
done:
|
done:
|
||||||
clear_exclude_list(&el);
|
clear_exclude_list(&el);
|
||||||
if (o->path_exclude_check) {
|
|
||||||
path_exclude_check_clear(o->path_exclude_check);
|
|
||||||
free(o->path_exclude_check);
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
return_failed:
|
return_failed:
|
||||||
|
@ -1375,7 +1367,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (o->dir &&
|
if (o->dir &&
|
||||||
is_path_excluded(o->path_exclude_check, name, -1, &dtype))
|
is_excluded(o->dir, name, &dtype))
|
||||||
/*
|
/*
|
||||||
* ce->name is explicitly excluded, so it is Ok to
|
* ce->name is explicitly excluded, so it is Ok to
|
||||||
* overwrite it.
|
* overwrite it.
|
||||||
|
|
|
@ -52,7 +52,6 @@ struct unpack_trees_options {
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
int cache_bottom;
|
int cache_bottom;
|
||||||
struct dir_struct *dir;
|
struct dir_struct *dir;
|
||||||
struct path_exclude_check *path_exclude_check;
|
|
||||||
struct pathspec *pathspec;
|
struct pathspec *pathspec;
|
||||||
merge_fn_t fn;
|
merge_fn_t fn;
|
||||||
const char *msgs[NB_UNPACK_TREES_ERROR_TYPES];
|
const char *msgs[NB_UNPACK_TREES_ERROR_TYPES];
|
||||||
|
|
Загрузка…
Ссылка в новой задаче