Skip to content

Commit d64d483

Browse files
committed
Merge branch 'cb/add-pathspec'
* cb/add-pathspec: remove pathspec_match, use match_pathspec instead clean up pathspec matching
2 parents f18e6be + 0b50922 commit d64d483

File tree

5 files changed

+17
-51
lines changed

5 files changed

+17
-51
lines changed

builtin-checkout.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
230230

231231
for (pos = 0; pos < active_nr; pos++) {
232232
struct cache_entry *ce = active_cache[pos];
233-
pathspec_match(pathspec, ps_matched, ce->name, 0);
233+
match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, ps_matched);
234234
}
235235

236236
if (report_path_error(ps_matched, pathspec, 0))
@@ -239,7 +239,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
239239
/* Any unmerged paths? */
240240
for (pos = 0; pos < active_nr; pos++) {
241241
struct cache_entry *ce = active_cache[pos];
242-
if (pathspec_match(pathspec, NULL, ce->name, 0)) {
242+
if (match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) {
243243
if (!ce_stage(ce))
244244
continue;
245245
if (opts->force) {
@@ -264,7 +264,7 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec,
264264
state.refresh_cache = 1;
265265
for (pos = 0; pos < active_nr; pos++) {
266266
struct cache_entry *ce = active_cache[pos];
267-
if (pathspec_match(pathspec, NULL, ce->name, 0)) {
267+
if (match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, NULL)) {
268268
if (!ce_stage(ce)) {
269269
errs |= checkout_entry(ce, &state, NULL);
270270
continue;

builtin-commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
166166
struct cache_entry *ce = active_cache[i];
167167
if (ce->ce_flags & CE_UPDATE)
168168
continue;
169-
if (!pathspec_match(pattern, m, ce->name, 0))
169+
if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
170170
continue;
171171
string_list_insert(ce->name, list);
172172
}

builtin-ls-files.c

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,6 @@ static const char *tag_other = "";
3636
static const char *tag_killed = "";
3737
static const char *tag_modified = "";
3838

39-
40-
/*
41-
* Match a pathspec against a filename. The first "skiplen" characters
42-
* are the common prefix
43-
*/
44-
int pathspec_match(const char **spec, char *ps_matched,
45-
const char *filename, int skiplen)
46-
{
47-
const char *m;
48-
49-
while ((m = *spec++) != NULL) {
50-
int matchlen = strlen(m + skiplen);
51-
52-
if (!matchlen)
53-
goto matched;
54-
if (!strncmp(m + skiplen, filename + skiplen, matchlen)) {
55-
if (m[skiplen + matchlen - 1] == '/')
56-
goto matched;
57-
switch (filename[skiplen + matchlen]) {
58-
case '/': case '\0':
59-
goto matched;
60-
}
61-
}
62-
if (!fnmatch(m + skiplen, filename + skiplen, 0))
63-
goto matched;
64-
if (ps_matched)
65-
ps_matched++;
66-
continue;
67-
matched:
68-
if (ps_matched)
69-
*ps_matched = 1;
70-
return 1;
71-
}
72-
return 0;
73-
}
74-
7539
static void show_dir_entry(const char *tag, struct dir_entry *ent)
7640
{
7741
int len = prefix_len;
@@ -80,7 +44,7 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent)
8044
if (len >= ent->len)
8145
die("git ls-files: internal error - directory entry not superset of prefix");
8246

83-
if (pathspec && !pathspec_match(pathspec, ps_matched, ent->name, len))
47+
if (!match_pathspec(pathspec, ent->name, ent->len, len, ps_matched))
8448
return;
8549

8650
fputs(tag, stdout);
@@ -156,7 +120,7 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)
156120
if (len >= ce_namelen(ce))
157121
die("git ls-files: internal error - cache entry not superset of prefix");
158122

159-
if (pathspec && !pathspec_match(pathspec, ps_matched, ce->name, len))
123+
if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), len, ps_matched))
160124
return;
161125

162126
if (tag && *tag && show_valid_bit &&

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,6 @@ extern int ws_fix_copy(char *, const char *, int, unsigned, int *);
937937
extern int ws_blank_line(const char *line, int len, unsigned ws_rule);
938938

939939
/* ls-files */
940-
int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen);
941940
int report_path_error(const char *ps_matched, const char **pathspec, int prefix_offset);
942941
void overlay_tree_on_cache(const char *tree_name, const char *prefix);
943942

dir.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,28 @@ static int match_one(const char *match, const char *name, int namelen)
108108
* and a mark is left in seen[] array for pathspec element that
109109
* actually matched anything.
110110
*/
111-
int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen)
111+
int match_pathspec(const char **pathspec, const char *name, int namelen,
112+
int prefix, char *seen)
112113
{
113-
int retval;
114-
const char *match;
114+
int i, retval = 0;
115+
116+
if (!pathspec)
117+
return 1;
115118

116119
name += prefix;
117120
namelen -= prefix;
118121

119-
for (retval = 0; (match = *pathspec++) != NULL; seen++) {
122+
for (i = 0; pathspec[i] != NULL; i++) {
120123
int how;
121-
if (retval && *seen == MATCHED_EXACTLY)
124+
const char *match = pathspec[i] + prefix;
125+
if (seen && seen[i] == MATCHED_EXACTLY)
122126
continue;
123-
match += prefix;
124127
how = match_one(match, name, namelen);
125128
if (how) {
126129
if (retval < how)
127130
retval = how;
128-
if (*seen < how)
129-
*seen = how;
131+
if (seen && seen[i] < how)
132+
seen[i] = how;
130133
}
131134
}
132135
return retval;

0 commit comments

Comments
 (0)