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>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2014-01-24 20:40:28 +07:00 committed by Junio C Hamano
parent 017f804efc
commit 429bb40abd
14 changed files with 24 additions and 22 deletions

View File

@ -297,8 +297,7 @@ static int checkout_paths(const struct checkout_opts *opts,
* match_pathspec() for _all_ entries when * match_pathspec() for _all_ entries when
* opts->source_tree != NULL. * opts->source_tree != NULL.
*/ */
if (match_pathspec_depth(&opts->pathspec, ce->name, ce_namelen(ce), if (ce_path_match(ce, &opts->pathspec, ps_matched))
0, ps_matched))
ce->ce_flags |= CE_MATCHED; ce->ce_flags |= CE_MATCHED;
} }

View File

@ -234,7 +234,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
if (ce->ce_flags & CE_UPDATE) if (ce->ce_flags & CE_UPDATE)
continue; continue;
if (!match_pathspec_depth(pattern, ce->name, ce_namelen(ce), 0, m)) if (!ce_path_match(ce, pattern, m))
continue; continue;
item = string_list_insert(list, ce->name); item = string_list_insert(list, ce->name);
if (ce_skip_worktree(ce)) if (ce_skip_worktree(ce))

View File

@ -379,7 +379,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
const struct cache_entry *ce = active_cache[nr]; const struct cache_entry *ce = active_cache[nr];
if (!S_ISREG(ce->ce_mode)) if (!S_ISREG(ce->ce_mode))
continue; continue;
if (!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL)) if (!ce_path_match(ce, pathspec, NULL))
continue; continue;
/* /*
* If CE_VALID is on, we assume worktree file and its cache entry * If CE_VALID is on, we assume worktree file and its cache entry

View File

@ -308,7 +308,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
const struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if (!match_pathspec_depth(&pathspec, ce->name, ce_namelen(ce), 0, seen)) if (!ce_path_match(ce, &pathspec, seen))
continue; continue;
ALLOC_GROW(list.entry, list.nr + 1, list.alloc); ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
list.entry[list.nr].name = ce->name; list.entry[list.nr].name = ce->name;

View File

@ -12,6 +12,7 @@
#include "resolve-undo.h" #include "resolve-undo.h"
#include "parse-options.h" #include "parse-options.h"
#include "pathspec.h" #include "pathspec.h"
#include "dir.h"
/* /*
* Default to not allowing changes to the list of files. The * Default to not allowing changes to the list of files. The
@ -564,7 +565,7 @@ static int do_reupdate(int ac, const char **av,
struct cache_entry *old = NULL; struct cache_entry *old = NULL;
int save_nr; int save_nr;
if (ce_stage(ce) || !ce_path_match(ce, &pathspec)) if (ce_stage(ce) || !ce_path_match(ce, &pathspec, NULL))
continue; continue;
if (has_head) if (has_head)
old = read_one_ent(NULL, head_sha1, old = read_one_ent(NULL, head_sha1,

View File

@ -501,8 +501,6 @@ extern void *read_blob_data_from_index(struct index_state *, const char *, unsig
extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int); extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int); extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec);
#define HASH_WRITE_OBJECT 1 #define HASH_WRITE_OBJECT 1
#define HASH_FORMAT_CHECK 2 #define HASH_FORMAT_CHECK 2
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags); extern int index_fd(unsigned char *sha1, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);

View File

@ -11,6 +11,7 @@
#include "unpack-trees.h" #include "unpack-trees.h"
#include "refs.h" #include "refs.h"
#include "submodule.h" #include "submodule.h"
#include "dir.h"
/* /*
* diff-files * diff-files
@ -108,7 +109,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
if (diff_can_quit_early(&revs->diffopt)) if (diff_can_quit_early(&revs->diffopt))
break; break;
if (!ce_path_match(ce, &revs->prune_data)) if (!ce_path_match(ce, &revs->prune_data, NULL))
continue; continue;
if (ce_stage(ce)) { if (ce_stage(ce)) {
@ -438,7 +439,7 @@ static int oneway_diff(const struct cache_entry * const *src,
if (tree == o->df_conflict_entry) if (tree == o->df_conflict_entry)
tree = NULL; tree = NULL;
if (ce_path_match(idx ? idx : tree, &revs->prune_data)) { if (ce_path_match(idx ? idx : tree, &revs->prune_data, NULL)) {
do_oneway_diff(o, idx, tree); do_oneway_diff(o, idx, tree);
if (diff_can_quit_early(&revs->diffopt)) { if (diff_can_quit_early(&revs->diffopt)) {
o->exiting_early = 1; o->exiting_early = 1;

7
dir.h
View File

@ -205,4 +205,11 @@ extern int git_fnmatch(const struct pathspec_item *item,
const char *pattern, const char *string, const char *pattern, const char *string,
int prefix); int prefix);
static inline int ce_path_match(const struct cache_entry *ce,
const struct pathspec *pathspec,
char *seen)
{
return match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen);
}
#endif #endif

View File

@ -33,7 +33,7 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
return; return;
for (i = 0; i < active_nr; i++) { for (i = 0; i < active_nr; i++) {
const struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen); ce_path_match(ce, pathspec, seen);
} }
} }

View File

@ -3,6 +3,7 @@
*/ */
#include "cache.h" #include "cache.h"
#include "pathspec.h" #include "pathspec.h"
#include "dir.h"
#ifdef NO_PTHREADS #ifdef NO_PTHREADS
static void preload_index(struct index_state *index, static void preload_index(struct index_state *index,
@ -53,7 +54,7 @@ static void *preload_thread(void *_data)
continue; continue;
if (ce_uptodate(ce)) if (ce_uptodate(ce))
continue; continue;
if (!ce_path_match(ce, &p->pathspec)) if (!ce_path_match(ce, &p->pathspec, NULL))
continue; continue;
if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce))) if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
continue; continue;

