ls-files: convert to use parse_pathspec
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:
parent
29211a93c1
commit
9e06d6ed76
@ -31,7 +31,7 @@ static int debug_mode;
|
||||
static const char *prefix;
|
||||
static int max_prefix_len;
|
||||
static int prefix_len;
|
||||
static const char **pathspec;
|
||||
static struct pathspec pathspec;
|
||||
static int error_unmatch;
|
||||
static char *ps_matched;
|
||||
static const char *with_tree;
|
||||
@ -60,7 +60,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
|
||||
if (len >= ent->len)
|
||||
die("git ls-files: internal error - directory entry not superset of prefix");
|
||||
|
||||
if (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched))
|
||||
if (!match_pathspec_depth(&pathspec, ent->name, ent->len, len, ps_matched))
|
||||
return;
|
||||
|
||||
fputs(tag, stdout);
|
||||
@ -135,7 +135,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
|
||||
if (len >= ce_namelen(ce))
|
||||
die("git ls-files: internal error - cache entry not superset of prefix");
|
||||
|
||||
if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), len, ps_matched))
|
||||
if (!match_pathspec_depth(&pathspec, ce->name, ce_namelen(ce), len, ps_matched))
|
||||
return;
|
||||
|
||||
if (tag && *tag && show_valid_bit &&
|
||||
@ -191,7 +191,7 @@ static void show_ru_info(void)
|
||||
len = strlen(path);
|
||||
if (len < max_prefix_len)
|
||||
continue; /* outside of the prefix */
|
||||
if (!match_pathspec(pathspec, path, len, max_prefix_len, ps_matched))
|
||||
if (!match_pathspec_depth(&pathspec, path, len, max_prefix_len, ps_matched))
|
||||
continue; /* uninterested */
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (!ui->mode[i])
|
||||
@ -216,7 +216,7 @@ static void show_files(struct dir_struct *dir)
|
||||
|
||||
/* For cached/deleted files we don't need to even do the readdir */
|
||||
if (show_others || show_killed) {
|
||||
fill_directory(dir, pathspec);
|
||||
fill_directory(dir, pathspec.raw);
|
||||
if (show_others)
|
||||
show_other_files(dir);
|
||||
if (show_killed)
|
||||
@ -284,21 +284,6 @@ static void prune_cache(const char *prefix)
|
||||
active_nr = last;
|
||||
}
|
||||
|
||||
static void strip_trailing_slash_from_submodules(void)
|
||||
{
|
||||
const char **p;
|
||||
|
||||
for (p = pathspec; *p != NULL; p++) {
|
||||
int len = strlen(*p), pos;
|
||||
|
||||
if (len < 1 || (*p)[len - 1] != '/')
|
||||
continue;
|
||||
pos = cache_name_pos(*p, len - 1);
|
||||
if (pos >= 0 && S_ISGITLINK(active_cache[pos]->ce_mode))
|
||||
*p = xstrndup(*p, len - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Read the tree specified with --with-tree option
|
||||
* (typically, HEAD) into stage #1 and then
|
||||
@ -552,23 +537,18 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
|
||||
if (require_work_tree && !is_inside_work_tree())
|
||||
setup_work_tree();
|
||||
|
||||
pathspec = get_pathspec(prefix, argv);
|
||||
|
||||
/* be nice with submodule paths ending in a slash */
|
||||
if (pathspec)
|
||||
strip_trailing_slash_from_submodules();
|
||||
parse_pathspec(&pathspec, 0,
|
||||
PATHSPEC_PREFER_CWD |
|
||||
PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
|
||||
prefix, argv);
|
||||
|
||||
/* Find common prefix for all pathspec's */
|
||||
max_prefix = common_prefix(pathspec);
|
||||
max_prefix = common_prefix(pathspec.raw);
|
||||
max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
|
||||
|
||||
/* Treat unmatching pathspec elements as errors */
|
||||
if (pathspec && error_unmatch) {
|
||||
int num;
|
||||
for (num = 0; pathspec[num]; num++)
|
||||
;
|
||||
ps_matched = xcalloc(1, num);
|
||||
}
|
||||
if (pathspec.nr && error_unmatch)
|
||||
ps_matched = xcalloc(1, pathspec.nr);
|
||||
|
||||
if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given)
|
||||
die("ls-files --ignored needs some exclude pattern");
|
||||
@ -595,7 +575,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
|
||||
|
||||
if (ps_matched) {
|
||||
int bad;
|
||||
bad = report_path_error(ps_matched, pathspec, prefix);
|
||||
bad = report_path_error(ps_matched, pathspec.raw, prefix);
|
||||
if (bad)
|
||||
fprintf(stderr, "Did you forget to 'git add'?\n");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user