pathspec: convert some match_pathspec_depth() to ce_path_match()

This helps reduce the number of match_pathspec_depth() call sites and show how match_pathspec_depth() is used. 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 Jan 24, 2014 at 20:40 UTC 429bb40abdb5b42ffdde5b1a58f9a37da723d179
14 files changed +24 -22
builtin/checkout.c
+1 -2
@@ -297,8 +297,7 @@ static int checkout_paths(const struct checkout_opts *opts,
297 * match_pathspec() for _all_ entries when
298 * opts->source_tree != NULL.
299 */
300 - if (match_pathspec_depth(&opts->pathspec, ce->name, ce_namelen(ce),
301 - 0, ps_matched))
300 + if (ce_path_match(ce, &opts->pathspec, ps_matched))
301 ce->ce_flags |= CE_MATCHED;
302 }
303
builtin/commit.c
+1 -1
@@ -234,7 +234,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
234
235 if (ce->ce_flags & CE_UPDATE)
236 continue;
237 - if (!match_pathspec_depth(pattern, ce->name, ce_namelen(ce), 0, m))
237 + if (!ce_path_match(ce, pattern, m))
238 continue;
239 item = string_list_insert(list, ce->name);
240 if (ce_skip_worktree(ce))
builtin/grep.c
+1 -1
@@ -379,7 +379,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
379 const struct cache_entry *ce = active_cache[nr];
380 if (!S_ISREG(ce->ce_mode))
381 continue;
382 - if (!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL))
382 + if (!ce_path_match(ce, pathspec, NULL))
383 continue;
384 /*
385 * If CE_VALID is on, we assume worktree file and its cache entry
builtin/rm.c
+1 -1
@@ -308,7 +308,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
308
309 for (i = 0; i < active_nr; i++) {
310 const struct cache_entry *ce = active_cache[i];
311 - if (!match_pathspec_depth(&pathspec, ce->name, ce_namelen(ce), 0, seen))
311 + if (!ce_path_match(ce, &pathspec, seen))
312 continue;
313 ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
314 list.entry[list.nr].name = ce->name;
builtin/update-index.c
+2 -1
@@ -12,6 +12,7 @@
12 #include "resolve-undo.h"
13 #include "parse-options.h"
14 #include "pathspec.h"
15 +#include "dir.h"
16
17 /*
18 * Default to not allowing changes to the list of files. The
@@ -564,7 +565,7 @@ static int do_reupdate(int ac, const char **av,
565 struct cache_entry *old = NULL;
566 int save_nr;
567
567 - if (ce_stage(ce) || !ce_path_match(ce, &pathspec))
568 + if (ce_stage(ce) || !ce_path_match(ce, &pathspec, NULL))
569 continue;
570 if (has_head)
571 old = read_one_ent(NULL, head_sha1,
cache.h
-2
@@ -501,8 +501,6 @@ extern void *read_blob_data_from_index(struct index_state *, const char *, unsig
501 extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
502 extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
503
504 -extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec);
505 -
504 #define HASH_WRITE_OBJECT 1
505 #define HASH_FORMAT_CHECK 2
506 extern int index_fd(unsigned char *sha1, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
diff-lib.c
+3 -2
@@ -11,6 +11,7 @@
11 #include "unpack-trees.h"
12 #include "refs.h"
13 #include "submodule.h"
14 +#include "dir.h"
15
16 /*
17 * diff-files
@@ -108,7 +109,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
109 if (diff_can_quit_early(&revs->diffopt))
110 break;
111
111 - if (!ce_path_match(ce, &revs->prune_data))
112 + if (!ce_path_match(ce, &revs->prune_data, NULL))
113 continue;
114
115 if (ce_stage(ce)) {
@@ -438,7 +439,7 @@ static int oneway_diff(const struct cache_entry * const *src,
439 if (tree == o->df_conflict_entry)
440 tree = NULL;
441
441 - if (ce_path_match(idx ? idx : tree, &revs->prune_data)) {
442 + if (ce_path_match(idx ? idx : tree, &revs->prune_data, NULL)) {
443 do_oneway_diff(o, idx, tree);
444 if (diff_can_quit_early(&revs->diffopt)) {
445 o->exiting_early = 1;
dir.h
+7
@@ -205,4 +205,11 @@ extern int git_fnmatch(const struct pathspec_item *item,
205 const char *pattern, const char *string,
206 int prefix);
207
208 +static inline int ce_path_match(const struct cache_entry *ce,
209 + const struct pathspec *pathspec,
210 + char *seen)
211 +{
212 + return match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen);
213 +}
214 +
215 #endif
pathspec.c
+1 -1
@@ -33,7 +33,7 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
33 return;
34 for (i = 0; i < active_nr; i++) {
35 const struct cache_entry *ce = active_cache[i];
36 - match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen);
36 + ce_path_match(ce, pathspec, seen);
37 }
38 }
39
preload-index.c
+2 -1
@@ -3,6 +3,7 @@
3 */
4 #include "cache.h"
5 #include "pathspec.h"
6 +#include "dir.h"
7
8 #ifdef NO_PTHREADS
9 static void preload_index(struct index_state *index,
@@ -53,7 +54,7 @@ static void *preload_thread(void *_data)
54 continue;
55 if (ce_uptodate(ce))
56 continue;
56 - if (!ce_path_match(ce, &p->pathspec))
57 + if (!ce_path_match(ce, &p->pathspec, NULL))
58 continue;
59 if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
60 continue;
read-cache.c
+1 -7
@@ -728,11 +728,6 @@ int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)
728 return ce_namelen(b) == len && !memcmp(a->name, b->name, len);
729 }
730
731 -int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec)
732 -{
733 - return match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL);
734 -}
735 -
731 /*
732 * We fundamentally don't like some paths: we don't want
733 * dot or dot-dot anywhere, and for obvious reasons don't
@@ -1149,8 +1144,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
1144 if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
1145 continue;
1146
1152 - if (pathspec &&
1153 - !match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen))
1147 + if (pathspec && !ce_path_match(ce, pathspec, seen))
1148 filtered = 1;
1149
1150 if (ce_stage(ce)) {
resolve-undo.c
+1 -1
@@ -182,7 +182,7 @@ void unmerge_index(struct index_state *istate, const struct pathspec *pathspec)
182
183 for (i = 0; i < istate->cache_nr; i++) {
184 const struct cache_entry *ce = istate->cache[i];
185 - if (!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL))
185 + if (!ce_path_match(ce, pathspec, NULL))
186 continue;
187 i = unmerge_index_entry_at(istate, i);
188 }
revision.c
+2 -1
@@ -16,6 +16,7 @@
16 #include "line-log.h"
17 #include "mailmap.h"
18 #include "commit-slab.h"
19 +#include "dir.h"
20
21 volatile show_early_output_fn_t show_early_output;
22
@@ -1400,7 +1401,7 @@ static void prepare_show_merge(struct rev_info *revs)
1401 const struct cache_entry *ce = active_cache[i];
1402 if (!ce_stage(ce))
1403 continue;
1403 - if (ce_path_match(ce, &revs->prune_data)) {
1404 + if (ce_path_match(ce, &revs->prune_data, NULL)) {
1405 prune_num++;
1406 prune = xrealloc(prune, sizeof(*prune) * prune_num);
1407 prune[prune_num-2] = ce->name;
wt-status.c
+1 -1
@@ -510,7 +510,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
510 struct wt_status_change_data *d;
511 const struct cache_entry *ce = active_cache[i];
512
513 - if (!ce_path_match(ce, &s->pathspec))
513 + if (!ce_path_match(ce, &s->pathspec, NULL))
514 continue;
515 it = string_list_insert(&s->change, ce->name);
516 d = it->util;