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>
Nguyễn Thái Ngọc Duy committed
Jul 14, 2013 at 15:35 UTC
9e06d6ed7667b9564702f3bcda954748cb8afe0e
1 file changed
+13
-33
builtin/ls-files.c
+13
-33
@@ -31,7 +31,7 @@ static int debug_mode;
31
static const char *prefix;
32
static int max_prefix_len;
33
static int prefix_len;
34
-static const char **pathspec;
34
+static struct pathspec pathspec;
35
static int error_unmatch;
36
static char *ps_matched;
37
static const char *with_tree;
@@ -60,7 +60,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
60
if (len >= ent->len)
61
die("git ls-files: internal error - directory entry not superset of prefix");
62
63
- if (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched))
63
+ if (!match_pathspec_depth(&pathspec, ent->name, ent->len, len, ps_matched))
64
return;
65
66
fputs(tag, stdout);
@@ -135,7 +135,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
135
if (len >= ce_namelen(ce))
136
die("git ls-files: internal error - cache entry not superset of prefix");
137
138
- if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), len, ps_matched))
138
+ if (!match_pathspec_depth(&pathspec, ce->name, ce_namelen(ce), len, ps_matched))
139
return;
140
141
if (tag && *tag && show_valid_bit &&
@@ -191,7 +191,7 @@ static void show_ru_info(void)
191
len = strlen(path);
192
if (len < max_prefix_len)
193
continue; /* outside of the prefix */
194
- if (!match_pathspec(pathspec, path, len, max_prefix_len, ps_matched))
194
+ if (!match_pathspec_depth(&pathspec, path, len, max_prefix_len, ps_matched))
195
continue; /* uninterested */
196
for (i = 0; i < 3; i++) {
197
if (!ui->mode[i])
@@ -216,7 +216,7 @@ static void show_files(struct dir_struct *dir)
216
217
/* For cached/deleted files we don't need to even do the readdir */
218
if (show_others || show_killed) {
219
- fill_directory(dir, pathspec);
219
+ fill_directory(dir, pathspec.raw);
220
if (show_others)
221
show_other_files(dir);
222
if (show_killed)
@@ -284,21 +284,6 @@ static void prune_cache(const char *prefix)
284
active_nr = last;
285
}
286
287
-static void strip_trailing_slash_from_submodules(void)
288
-{
289
- const char **p;
290
-
291
- for (p = pathspec; *p != NULL; p++) {
292
- int len = strlen(*p), pos;
293
-
294
- if (len < 1 || (*p)[len - 1] != '/')
295
- continue;
296
- pos = cache_name_pos(*p, len - 1);
297
- if (pos >= 0 && S_ISGITLINK(active_cache[pos]->ce_mode))
298
- *p = xstrndup(*p, len - 1);
299
- }
300
-}
301
-
287
/*
288
* Read the tree specified with --with-tree option
289
* (typically, HEAD) into stage #1 and then
@@ -552,23 +537,18 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
537
if (require_work_tree && !is_inside_work_tree())
538
setup_work_tree();
539
555
- pathspec = get_pathspec(prefix, argv);
556
-
557
- /* be nice with submodule paths ending in a slash */
558
- if (pathspec)
559
- strip_trailing_slash_from_submodules();
540
+ parse_pathspec(&pathspec, 0,
541
+ PATHSPEC_PREFER_CWD |
542
+ PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
543
+ prefix, argv);
544
545
/* Find common prefix for all pathspec's */
562
- max_prefix = common_prefix(pathspec);
546
+ max_prefix = common_prefix(pathspec.raw);
547
max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
548
549
/* Treat unmatching pathspec elements as errors */
566
- if (pathspec && error_unmatch) {
567
- int num;
568
- for (num = 0; pathspec[num]; num++)
569
- ;
570
- ps_matched = xcalloc(1, num);
571
- }
550
+ if (pathspec.nr && error_unmatch)
551
+ ps_matched = xcalloc(1, pathspec.nr);
552
553
if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given)
554
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)
575
576
if (ps_matched) {
577
int bad;
598
- bad = report_path_error(ps_matched, pathspec, prefix);
578
+ bad = report_path_error(ps_matched, pathspec.raw, prefix);
579
if (bad)
580
fprintf(stderr, "Did you forget to 'git add'?\n");
581