Commit 429bb40a authored by Duy Nguyen's avatar Duy Nguyen Committed by Junio C Hamano

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: Duy Nguyen's avatarNguyễn Thái Ngọc Duy <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent 017f804e
......@@ -297,8 +297,7 @@ static int checkout_paths(const struct checkout_opts *opts,
* match_pathspec() for _all_ entries when
* opts->source_tree != NULL.
*/
if (match_pathspec_depth(&opts->pathspec, ce->name, ce_namelen(ce),
0, ps_matched))
if (ce_path_match(ce, &opts->pathspec, ps_matched))
ce->ce_flags |= CE_MATCHED;
}
......
......@@ -234,7 +234,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
if (ce->ce_flags & CE_UPDATE)
continue;
if (!match_pathspec_depth(pattern, ce->name, ce_namelen(ce), 0, m))
if (!ce_path_match(ce, pattern, m))
continue;
item = string_list_insert(list, ce->name);
if (ce_skip_worktree(ce))
......
......@@ -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];
if (!S_ISREG(ce->ce_mode))
continue;
if (!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL))
if (!ce_path_match(ce, pathspec, NULL))
continue;
/*
* If CE_VALID is on, we assume worktree file and its cache entry
......
......@@ -308,7 +308,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
for (i = 0; i < active_nr; 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;
ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
list.entry[list.nr].name = ce->name;
......
......@@ -12,6 +12,7 @@
#include "resolve-undo.h"
#include "parse-options.h"
#include "pathspec.h"
#include "dir.h"
/*
* 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;
int save_nr;
if (ce_stage(ce) || !ce_path_match(ce, &pathspec))
if (ce_stage(ce) || !ce_path_match(ce, &pathspec, NULL))
continue;
if (has_head)
old = read_one_ent(NULL, head_sha1,
......
......@@ -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_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_FORMAT_CHECK 2
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);
......
......@@ -11,6 +11,7 @@
#include "unpack-trees.h"
#include "refs.h"
#include "submodule.h"
#include "dir.h"
/*
* diff-files
......@@ -108,7 +109,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
if (diff_can_quit_early(&revs->diffopt))
break;
if (!ce_path_match(ce, &revs->prune_data))
if (!ce_path_match(ce, &revs->prune_data, NULL))
continue;
if (ce_stage(ce)) {
......@@ -438,7 +439,7 @@ static int oneway_diff(const struct cache_entry * const *src,
if (tree == o->df_conflict_entry)
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);
if (diff_can_quit_early(&revs->diffopt)) {
o->exiting_early = 1;
......
......@@ -205,4 +205,11 @@ extern int git_fnmatch(const struct pathspec_item *item,
const char *pattern, const char *string,
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
......@@ -33,7 +33,7 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
return;
for (i = 0; i < active_nr; 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);
}
}
......
......@@ -3,6 +3,7 @@
*/
#include "cache.h"
#include "pathspec.h"
#include "dir.h"
#ifdef NO_PTHREADS
static void preload_index(struct index_state *index,
......@@ -53,7 +54,7 @@ static void *preload_thread(void *_data)
continue;
if (ce_uptodate(ce))
continue;
if (!ce_path_match(ce, &p->pathspec))
if (!ce_path_match(ce, &p->pathspec, NULL))
continue;
if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
continue;
......
......@@ -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);
}
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
* 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))
continue;
if (pathspec &&
!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen))
if (pathspec && !ce_path_match(ce, pathspec, seen))
filtered = 1;
if (ce_stage(ce)) {
......
......@@ -182,7 +182,7 @@ void unmerge_index(struct index_state *istate, const struct pathspec *pathspec)
for (i = 0; i < istate->cache_nr; 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;
i = unmerge_index_entry_at(istate, i);
}
......
......@@ -16,6 +16,7 @@
#include "line-log.h"
#include "mailmap.h"
#include "commit-slab.h"
#include "dir.h"
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];
if (!ce_stage(ce))
continue;
if (ce_path_match(ce, &revs->prune_data)) {
if (ce_path_match(ce, &revs->prune_data, NULL)) {
prune_num++;
prune = xrealloc(prune, sizeof(*prune) * prune_num);
prune[prune_num-2] = ce->name;
......
......@@ -510,7 +510,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
struct wt_status_change_data *d;
const struct cache_entry *ce = active_cache[i];
if (!ce_path_match(ce, &s->pathspec))
if (!ce_path_match(ce, &s->pathspec, NULL))
continue;
it = string_list_insert(&s->change, ce->name);
d = it->util;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment