dir.c: prepare match_pathspec_item for taking more flags

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 Jan 24, 2014 at 20:40 UTC 42b0874a7ef66f9bd561c66df6e989f58d0393b9
1 file changed +13 -6
dir.c
+13 -6
@@ -195,6 +195,8 @@ int within_depth(const char *name, int namelen,
195 return 1;
196 }
197
198 +#define DO_MATCH_EXCLUDE 1
199 +
200 /*
201 * Does 'match' match the given name?
202 * A match is found if
@@ -208,7 +210,7 @@ int within_depth(const char *name, int namelen,
210 * It returns 0 when there is no match.
211 */
212 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)
214 {
215 /* name/namelen has prefix cut off by caller */
216 const char *match = item->match + prefix;
@@ -285,9 +287,9 @@ static int match_pathspec_item(const struct pathspec_item *item, int prefix,
287 static int do_match_pathspec(const struct pathspec *ps,
288 const char *name, int namelen,
289 int prefix, char *seen,
288 - int exclude)
290 + unsigned flags)
291 {
290 - int i, retval = 0;
292 + int i, retval = 0, exclude = flags & DO_MATCH_EXCLUDE;
293
294 GUARD_PATHSPEC(ps,
295 PATHSPEC_FROMTOP |
@@ -327,7 +329,8 @@ static int do_match_pathspec(const struct pathspec *ps,
329 */
330 if (seen && ps->items[i].magic & PATHSPEC_EXCLUDE)
331 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);
334 if (ps->recursive &&
335 (ps->magic & PATHSPEC_MAXDEPTH) &&
336 ps->max_depth != -1 &&
@@ -355,10 +358,14 @@ int match_pathspec(const struct pathspec *ps,
358 int prefix, char *seen)
359 {
360 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);
364 if (!(ps->magic & PATHSPEC_EXCLUDE) || !positive)
365 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);
369 return negative ? 0 : positive;
370 }
371