View File

@ -728,11 +728,6 @@ int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)
return ce_namelen(b) == len && !memcmp(a->name, b->name, len); return ce_namelen(b) == len && !memcmp(a->name, b->name, len);
} }
int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec)
{
return match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL);
}
/* /*
* We fundamentally don't like some paths: we don't want * We fundamentally don't like some paths: we don't want
* dot or dot-dot anywhere, and for obvious reasons don't * 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,
if (ignore_submodules && S_ISGITLINK(ce->ce_mode)) if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
continue; continue;
if (pathspec && if (pathspec && !ce_path_match(ce, pathspec, seen))
!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen))
filtered = 1; filtered = 1;
if (ce_stage(ce)) { if (ce_stage(ce)) {

View File

@ -182,7 +182,7 @@ void unmerge_index(struct index_state *istate, const struct pathspec *pathspec)
for (i = 0; i < istate->cache_nr; i++) { for (i = 0; i < istate->cache_nr; i++) {
const struct cache_entry *ce = istate->cache[i]; const struct cache_entry *ce = istate->cache[i];
if (!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL)) if (!ce_path_match(ce, pathspec, NULL))
continue; continue;
i = unmerge_index_entry_at(istate, i); i = unmerge_index_entry_at(istate, i);
} }

View File

@ -16,6 +16,7 @@
#include "line-log.h" #include "line-log.h"
#include "mailmap.h" #include "mailmap.h"
#include "commit-slab.h" #include "commit-slab.h"
#include "dir.h"
volatile show_early_output_fn_t show_early_output; volatile show_early_output_fn_t show_early_output;
@ -1400,7 +1401,7 @@ static void prepare_show_merge(struct rev_info *revs)
const struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if (!ce_stage(ce)) if (!ce_stage(ce))
continue; continue;
if (ce_path_match(ce, &revs->prune_data)) { if (ce_path_match(ce, &revs->prune_data, NULL)) {
prune_num++; prune_num++;
prune = xrealloc(prune, sizeof(*prune) * prune_num); prune = xrealloc(prune, sizeof(*prune) * prune_num);
prune[prune_num-2] = ce->name; prune[prune_num-2] = ce->name;

View File

@ -510,7 +510,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
struct wt_status_change_data *d; struct wt_status_change_data *d;
const struct cache_entry *ce = active_cache[i]; const struct cache_entry *ce = active_cache[i];
if (!ce_path_match(ce, &s->pathspec)) if (!ce_path_match(ce, &s->pathspec, NULL))
continue; continue;
it = string_list_insert(&s->change, ce->name); it = string_list_insert(&s->change, ce->name);
d = it->util; d = it->util;