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

Commit 42b0874

Browse files
pcloudsgitster
authored andcommitted
dir.c: prepare match_pathspec_item for taking more flags
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 854b095 commit 42b0874

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

dir.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ int within_depth(const char *name, int namelen,
195195
return 1;
196196
}
197197

198+
#define DO_MATCH_EXCLUDE 1
199+
198200
/*
199201
* Does 'match' match the given name?
200202
* A match is found if
@@ -208,7 +210,7 @@ int within_depth(const char *name, int namelen,
208210
* It returns 0 when there is no match.
209211
*/
210212
static int match_pathspec_item(const struct pathspec_item *item, int prefix,
211-
const char *name, int namelen)
213+
const char *name, int namelen, unsigned flags)
212214
{
213215
/* name/namelen has prefix cut off by caller */
214216
const char *match = item->match + prefix;
@@ -285,9 +287,9 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,
285287
static int do_match_pathspec(const struct pathspec *ps,
286288
const char *name, int namelen,
287289
int prefix, char *seen,
288-
int exclude)
290+
unsigned flags)
289291
{
290-
int i, retval = 0;
292+
int i, retval = 0, exclude = flags & DO_MATCH_EXCLUDE;
291293

292294
GUARD_PATHSPEC(ps,
293295
PATHSPEC_FROMTOP |
@@ -327,7 +329,8 @@ static int do_match_pathspec(const struct pathspec *ps,
327329
*/
328330
if (seen && ps->items[i].magic & PATHSPEC_EXCLUDE)
329331
seen[i] = MATCHED_FNMATCH;
330-
how = match_pathspec_item(ps->items+i, prefix, name, namelen);
332+
how = match_pathspec_item(ps->items+i, prefix, name,
333+
namelen, flags);
331334
if (ps->recursive &&
332335
(ps->magic & PATHSPEC_MAXDEPTH) &&
333336
ps->max_depth != -1 &&
@@ -355,10 +358,14 @@ int match_pathspec(const struct pathspec *ps,
355358
int prefix, char *seen)
356359
{
357360
int positive, negative;
358-
positive = do_match_pathspec(ps, name, namelen, prefix, seen, 0);
361+
unsigned flags = 0;
362+
positive = do_match_pathspec(ps, name, namelen,
363+
prefix, seen, flags);
359364
if (!(ps->magic & PATHSPEC_EXCLUDE) || !positive)
360365
return positive;
361-
negative = do_match_pathspec(ps, name, namelen, prefix, seen, 1);
366+
negative = do_match_pathspec(ps, name, namelen,
367+
prefix, seen,
368+
flags | DO_MATCH_EXCLUDE);
362369
return negative ? 0 : positive;
363370
}
364371

0 commit comments

Comments
 (0)