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