Skip to content

Commit 6d2df28

Browse files
pcloudsgitster
authored andcommitted
dir.c: remove an implicit dependency on the_index in pathspec code
Make the match_patchspec API and friends take an index_state instead of assuming the_index in dir.c. All external call sites are converted blindly to keep the patch simple and retain current behavior. Individual call sites may receive further updates to use the right index instead of the_index. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7f944e2 commit 6d2df28

21 files changed

+54
-45
lines changed

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static int reject_entry(const struct object_id *oid, struct strbuf *base,
313313
struct strbuf sb = STRBUF_INIT;
314314
strbuf_addbuf(&sb, base);
315315
strbuf_addstr(&sb, filename);
316-
if (!match_pathspec(context, sb.buf, sb.len, 0, NULL, 1))
316+
if (!match_pathspec(&the_index, context, sb.buf, sb.len, 0, NULL, 1))
317317
ret = READ_TREE_RECURSIVE;
318318
strbuf_release(&sb);
319319
}

builtin/add.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void chmod_pathspec(struct pathspec *pathspec, char flip)
4040
for (i = 0; i < active_nr; i++) {
4141
struct cache_entry *ce = active_cache[i];
4242

43-
if (pathspec && !ce_path_match(ce, pathspec, NULL))
43+
if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
4444
continue;
4545

4646
if (chmod_cache_entry(ce, flip) < 0)
@@ -135,7 +135,7 @@ static int renormalize_tracked_files(const struct pathspec *pathspec, int flags)
135135
continue; /* do not touch unmerged paths */
136136
if (!S_ISREG(ce->ce_mode) && !S_ISLNK(ce->ce_mode))
137137
continue; /* do not touch non blobs */
138-
if (pathspec && !ce_path_match(ce, pathspec, NULL))
138+
if (pathspec && !ce_path_match(&the_index, ce, pathspec, NULL))
139139
continue;
140140
retval |= add_file_to_cache(ce->name, flags | HASH_RENORMALIZE);
141141
}
@@ -155,7 +155,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
155155
i = dir->nr;
156156
while (--i >= 0) {
157157
struct dir_entry *entry = *src++;
158-
if (dir_path_match(entry, pathspec, prefix, seen))
158+
if (dir_path_match(&the_index, entry, pathspec, prefix, seen))
159159
*dst++ = entry;
160160
}
161161
dir->nr = dst - dir->entries;

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static int checkout_paths(const struct checkout_opts *opts,
318318
* match_pathspec() for _all_ entries when
319319
* opts->source_tree != NULL.
320320
*/
321-
if (ce_path_match(ce, &opts->pathspec, ps_matched))
321+
if (ce_path_match(&the_index, ce, &opts->pathspec, ps_matched))
322322
ce->ce_flags |= CE_MATCHED;
323323
}
324324

builtin/clean.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
976976
continue;
977977

978978
if (pathspec.nr)
979-
matches = dir_path_match(ent, &pathspec, 0, NULL);
979+
matches = dir_path_match(&the_index, ent, &pathspec, 0, NULL);
980980

981981
if (pathspec.nr && !matches)
982982
continue;

builtin/commit.c

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

252252
if (ce->ce_flags & CE_UPDATE)
253253
continue;
254-
if (!ce_path_match(ce, pattern, m))
254+
if (!ce_path_match(&the_index, ce, pattern, m))
255255
continue;
256256
item = string_list_insert(list, ce->name);
257257
if (ce_skip_worktree(ce))

builtin/grep.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
497497
strbuf_addstr(&name, ce->name);
498498

499499
if (S_ISREG(ce->ce_mode) &&
500-
match_pathspec(pathspec, name.buf, name.len, 0, NULL,
500+
match_pathspec(&the_index, pathspec, name.buf, name.len, 0, NULL,
501501
S_ISDIR(ce->ce_mode) ||
502502
S_ISGITLINK(ce->ce_mode))) {
503503
/*
@@ -515,7 +515,7 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
515515
hit |= grep_file(opt, name.buf);
516516
}
517517
} else if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
518-
submodule_path_match(pathspec, name.buf, NULL)) {
518+
submodule_path_match(&the_index, pathspec, name.buf, NULL)) {
519519
hit |= grep_submodule(opt, repo, pathspec, NULL, ce->name, ce->name);
520520
} else {
521521
continue;
@@ -679,7 +679,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
679679

680680
fill_directory(&dir, &the_index, pathspec);
681681
for (i = 0; i < dir.nr; i++) {
682-
if (!dir_path_match(dir.entries[i], pathspec, 0, NULL))
682+
if (!dir_path_match(&the_index, dir.entries[i], pathspec, 0, NULL))
683683
continue;
684684
hit |= grep_file(opt, dir.entries[i]->name);
685685
if (hit && opt->status_only)

builtin/ls-files.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
128128
if (len > ent->len)
129129
die("git ls-files: internal error - directory entry not superset of prefix");
130130

131-
if (!dir_path_match(ent, &pathspec, len, ps_matched))
131+
if (!dir_path_match(&the_index, ent, &pathspec, len, ps_matched))
132132
return;
133133

134134
fputs(tag, stdout);
@@ -228,7 +228,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
228228
if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
229229
is_submodule_active(repo, ce->name)) {
230230
show_submodule(repo, dir, ce->name);
231-
} else if (match_pathspec(&pathspec, fullname, strlen(fullname),
231+
} else if (match_pathspec(&the_index, &pathspec, fullname, strlen(fullname),
232232
max_prefix_len, ps_matched,
233233
S_ISDIR(ce->ce_mode) ||
234234
S_ISGITLINK(ce->ce_mode))) {
@@ -264,7 +264,7 @@ static void show_ru_info(const struct index_state *istate)
264264
len = strlen(path);
265265
if (len < max_prefix_len)
266266
continue; /* outside of the prefix */
267-
if (!match_pathspec(&pathspec, path, len,
267+
if (!match_pathspec(&the_index, &pathspec, path, len,
268268
max_prefix_len, ps_matched, 0))
269269
continue; /* uninterested */
270270
for (i = 0; i < 3; i++) {

builtin/rm.c

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

279279
for (i = 0; i < active_nr; i++) {
280280
const struct cache_entry *ce = active_cache[i];
281-
if (!ce_path_match(ce, &pathspec, seen))
281+
if (!ce_path_match(&the_index, ce, &pathspec, seen))
282282
continue;
283283
ALLOC_GROW(list.entry, list.nr + 1, list.alloc);
284284
list.entry[list.nr].name = xstrdup(ce->name);

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ static int module_list_compute(int argc, const char **argv,
331331
for (i = 0; i < active_nr; i++) {
332332
const struct cache_entry *ce = active_cache[i];
333333

334-
if (!match_pathspec(pathspec, ce->name, ce_namelen(ce),
334+
if (!match_pathspec(&the_index, pathspec, ce->name, ce_namelen(ce),
335335
0, ps_matched, 1) ||
336336
!S_ISGITLINK(ce->ce_mode))
337337
continue;

builtin/update-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ static int do_reupdate(int ac, const char **av,
748748
int save_nr;
749749
char *path;
750750

751-
if (ce_stage(ce) || !ce_path_match(ce, &pathspec, NULL))
751+
if (ce_stage(ce) || !ce_path_match(&the_index, ce, &pathspec, NULL))
752752
continue;
753753
if (has_head)
754754
old = read_one_ent(NULL, &head_oid,

0 commit comments

Comments
 (0)