check-ignore: convert to use parse_pathspec
check-ignore (at least the test suite) seems to rely on the pattern order. PATHSPEC_KEEP_ORDER is introduced to explictly express this. The lack of PATHSPEC_MAXDEPTH_VALID is sufficient because it's the only flag that reorders pathspecs, but it's less obvious that way. Cc: Adam Spiers <git@adamspiers.org> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
f3e743a0d9
commit
931eab64ad
@ -64,37 +64,45 @@ static void output_exclude(const char *path, struct exclude *exclude)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int check_ignore(struct dir_struct *dir,
|
static int check_ignore(struct dir_struct *dir,
|
||||||
const char *prefix, const char **pathspec)
|
const char *prefix, int argc, const char **argv)
|
||||||
{
|
{
|
||||||
const char *path, *full_path;
|
const char *full_path;
|
||||||
char *seen;
|
char *seen;
|
||||||
int num_ignored = 0, dtype = DT_UNKNOWN, i;
|
int num_ignored = 0, dtype = DT_UNKNOWN, i;
|
||||||
struct exclude *exclude;
|
struct exclude *exclude;
|
||||||
|
struct pathspec pathspec;
|
||||||
|
|
||||||
if (!pathspec || !*pathspec) {
|
if (!argc) {
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
fprintf(stderr, "no pathspec given.\n");
|
fprintf(stderr, "no pathspec given.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check-ignore just needs paths. Magic beyond :/ is really
|
||||||
|
* irrelevant.
|
||||||
|
*/
|
||||||
|
parse_pathspec(&pathspec,
|
||||||
|
PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP,
|
||||||
|
PATHSPEC_SYMLINK_LEADING_PATH |
|
||||||
|
PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE |
|
||||||
|
PATHSPEC_KEEP_ORDER,
|
||||||
|
prefix, argv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
* 'git status', 'git add' etc.
|
* 'git status', 'git add' etc.
|
||||||
*/
|
*/
|
||||||
seen = find_pathspecs_matching_against_index(pathspec);
|
seen = find_pathspecs_matching_against_index(pathspec.raw);
|
||||||
for (i = 0; pathspec[i]; i++) {
|
for (i = 0; i < pathspec.nr; i++) {
|
||||||
path = pathspec[i];
|
full_path = pathspec.raw[i];
|
||||||
full_path = prefix_path(prefix, prefix
|
|
||||||
? strlen(prefix) : 0, path);
|
|
||||||
full_path = check_path_for_gitlink(full_path);
|
|
||||||
die_if_path_beyond_symlink(full_path, prefix);
|
|
||||||
exclude = NULL;
|
exclude = NULL;
|
||||||
if (!seen[i]) {
|
if (!seen[i]) {
|
||||||
exclude = last_exclude_matching(dir, full_path, &dtype);
|
exclude = last_exclude_matching(dir, full_path, &dtype);
|
||||||
}
|
}
|
||||||
if (!quiet && (exclude || show_non_matching))
|
if (!quiet && (exclude || show_non_matching))
|
||||||
output_exclude(path, exclude);
|
output_exclude(pathspec.items[i].original, exclude);
|
||||||
if (exclude)
|
if (exclude)
|
||||||
num_ignored++;
|
num_ignored++;
|
||||||
}
|
}
|
||||||
@ -120,7 +128,8 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix)
|
|||||||
strbuf_swap(&buf, &nbuf);
|
strbuf_swap(&buf, &nbuf);
|
||||||
}
|
}
|
||||||
pathspec[0] = buf.buf;
|
pathspec[0] = buf.buf;
|
||||||
num_ignored += check_ignore(dir, prefix, (const char **)pathspec);
|
num_ignored += check_ignore(dir, prefix,
|
||||||
|
1, (const char **)pathspec);
|
||||||
maybe_flush_or_die(stdout, "check-ignore to stdout");
|
maybe_flush_or_die(stdout, "check-ignore to stdout");
|
||||||
}
|
}
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
@ -166,7 +175,7 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)
|
|||||||
if (stdin_paths) {
|
if (stdin_paths) {
|
||||||
num_ignored = check_ignore_stdin_paths(&dir, prefix);
|
num_ignored = check_ignore_stdin_paths(&dir, prefix);
|
||||||
} else {
|
} else {
|
||||||
num_ignored = check_ignore(&dir, prefix, argv);
|
num_ignored = check_ignore(&dir, prefix, argc, argv);
|
||||||
maybe_flush_or_die(stdout, "ignore to stdout");
|
maybe_flush_or_die(stdout, "ignore to stdout");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,10 +370,14 @@ void parse_pathspec(struct pathspec *pathspec,
|
|||||||
pathspec->magic |= item[i].magic;
|
pathspec->magic |= item[i].magic;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pathspec->magic & PATHSPEC_MAXDEPTH)
|
|
||||||
|
if (pathspec->magic & PATHSPEC_MAXDEPTH) {
|
||||||
|
if (flags & PATHSPEC_KEEP_ORDER)
|
||||||
|
die("BUG: PATHSPEC_MAXDEPTH_VALID and PATHSPEC_KEEP_ORDER are incompatible");
|
||||||
qsort(pathspec->items, pathspec->nr,
|
qsort(pathspec->items, pathspec->nr,
|
||||||
sizeof(struct pathspec_item), pathspec_item_cmp);
|
sizeof(struct pathspec_item), pathspec_item_cmp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* N.B. get_pathspec() is deprecated in favor of the "struct pathspec"
|
* N.B. get_pathspec() is deprecated in favor of the "struct pathspec"
|
||||||
|
@ -51,6 +51,7 @@ struct pathspec {
|
|||||||
*/
|
*/
|
||||||
#define PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE (1<<5)
|
#define PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE (1<<5)
|
||||||
#define PATHSPEC_PREFIX_ORIGIN (1<<6)
|
#define PATHSPEC_PREFIX_ORIGIN (1<<6)
|
||||||
|
#define PATHSPEC_KEEP_ORDER (1<<7)
|
||||||
|
|
||||||
extern int init_pathspec(struct pathspec *, const char **);
|
extern int init_pathspec(struct pathspec *, const char **);
|
||||||
extern void parse_pathspec(struct pathspec *pathspec,
|
extern void parse_pathspec(struct pathspec *pathspec,
|
||||||
|
@ -432,7 +432,7 @@ test_expect_success_multi SYMLINKS 'symlink' ':: a/symlink' '
|
|||||||
|
|
||||||
test_expect_success_multi SYMLINKS 'beyond a symlink' '' '
|
test_expect_success_multi SYMLINKS 'beyond a symlink' '' '
|
||||||
test_check_ignore "a/symlink/foo" 128 &&
|
test_check_ignore "a/symlink/foo" 128 &&
|
||||||
test_stderr "fatal: '\''a/symlink/foo'\'' is beyond a symbolic link"
|
test_stderr "fatal: pathspec '\''a/symlink/foo'\'' is beyond a symbolic link"
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success_multi SYMLINKS 'beyond a symlink from subdirectory' '' '
|
test_expect_success_multi SYMLINKS 'beyond a symlink from subdirectory' '' '
|
||||||
@ -440,7 +440,7 @@ test_expect_success_multi SYMLINKS 'beyond a symlink from subdirectory' '' '
|
|||||||
cd a &&
|
cd a &&
|
||||||
test_check_ignore "symlink/foo" 128
|
test_check_ignore "symlink/foo" 128
|
||||||
) &&
|
) &&
|
||||||
test_stderr "fatal: '\''symlink/foo'\'' is beyond a symbolic link"
|
test_stderr "fatal: pathspec '\''symlink/foo'\'' is beyond a symbolic link"
|
||||||
'
|
'
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
@ -449,7 +449,7 @@ test_expect_success_multi SYMLINKS 'beyond a symlink from subdirectory' '' '
|
|||||||
|
|
||||||
test_expect_success_multi 'submodule' '' '
|
test_expect_success_multi 'submodule' '' '
|
||||||
test_check_ignore "a/submodule/one" 128 &&
|
test_check_ignore "a/submodule/one" 128 &&
|
||||||
test_stderr "fatal: Path '\''a/submodule/one'\'' is in submodule '\''a/submodule'\''"
|
test_stderr "fatal: Pathspec '\''a/submodule/one'\'' is in submodule '\''a/submodule'\''"
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success_multi 'submodule from subdirectory' '' '
|
test_expect_success_multi 'submodule from subdirectory' '' '
|
||||||
@ -457,7 +457,7 @@ test_expect_success_multi 'submodule from subdirectory' '' '
|
|||||||
cd a &&
|
cd a &&
|
||||||
test_check_ignore "submodule/one" 128
|
test_check_ignore "submodule/one" 128
|
||||||
) &&
|
) &&
|
||||||
test_stderr "fatal: Path '\''a/submodule/one'\'' is in submodule '\''a/submodule'\''"
|
test_stderr "fatal: Pathspec '\''submodule/one'\'' is in submodule '\''a/submodule'\''"
|
||||||
'
|
'
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
|
Reference in New Issue
Block a user