remove match_pathspec() in favor of match_pathspec_depth()

match_pathspec_depth was created to replace match_pathspec (see
61cf282 (pathspec: add match_pathspec_depth() - 2010-12-15). It took
more than two years, but the replacement finally happens :-)

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:
Nguyễn Thái Ngọc Duy
2013-07-14 15:36:00 +07:00
committed by Junio C Hamano
parent 9a08727443
commit 84b8b5d1fa
6 changed files with 25 additions and 140 deletions

View File

@ -195,23 +195,21 @@ int add_files_to_cache(const char *prefix,
}
#define WARN_IMPLICIT_DOT (1u << 0)
static char *prune_directory(struct dir_struct *dir, const char **pathspec,
static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
int prefix, unsigned flag)
{
char *seen;
int i, specs;
int i;
struct dir_entry **src, **dst;
for (specs = 0; pathspec[specs]; specs++)
/* nothing */;
seen = xcalloc(specs, 1);
seen = xcalloc(pathspec->nr, 1);
src = dst = dir->entries;
i = dir->nr;
while (--i >= 0) {
struct dir_entry *entry = *src++;
if (match_pathspec(pathspec, entry->name, entry->len,
prefix, seen))
if (match_pathspec_depth(pathspec, entry->name, entry->len,
prefix, seen))
*dst++ = entry;
else if (flag & WARN_IMPLICIT_DOT)
/*
@ -225,7 +223,7 @@ static char *prune_directory(struct dir_struct *dir, const char **pathspec,
warn_pathless_add();
}
dir->nr = dst - dir->entries;
add_pathspec_matches_against_index(pathspec, seen, specs);
add_pathspec_matches_against_index(pathspec, seen);
return seen;
}
@ -523,7 +521,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
/* This picks up the paths that are not tracked */
baselen = fill_directory(&dir, implicit_dot ? &empty_pathspec : &pathspec);
if (pathspec.nr)
seen = prune_directory(&dir, pathspec.raw, baselen,
seen = prune_directory(&dir, &pathspec, baselen,
implicit_dot ? WARN_IMPLICIT_DOT : 0);
}
@ -538,23 +536,23 @@ int cmd_add(int argc, const char **argv, const char *prefix)
int i;
if (!seen)
seen = find_pathspecs_matching_against_index(pathspec.raw);
seen = find_pathspecs_matching_against_index(&pathspec);
/*
* file_exists() assumes exact match
*/
GUARD_PATHSPEC(&pathspec, PATHSPEC_FROMTOP);
for (i = 0; pathspec.raw[i]; i++) {
if (!seen[i] && pathspec.raw[i][0]
&& !file_exists(pathspec.raw[i])) {
for (i = 0; i < pathspec.nr; i++) {
const char *path = pathspec.items[i].match;
if (!seen[i] && !file_exists(path)) {
if (ignore_missing) {
int dtype = DT_UNKNOWN;
if (is_excluded(&dir, pathspec.raw[i], &dtype))
dir_add_ignored(&dir, pathspec.raw[i], strlen(pathspec.raw[i]));
if (is_excluded(&dir, path, &dtype))
dir_add_ignored(&dir, path, pathspec.items[i].len);
} else
die(_("pathspec '%s' did not match any files"),
pathspec.raw[i]);
pathspec.items[i].original);
}
}
free(seen);