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

Commit 6a0556e

Browse files
committed
Merge branch 'nd/submodule-pathspec-ending-with-slash' into maint
Allow "git cmd path/", when the 'path' is where a submodule is bound to the top-level working tree, to match 'path', despite the extra and unnecessary trailing slash (such a slash is often given by command line completion). * nd/submodule-pathspec-ending-with-slash: clean: use cache_name_is_other() clean: replace match_pathspec() with dir_path_match() pathspec: pass directory indicator to match_pathspec_item() match_pathspec: match pathspec "foo/" against directory "foo" dir.c: prepare match_pathspec_item for taking more flags pathspec: rename match_pathspec_depth() to match_pathspec() pathspec: convert some match_pathspec_depth() to dir_path_match() pathspec: convert some match_pathspec_depth() to ce_path_match()
2 parents 16216b6 + 2e70c01 commit 6a0556e

22 files changed

+89
-76
lines changed

builtin/add.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
208208
i = dir->nr;
209209
while (--i >= 0) {
210210
struct dir_entry *entry = *src++;
211-
if (match_pathspec_depth(pathspec, entry->name, entry->len,
212-
prefix, seen))
211+
if (dir_path_match(entry, pathspec, prefix, seen))
213212
*dst++ = entry;
214213
else if (flag & WARN_IMPLICIT_DOT)
215214
/*

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/clean.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -933,36 +933,18 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
933933

934934
for (i = 0; i < dir.nr; i++) {
935935
struct dir_entry *ent = dir.entries[i];
936-
int len, pos;
937936
int matches = 0;
938-
const struct cache_entry *ce;
939937
struct stat st;
940938
const char *rel;
941939

942-
/*
943-
* Remove the '/' at the end that directory
944-
* walking adds for directory entries.
945-
*/
946-
len = ent->len;
947-
if (len && ent->name[len-1] == '/')
948-
len--;
949-
pos = cache_name_pos(ent->name, len);
950-
if (0 <= pos)
951-
continue; /* exact match */
952-
pos = -pos - 1;
953-
if (pos < active_nr) {
954-
ce = active_cache[pos];
955-
if (ce_namelen(ce) == len &&
956-
!memcmp(ce->name, ent->name, len))
957-
continue; /* Yup, this one exists unmerged */
958-
}
940+
if (!cache_name_is_other(ent->name, ent->len))
941+
continue;
959942

960943
if (lstat(ent->name, &st))
961944
die_errno("Cannot lstat '%s'", ent->name);
962945

963946
if (pathspec.nr)
964-
matches = match_pathspec_depth(&pathspec, ent->name,
965-
len, 0, NULL);
947+
matches = dir_path_match(ent, &pathspec, 0, NULL);
966948

967949
if (S_ISDIR(st.st_mode)) {
968950
if (remove_directories || (matches == MATCHED_EXACTLY)) {

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: 2 additions & 4 deletions
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
@@ -524,9 +524,7 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
524524

525525
fill_directory(&dir, pathspec);
526526
for (i = 0; i < dir.nr; i++) {
527-
const char *name = dir.entries[i]->name;
528-
int namelen = strlen(name);
529-
if (!match_pathspec_depth(pathspec, name, namelen, 0, NULL))
527+
if (!dir_path_match(dir.entries[i], pathspec, 0, NULL))
530528
continue;
531529
hit |= grep_file(opt, dir.entries[i]->name);
532530
if (hit && opt->status_only)

builtin/ls-files.c

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

67-
if (!match_pathspec_depth(&pathspec, ent->name, ent->len, len, ps_matched))
67+
if (!dir_path_match(ent, &pathspec, len, ps_matched))
6868
return;
6969

7070
fputs(tag, stdout);
@@ -139,7 +139,9 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)
139139
if (len >= ce_namelen(ce))
140140
die("git ls-files: internal error - cache entry not superset of prefix");
141141

142-
if (!match_pathspec_depth(&pathspec, ce->name, ce_namelen(ce), len, ps_matched))
142+
if (!match_pathspec(&pathspec, ce->name, ce_namelen(ce),
143+
len, ps_matched,
144+
S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode)))
143145
return;
144146

145147
if (tag && *tag && show_valid_bit &&
@@ -195,7 +197,8 @@ static void show_ru_info(void)
195197
len = strlen(path);
196198
if (len < max_prefix_len)
197199
continue; /* outside of the prefix */
198-
if (!match_pathspec_depth(&pathspec, path, len, max_prefix_len, ps_matched))
200+
if (!match_pathspec(&pathspec, path, len,
201+
max_prefix_len, ps_matched, 0))
199202
continue; /* uninterested */
200203
for (i = 0; i < 3; i++) {
201204
if (!ui->mode[i])

builtin/ls-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
171171
* show_recursive() rolls its own matching code and is
172172
* generally ignorant of 'struct pathspec'. The magic mask
173173
* cannot be lifted until it is converted to use
174-
* match_pathspec_depth() or tree_entry_interesting()
174+
* match_pathspec() or tree_entry_interesting()
175175
*/
176176
parse_pathspec(&pathspec, PATHSPEC_GLOB | PATHSPEC_ICASE,
177177
PATHSPEC_PREFER_CWD,

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);

0 commit comments

Comments
 (0)