Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 429bb40

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 017f804 commit 429bb40

File tree

14 files changed

+24
-22
lines changed

14 files changed

+24
-22
lines changed

builtin/checkout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ static int checkout_paths(const struct checkout_opts *opts,
297297
* match_pathspec() for _all_ entries when
298298
* opts->source_tree != NULL.
299299
*/
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))
302301
ce->ce_flags |= CE_MATCHED;
303302
}
304303

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
234234

235235
if (ce->ce_flags & CE_UPDATE)
236236
continue;
237-
if (!match_pathspec_depth(pattern, ce->name, ce_namelen(ce), 0, m))
237+
if (!ce_path_match(ce, pattern, m))
238238
continue;
239239
item = string_list_insert(list, ce->name);
240240
if (ce_skip_worktree(ce))

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
379379
const struct cache_entry *ce = active_cache[nr];
380380
if (!S_ISREG(ce->ce_mode))
381381
continue;
382-
if (!match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, NULL))
382+
if (!ce_path_match(ce, pathspec, NULL))
383383
continue;
384384
/*
385385
* If CE_VALID is on, we assume worktree file and its cache entry

builtin/rm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
308308

309309
for (i = 0; i < active_nr; i++) {
310310
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))
312312
continue;
313313
ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
314314
list.entry[list.nr].name = ce->name;

builtin/update-index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "resolve-undo.h"
1313
#include "parse-options.h"
1414
#include "pathspec.h"
15+
#include "dir.h"
1516

1617
/*
1718
* Default to not allowing changes to the list of files. The
@@ -564,7 +565,7 @@ static int do_reupdate(int ac, const char **av,
564565
struct cache_entry *old = NULL;
565566
int save_nr;
566567

567-
if (ce_stage(ce) || !ce_path_match(ce, &pathspec))
568+
if (ce_stage(ce) || !ce_path_match(ce, &pathspec, NULL))
568569
continue;
569570
if (has_head)
570571
old = read_one_ent(NULL, head_sha1,

cache.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,6 @@ extern void *read_blob_data_from_index(struct index_state *, const char *, unsig
501501
extern int ie_match_stat(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
502502
extern int ie_modified(const struct index_state *, const struct cache_entry *, struct stat *, unsigned int);
503503

504-
extern int ce_path_match(const struct cache_entry *ce, const struct pathspec *pathspec);
505-
506504
#define HASH_WRITE_OBJECT 1
507505
#define HASH_FORMAT_CHECK 2
508506
extern int index_fd(unsigned char *sha1, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags);

diff-lib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "unpack-trees.h"
1212
#include "refs.h"
1313
#include "submodule.h"
14+
#include "dir.h"
1415

1516
/*
1617
* diff-files
@@ -108,7 +109,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
108109
if (diff_can_quit_early(&revs->diffopt))
109110
break;
110111

111-
if (!ce_path_match(ce, &revs->prune_data))
112+
if (!ce_path_match(ce, &revs->prune_data, NULL))
112113
continue;
113114

114115
if (ce_stage(ce)) {
@@ -438,7 +439,7 @@ static int oneway_diff(const struct cache_entry * const *src,
438439
if (tree == o->df_conflict_entry)
439440
tree = NULL;
440441

441-
if (ce_path_match(idx ? idx : tree, &revs->prune_data)) {
442+
if (ce_path_match(idx ? idx : tree, &revs->prune_data, NULL)) {
442443
do_oneway_diff(o, idx, tree);
443444
if (diff_can_quit_early(&revs->diffopt)) {
444445
o->exiting_early = 1;

dir.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,11 @@ extern int git_fnmatch(const struct pathspec_item *item,
205205
const char *pattern, const char *string,
206206
int prefix);
207207

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+
208215
#endif

pathspec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
3333
return;
3434
for (i = 0; i < active_nr; i++) {
3535
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);
3737
}
3838
}
3939

preload-index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
#include "cache.h"
55
#include "pathspec.h"
6+
#include "dir.h"
67

78
#ifdef NO_PTHREADS
89
static void preload_index(struct index_state *index,
@@ -53,7 +54,7 @@ static void *preload_thread(void *_data)
5354
continue;
5455
if (ce_uptodate(ce))
5556
continue;
56-
if (!ce_path_match(ce, &p->pathspec))
57+
if (!ce_path_match(ce, &p->pathspec, NULL))
5758
continue;
5859
if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce)))
5960
continue;

0 commit comments

Comments
 (0)