remove match_pathspec() in favor of match_pathspec_depth()
match_pathspec_depth was created to replace match_pathspec (see 61cf282 (pathspec: add match_pathspec_depth() - 2010-12-15). It took more than two years, but the replacement finally happens :-) Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jul 14, 2013 at 15:36 UTC
84b8b5d1fa244bc591291a3cf18bf0fa9976ad17
6 files changed
+25
-140
builtin/add.c
+14
-16
@@ -195,23 +195,21 @@ int add_files_to_cache(const char *prefix,
195
}
196
197
#define WARN_IMPLICIT_DOT (1u << 0)
198
-static char *prune_directory(struct dir_struct *dir, const char **pathspec,
198
+static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec,
199
int prefix, unsigned flag)
200
{
201
char *seen;
202
- int i, specs;
202
+ int i;
203
struct dir_entry **src, **dst;
204
205
- for (specs = 0; pathspec[specs]; specs++)
206
- /* nothing */;
207
- seen = xcalloc(specs, 1);
205
+ seen = xcalloc(pathspec->nr, 1);
206
207
src = dst = dir->entries;
208
i = dir->nr;
209
while (--i >= 0) {
210
struct dir_entry *entry = *src++;
213
- if (match_pathspec(pathspec, entry->name, entry->len,
214
- prefix, seen))
211
+ if (match_pathspec_depth(pathspec, entry->name, entry->len,
212
+ prefix, seen))
213
*dst++ = entry;
214
else if (flag & WARN_IMPLICIT_DOT)
215
/*
@@ -225,7 +223,7 @@ static char *prune_directory(struct dir_struct *dir, const char **pathspec,
223
warn_pathless_add();
224
}
225
dir->nr = dst - dir->entries;
228
- add_pathspec_matches_against_index(pathspec, seen, specs);
226
+ add_pathspec_matches_against_index(pathspec, seen);
227
return seen;
228
}
229
@@ -523,7 +521,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
521
/* This picks up the paths that are not tracked */
522
baselen = fill_directory(&dir, implicit_dot ? &empty_pathspec : &pathspec);
523
if (pathspec.nr)
526
- seen = prune_directory(&dir, pathspec.raw, baselen,
524
+ seen = prune_directory(&dir, &pathspec, baselen,
525
implicit_dot ? WARN_IMPLICIT_DOT : 0);
526
}
527
@@ -538,23 +536,23 @@ int cmd_add(int argc, const char **argv, const char *prefix)
536
int i;
537
538
if (!seen)
541
- seen = find_pathspecs_matching_against_index(pathspec.raw);
539
+ seen = find_pathspecs_matching_against_index(&pathspec);
540
541
/*
542
* file_exists() assumes exact match
543
*/
544
GUARD_PATHSPEC(&pathspec, PATHSPEC_FROMTOP);
545
548
- for (i = 0; pathspec.raw[i]; i++) {
549
- if (!seen[i] && pathspec.raw[i][0]
550
- && !file_exists(pathspec.raw[i])) {
546
+ for (i = 0; i < pathspec.nr; i++) {
547
+ const char *path = pathspec.items[i].match;
548
+ if (!seen[i] && !file_exists(path)) {
549
if (ignore_missing) {
550
int dtype = DT_UNKNOWN;
553
- if (is_excluded(&dir, pathspec.raw[i], &dtype))
554
- dir_add_ignored(&dir, pathspec.raw[i], strlen(pathspec.raw[i]));
551
+ if (is_excluded(&dir, path, &dtype))
552
+ dir_add_ignored(&dir, path, pathspec.items[i].len);
553
} else
554
die(_("pathspec '%s' did not match any files"),
557
- pathspec.raw[i]);
555
+ pathspec.items[i].original);
556
}
557
}
558
free(seen);
builtin/check-ignore.c
+2
-2
@@ -94,9 +94,9 @@ static int check_ignore(struct dir_struct *dir,
94
* should not be ignored, in order to be consistent with
95
* 'git status', 'git add' etc.
96
*/
97
- seen = find_pathspecs_matching_against_index(pathspec.raw);
97
+ seen = find_pathspecs_matching_against_index(&pathspec);
98
for (i = 0; i < pathspec.nr; i++) {
99
- full_path = pathspec.raw[i];
99
+ full_path = pathspec.items[i].match;
100
exclude = NULL;
101
if (!seen[i]) {
102
exclude = last_exclude_matching(dir, full_path, &dtype);
dir.c
-107
@@ -171,113 +171,6 @@ int within_depth(const char *name, int namelen,
171
return 1;
172
}
173
174
-/*
175
- * Does 'match' match the given name?
176
- * A match is found if
177
- *
178
- * (1) the 'match' string is leading directory of 'name', or
179
- * (2) the 'match' string is a wildcard and matches 'name', or
180
- * (3) the 'match' string is exactly the same as 'name'.
181
- *
182
- * and the return value tells which case it was.
183
- *
184
- * It returns 0 when there is no match.
185
- */
186
-static int match_one(const char *match, const char *name, int namelen)
187
-{
188
- int matchlen;
189
- int literal = limit_pathspec_to_literal();
190
-
191
- /* If the match was just the prefix, we matched */
192
- if (!*match)
193
- return MATCHED_RECURSIVELY;
194
-
195
- if (ignore_case) {
196
- for (;;) {
197
- unsigned char c1 = tolower(*match);
198
- unsigned char c2 = tolower(*name);
199
- if (c1 == '\0' || (!literal && is_glob_special(c1)))
200
- break;
201
- if (c1 != c2)
202
- return 0;
203
- match++;
204
- name++;
205
- namelen--;
206
- }
207
- } else {
208
- for (;;) {
209
- unsigned char c1 = *match;
210
- unsigned char c2 = *name;
211
- if (c1 == '\0' || (!literal && is_glob_special(c1)))
212
- break;
213
- if (c1 != c2)
214
- return 0;
215
- match++;
216
- name++;
217
- namelen--;
218
- }
219
- }
220
-
221
- /*
222
- * If we don't match the matchstring exactly,
223
- * we need to match by fnmatch
224
- */
225
- matchlen = strlen(match);
226
- if (strncmp_icase(match, name, matchlen)) {
227
- if (literal)
228
- return 0;
229
- return !fnmatch_icase(match, name, 0) ? MATCHED_FNMATCH : 0;
230
- }
231
-
232
- if (namelen == matchlen)
233
- return MATCHED_EXACTLY;
234
- if (match[matchlen-1] == '/' || name[matchlen] == '/')
235
- return MATCHED_RECURSIVELY;
236
- return 0;
237
-}
238
-
239
-/*
240
- * Given a name and a list of pathspecs, returns the nature of the
241
- * closest (i.e. most specific) match of the name to any of the
242
- * pathspecs.
243
- *
244
- * The caller typically calls this multiple times with the same
245
- * pathspec and seen[] array but with different name/namelen
246
- * (e.g. entries from the index) and is interested in seeing if and
247
- * how each pathspec matches all the names it calls this function
248
- * with. A mark is left in the seen[] array for each pathspec element
249
- * indicating the closest type of match that element achieved, so if
250
- * seen[n] remains zero after multiple invocations, that means the nth
251
- * pathspec did not match any names, which could indicate that the
252
- * user mistyped the nth pathspec.
253
- */
254
-int match_pathspec(const char **pathspec, const char *name, int namelen,
255
- int prefix, char *seen)
256
-{
257
- int i, retval = 0;
258
-
259
- if (!pathspec)
260
- return 1;
261
-
262
- name += prefix;
263
- namelen -= prefix;
264
-
265
- for (i = 0; pathspec[i] != NULL; i++) {
266
- int how;
267
- const char *match = pathspec[i] + prefix;
268
- if (seen && seen[i] == MATCHED_EXACTLY)
269
- continue;
270
- how = match_one(match, name, namelen);
271
- if (how) {
272
- if (retval < how)
273
- retval = how;
274
- if (seen && seen[i] < how)
275
- seen[i] = how;
276
- }
277
- }
278
- return retval;
279
-}
280
-
174
/*
175
* Does 'match' match the given name?
176
* A match is found if
dir.h
-1
@@ -131,7 +131,6 @@ struct dir_struct {
131
extern int simple_length(const char *match);
132
extern int no_wildcard(const char *string);
133
extern char *common_prefix(const struct pathspec *pathspec);
134
-extern int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen);
134
extern int match_pathspec_depth(const struct pathspec *pathspec,
135
const char *name, int namelen,
136
int prefix, char *seen);
pathspec.c
+7
-12
@@ -15,8 +15,8 @@
15
* If seen[] has not already been written to, it may make sense
16
* to use find_pathspecs_matching_against_index() instead.
17
*/
18
-void add_pathspec_matches_against_index(const char **pathspec,
19
- char *seen, int specs)
18
+void add_pathspec_matches_against_index(const struct pathspec *pathspec,
19
+ char *seen)
20
{
21
int num_unmatched = 0, i;
22
@@ -26,14 +26,14 @@ void add_pathspec_matches_against_index(const char **pathspec,
26
* mistakenly think that the user gave a pathspec that did not match
27
* anything.
28
*/
29
- for (i = 0; i < specs; i++)
29
+ for (i = 0; i < pathspec->nr; i++)
30
if (!seen[i])
31
num_unmatched++;
32
if (!num_unmatched)
33
return;
34
for (i = 0; i < active_nr; i++) {
35
struct cache_entry *ce = active_cache[i];
36
- match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, seen);
36
+ match_pathspec_depth(pathspec, ce->name, ce_namelen(ce), 0, seen);
37
}
38
}
39
@@ -45,15 +45,10 @@ void add_pathspec_matches_against_index(const char **pathspec,
45
* nature of the "closest" (i.e. most specific) matches which each of the
46
* given pathspecs achieves against all items in the index.
47
*/
48
-char *find_pathspecs_matching_against_index(const char **pathspec)
48
+char *find_pathspecs_matching_against_index(const struct pathspec *pathspec)
49
{
50
- char *seen;
51
- int i;
52
-
53
- for (i = 0; pathspec[i]; i++)
54
- ; /* just counting */
55
- seen = xcalloc(i, 1);
56
- add_pathspec_matches_against_index(pathspec, seen, i);
50
+ char *seen = xcalloc(pathspec->nr, 1);
51
+ add_pathspec_matches_against_index(pathspec, seen);
52
return seen;
53
}
54
pathspec.h
+2
-2
@@ -63,8 +63,8 @@ extern void free_pathspec(struct pathspec *);
63
64
extern int limit_pathspec_to_literal(void);
65
66
-extern char *find_pathspecs_matching_against_index(const char **pathspec);
67
-extern void add_pathspec_matches_against_index(const char **pathspec, char *seen, int specs);
66
+extern char *find_pathspecs_matching_against_index(const struct pathspec *pathspec);
67
+extern void add_pathspec_matches_against_index(const struct pathspec *pathspec, char *seen);
68
extern const char *check_path_for_gitlink(const char *path);
69
extern void die_if_path_beyond_symlink(const char *path, const char *prefix);
70