3 #include "unpack-trees.h"
8 static const char *get_mode(const char *str
, unsigned int *modep
)
11 unsigned int mode
= 0;
16 while ((c
= *str
++) != ' ') {
17 if (c
< '0' || c
> '7')
19 mode
= (mode
<< 3) + (c
- '0');
25 static void decode_tree_entry(struct tree_desc
*desc
, const char *buf
, unsigned long size
)
28 unsigned int mode
, len
;
30 if (size
< 24 || buf
[size
- 21])
31 die("corrupt tree file");
33 path
= get_mode(buf
, &mode
);
35 die("corrupt tree file");
36 len
= strlen(path
) + 1;
38 /* Initialize the descriptor entry */
39 desc
->entry
.path
= path
;
40 desc
->entry
.mode
= canon_mode(mode
);
41 desc
->entry
.oid
= (const struct object_id
*)(path
+ len
);
44 void init_tree_desc(struct tree_desc
*desc
, const void *buffer
, unsigned long size
)
46 desc
->buffer
= buffer
;
49 decode_tree_entry(desc
, buffer
, size
);
52 void *fill_tree_descriptor(struct tree_desc
*desc
, const unsigned char *sha1
)
54 unsigned long size
= 0;
58 buf
= read_object_with_reference(sha1
, tree_type
, &size
, NULL
);
60 die("unable to read tree %s", sha1_to_hex(sha1
));
62 init_tree_desc(desc
, buf
, size
);
66 static void entry_clear(struct name_entry
*a
)
68 memset(a
, 0, sizeof(*a
));
71 static void entry_extract(struct tree_desc
*t
, struct name_entry
*a
)
76 void update_tree_entry(struct tree_desc
*desc
)
78 const void *buf
= desc
->buffer
;
79 const unsigned char *end
= desc
->entry
.oid
->hash
+ 20;
80 unsigned long size
= desc
->size
;
81 unsigned long len
= end
- (const unsigned char *)buf
;
84 die("corrupt tree file");
90 decode_tree_entry(desc
, buf
, size
);
93 int tree_entry(struct tree_desc
*desc
, struct name_entry
*entry
)
99 update_tree_entry(desc
);
103 void setup_traverse_info(struct traverse_info
*info
, const char *base
)
105 int pathlen
= strlen(base
);
106 static struct traverse_info dummy
;
108 memset(info
, 0, sizeof(*info
));
109 if (pathlen
&& base
[pathlen
-1] == '/')
111 info
->pathlen
= pathlen
? pathlen
+ 1 : 0;
112 info
->name
.path
= base
;
113 info
->name
.oid
= (void *)(base
+ pathlen
+ 1);
118 char *make_traverse_path(char *path
, const struct traverse_info
*info
, const struct name_entry
*n
)
120 int len
= tree_entry_len(n
);
121 int pathlen
= info
->pathlen
;
123 path
[pathlen
+ len
] = 0;
125 memcpy(path
+ pathlen
, n
->path
, len
);
128 path
[--pathlen
] = '/';
130 len
= tree_entry_len(n
);
137 struct tree_desc_skip
{
138 struct tree_desc_skip
*prev
;
144 struct tree_desc_skip
*skip
;
147 static int check_entry_match(const char *a
, int a_len
, const char *b
, int b_len
)
150 * The caller wants to pick *a* from a tree or nothing.
151 * We are looking at *b* in a tree.
153 * (0) If a and b are the same name, we are trivially happy.
155 * There are three possibilities where *a* could be hiding
158 * (1) *a* == "t", *b* == "ab" i.e. *b* sorts earlier than *a* no
160 * (2) *a* == "t", *b* == "t-2" and "t" is a subtree in the tree;
161 * (3) *a* == "t-2", *b* == "t" and "t-2" is a blob in the tree.
163 * Otherwise we know *a* won't appear in the tree without
167 int cmp
= name_compare(a
, a_len
, b
, b_len
);
169 /* Most common case first -- reading sync'd trees */
174 /* a comes after b; it does not matter if it is case (3)
175 if (b_len < a_len && !memcmp(a, b, b_len) && a[b_len] < '/')
178 return 1; /* keep looking */
181 /* b comes after a; are we looking at case (2)? */
182 if (a_len
< b_len
&& !memcmp(a
, b
, a_len
) && b
[a_len
] < '/')
183 return 1; /* keep looking */
185 return -1; /* a cannot appear in the tree */
189 * From the extended tree_desc, extract the first name entry, while
190 * paying attention to the candidate "first" name. Most importantly,
191 * when looking for an entry, if there are entries that sorts earlier
192 * in the tree object representation than that name, skip them and
193 * process the named entry first. We will remember that we haven't
194 * processed the first entry yet, and in the later call skip the
195 * entry we processed early when update_extended_entry() is called.
197 * E.g. if the underlying tree object has these entries:
204 * and the "first" asks for "t", remember that we still need to
205 * process "t-1" and "t-2" but extract "t". After processing the
206 * entry "t" from this call, the caller will let us know by calling
207 * update_extended_entry() that we can remember "t" has been processed
211 static void extended_entry_extract(struct tree_desc_x
*t
,
212 struct name_entry
*a
,
218 struct tree_desc probe
;
219 struct tree_desc_skip
*skip
;
222 * Extract the first entry from the tree_desc, but skip the
223 * ones that we already returned in earlier rounds.
228 break; /* not found */
230 entry_extract(&t
->d
, a
);
231 for (skip
= t
->skip
; skip
; skip
= skip
->prev
)
232 if (a
->path
== skip
->ptr
)
236 /* We have processed this entry already. */
237 update_tree_entry(&t
->d
);
240 if (!first
|| !a
->path
)
244 * The caller wants "first" from this tree, or nothing.
247 len
= tree_entry_len(a
);
248 switch (check_entry_match(first
, first_len
, path
, len
)) {
258 * We need to look-ahead -- we suspect that a subtree whose
259 * name is "first" may be hiding behind the current entry "path".
263 entry_extract(&probe
, a
);
265 len
= tree_entry_len(a
);
266 switch (check_entry_match(first
, first_len
, path
, len
)) {
272 update_tree_entry(&probe
);
280 static void update_extended_entry(struct tree_desc_x
*t
, struct name_entry
*a
)
282 if (t
->d
.entry
.path
== a
->path
) {
283 update_tree_entry(&t
->d
);
285 /* we have returned this entry early */
286 struct tree_desc_skip
*skip
= xmalloc(sizeof(*skip
));
288 skip
->prev
= t
->skip
;
293 static void free_extended_entry(struct tree_desc_x
*t
)
295 struct tree_desc_skip
*p
, *s
;
297 for (s
= t
->skip
; s
; s
= p
) {
303 static inline int prune_traversal(struct name_entry
*e
,
304 struct traverse_info
*info
,
306 int still_interesting
)
308 if (!info
->pathspec
|| still_interesting
== 2)
310 if (still_interesting
< 0)
311 return still_interesting
;
312 return tree_entry_interesting(e
, base
, 0, info
->pathspec
);
315 int traverse_trees(int n
, struct tree_desc
*t
, struct traverse_info
*info
)
318 struct name_entry
*entry
= xmalloc(n
*sizeof(*entry
));
320 struct tree_desc_x
*tx
= xcalloc(n
, sizeof(*tx
));
321 struct strbuf base
= STRBUF_INIT
;
325 for (i
= 0; i
< n
; i
++)
329 strbuf_grow(&base
, info
->pathlen
);
330 make_traverse_path(base
.buf
, info
->prev
, &info
->name
);
331 base
.buf
[info
->pathlen
-1] = '/';
332 strbuf_setlen(&base
, info
->pathlen
);
333 traverse_path
= xstrndup(base
.buf
, info
->pathlen
);
335 traverse_path
= xstrndup(info
->name
.path
, info
->pathlen
);
337 info
->traverse_path
= traverse_path
;
340 unsigned long mask
, dirmask
;
341 const char *first
= NULL
;
343 struct name_entry
*e
= NULL
;
346 for (i
= 0; i
< n
; i
++) {
348 extended_entry_extract(tx
+ i
, e
, NULL
, 0);
352 * A tree may have "t-2" at the current location even
353 * though it may have "t" that is a subtree behind it,
354 * and another tree may return "t". We want to grab
355 * all "t" from all trees to match in such a case.
357 for (i
= 0; i
< n
; i
++) {
361 len
= tree_entry_len(e
);
367 if (name_compare(e
->path
, len
, first
, first_len
) < 0) {
374 for (i
= 0; i
< n
; i
++) {
376 extended_entry_extract(tx
+ i
, e
, first
, first_len
);
377 /* Cull the ones that are not the earliest */
380 len
= tree_entry_len(e
);
381 if (name_compare(e
->path
, len
, first
, first_len
))
386 /* Now we have in entry[i] the earliest name from the trees */
389 for (i
= 0; i
< n
; i
++) {
393 if (S_ISDIR(entry
[i
].mode
))
399 interesting
= prune_traversal(e
, info
, &base
, interesting
);
403 trees_used
= info
->fn(n
, mask
, dirmask
, entry
, info
);
404 if (trees_used
< 0) {
406 if (!info
->show_all_errors
)
411 for (i
= 0; i
< n
; i
++)
412 if (mask
& (1ul << i
))
413 update_extended_entry(tx
+ i
, entry
+ i
);
416 for (i
= 0; i
< n
; i
++)
417 free_extended_entry(tx
+ i
);
420 info
->traverse_path
= NULL
;
421 strbuf_release(&base
);
428 unsigned char sha1
[20];
431 static int find_tree_entry(struct tree_desc
*t
, const char *name
, unsigned char *result
, unsigned *mode
)
433 int namelen
= strlen(name
);
436 const struct object_id
*oid
;
439 oid
= tree_entry_extract(t
, &entry
, mode
);
440 entrylen
= tree_entry_len(&t
->entry
);
441 update_tree_entry(t
);
442 if (entrylen
> namelen
)
444 cmp
= memcmp(name
, entry
, entrylen
);
449 if (entrylen
== namelen
) {
450 hashcpy(result
, oid
->hash
);
453 if (name
[entrylen
] != '/')
457 if (++entrylen
== namelen
) {
458 hashcpy(result
, oid
->hash
);
461 return get_tree_entry(oid
->hash
, name
+ entrylen
, result
, mode
);
466 int get_tree_entry(const unsigned char *tree_sha1
, const char *name
, unsigned char *sha1
, unsigned *mode
)
471 unsigned char root
[20];
473 tree
= read_object_with_reference(tree_sha1
, tree_type
, &size
, root
);
477 if (name
[0] == '\0') {
487 init_tree_desc(&t
, tree
, size
);
488 retval
= find_tree_entry(&t
, name
, sha1
, mode
);
495 * This is Linux's built-in max for the number of symlinks to follow.
496 * That limit, of course, does not affect git, but it's a reasonable
499 #define GET_TREE_ENTRY_FOLLOW_SYMLINKS_MAX_LINKS 40
502 * Find a tree entry by following symlinks in tree_sha (which is
503 * assumed to be the root of the repository). In the event that a
504 * symlink points outside the repository (e.g. a link to /foo or a
505 * root-level link to ../foo), the portion of the link which is
506 * outside the repository will be returned in result_path, and *mode
507 * will be set to 0. It is assumed that result_path is uninitialized.
508 * If there are no symlinks, or the end result of the symlink chain
509 * points to an object inside the repository, result will be filled in
510 * with the sha1 of the found object, and *mode will hold the mode of
513 * See the code for enum follow_symlink_result for a description of
516 enum follow_symlinks_result
get_tree_entry_follow_symlinks(unsigned char *tree_sha1
, const char *name
, unsigned char *result
, struct strbuf
*result_path
, unsigned *mode
)
518 int retval
= MISSING_OBJECT
;
519 struct dir_state
*parents
= NULL
;
520 size_t parents_alloc
= 0;
521 ssize_t parents_nr
= 0;
522 unsigned char current_tree_sha1
[20];
523 struct strbuf namebuf
= STRBUF_INIT
;
525 int follows_remaining
= GET_TREE_ENTRY_FOLLOW_SYMLINKS_MAX_LINKS
;
528 init_tree_desc(&t
, NULL
, 0UL);
529 strbuf_init(result_path
, 0);
530 strbuf_addstr(&namebuf
, name
);
531 hashcpy(current_tree_sha1
, tree_sha1
);
536 char *remainder
= NULL
;
540 unsigned char root
[20];
542 tree
= read_object_with_reference(current_tree_sha1
,
548 ALLOC_GROW(parents
, parents_nr
+ 1, parents_alloc
);
549 parents
[parents_nr
].tree
= tree
;
550 parents
[parents_nr
].size
= size
;
551 hashcpy(parents
[parents_nr
].sha1
, root
);
554 if (namebuf
.buf
[0] == '\0') {
555 hashcpy(result
, root
);
564 init_tree_desc(&t
, tree
, size
);
567 /* Handle symlinks to e.g. a//b by removing leading slashes */
568 while (namebuf
.buf
[0] == '/') {
569 strbuf_remove(&namebuf
, 0, 1);
572 /* Split namebuf into a first component and a remainder */
573 if ((first_slash
= strchr(namebuf
.buf
, '/'))) {
575 remainder
= first_slash
+ 1;
578 if (!strcmp(namebuf
.buf
, "..")) {
579 struct dir_state
*parent
;
581 * We could end up with .. in the namebuf if it
582 * appears in a symlink.
585 if (parents_nr
== 1) {
588 strbuf_add(result_path
, namebuf
.buf
,
594 parent
= &parents
[parents_nr
- 1];
597 parent
= &parents
[parents_nr
- 1];
598 init_tree_desc(&t
, parent
->tree
, parent
->size
);
599 strbuf_remove(&namebuf
, 0, remainder
? 3 : 2);
603 /* We could end up here via a symlink to dir/.. */
604 if (namebuf
.buf
[0] == '\0') {
605 hashcpy(result
, parents
[parents_nr
- 1].sha1
);
610 /* Look up the first (or only) path component in the tree. */
611 find_result
= find_tree_entry(&t
, namebuf
.buf
,
612 current_tree_sha1
, mode
);
617 if (S_ISDIR(*mode
)) {
619 hashcpy(result
, current_tree_sha1
);
623 /* Descend the tree */
625 strbuf_remove(&namebuf
, 0,
626 1 + first_slash
- namebuf
.buf
);
627 } else if (S_ISREG(*mode
)) {
629 hashcpy(result
, current_tree_sha1
);
635 } else if (S_ISLNK(*mode
)) {
636 /* Follow a symlink */
637 unsigned long link_len
;
639 char *contents
, *contents_start
;
640 struct dir_state
*parent
;
641 enum object_type type
;
643 if (follows_remaining
-- == 0) {
644 /* Too many symlinks followed */
645 retval
= SYMLINK_LOOP
;
650 * At this point, we have followed at a least
651 * one symlink, so on error we need to report this.
653 retval
= DANGLING_SYMLINK
;
655 contents
= read_sha1_file(current_tree_sha1
, &type
,
661 if (contents
[0] == '/') {
662 strbuf_addstr(result_path
, contents
);
670 len
= first_slash
- namebuf
.buf
;
674 contents_start
= contents
;
676 parent
= &parents
[parents_nr
- 1];
677 init_tree_desc(&t
, parent
->tree
, parent
->size
);
678 strbuf_splice(&namebuf
, 0, len
,
679 contents_start
, link_len
);
681 namebuf
.buf
[link_len
] = '/';
686 for (i
= 0; i
< parents_nr
; i
++)
687 free(parents
[i
].tree
);
690 strbuf_release(&namebuf
);
694 static int match_entry(const struct pathspec_item
*item
,
695 const struct name_entry
*entry
, int pathlen
,
696 const char *match
, int matchlen
,
697 enum interesting
*never_interesting
)
699 int m
= -1; /* signals that we haven't called strncmp() */
701 if (item
->magic
& PATHSPEC_ICASE
)
703 * "Never interesting" trick requires exact
704 * matching. We could do something clever with inexact
705 * matching, but it's trickier (and not to forget that
706 * strcasecmp is locale-dependent, at least in
707 * glibc). Just disable it for now. It can't be worse
708 * than the wildcard's codepath of '[Tt][Hi][Is][Ss]'
711 *never_interesting
= entry_not_interesting
;
712 else if (*never_interesting
!= entry_not_interesting
) {
714 * We have not seen any match that sorts later
715 * than the current path.
719 * Does match sort strictly earlier than path
720 * with their common parts?
722 m
= strncmp(match
, entry
->path
,
723 (matchlen
< pathlen
) ? matchlen
: pathlen
);
728 * If we come here even once, that means there is at
729 * least one pathspec that would sort equal to or
730 * later than the path we are currently looking at.
731 * In other words, if we have never reached this point
732 * after iterating all pathspecs, it means all
733 * pathspecs are either outside of base, or inside the
734 * base but sorts strictly earlier than the current
735 * one. In either case, they will never match the
736 * subsequent entries. In such a case, we initialized
737 * the variable to -1 and that is what will be
738 * returned, allowing the caller to terminate early.
740 *never_interesting
= entry_not_interesting
;
743 if (pathlen
> matchlen
)
746 if (matchlen
> pathlen
) {
747 if (match
[pathlen
] != '/')
749 if (!S_ISDIR(entry
->mode
) && !S_ISGITLINK(entry
->mode
))
755 * we cheated and did not do strncmp(), so we do
758 m
= ps_strncmp(item
, match
, entry
->path
, pathlen
);
761 * If common part matched earlier then it is a hit,
762 * because we rejected the case where path is not a
763 * leading directory and is shorter than match.
767 * match_entry does not check if the prefix part is
768 * matched case-sensitively. If the entry is a
769 * directory and part of prefix, it'll be rematched
770 * eventually by basecmp with special treatment for
778 /* :(icase)-aware string compare */
779 static int basecmp(const struct pathspec_item
*item
,
780 const char *base
, const char *match
, int len
)
782 if (item
->magic
& PATHSPEC_ICASE
) {
783 int ret
, n
= len
> item
->prefix
? item
->prefix
: len
;
784 ret
= strncmp(base
, match
, n
);
791 return ps_strncmp(item
, base
, match
, len
);
794 static int match_dir_prefix(const struct pathspec_item
*item
,
796 const char *match
, int matchlen
)
798 if (basecmp(item
, base
, match
, matchlen
))
802 * If the base is a subdirectory of a path which
803 * was specified, all of them are interesting.
806 base
[matchlen
] == '/' ||
807 match
[matchlen
- 1] == '/')
810 /* Just a random prefix match */
815 * Perform matching on the leading non-wildcard part of
816 * pathspec. item->nowildcard_len must be greater than zero. Return
817 * non-zero if base is matched.
819 static int match_wildcard_base(const struct pathspec_item
*item
,
820 const char *base
, int baselen
,
823 const char *match
= item
->match
;
824 /* the wildcard part is not considered in this function */
825 int matchlen
= item
->nowildcard_len
;
830 * Return early if base is longer than the
831 * non-wildcard part but it does not match.
833 if (baselen
>= matchlen
) {
835 return !basecmp(item
, base
, match
, matchlen
);
839 while (dirlen
&& match
[dirlen
- 1] != '/')
843 * Return early if base is shorter than the
844 * non-wildcard part but it does not match. Note that
845 * base ends with '/' so we are sure it really matches
848 if (basecmp(item
, base
, match
, baselen
))
854 * we could have checked entry against the non-wildcard part
855 * that is not in base and does similar never_interesting
856 * optimization as in match_entry. For now just be happy with
859 return entry_interesting
;
863 * Is a tree entry interesting given the pathspec we have?
865 * Pre-condition: either baselen == base_offset (i.e. empty path)
866 * or base[baselen-1] == '/' (i.e. with trailing slash).
868 static enum interesting
do_match(const struct name_entry
*entry
,
869 struct strbuf
*base
, int base_offset
,
870 const struct pathspec
*ps
,
874 int pathlen
, baselen
= base
->len
- base_offset
;
875 enum interesting never_interesting
= ps
->has_wildcard
?
876 entry_not_interesting
: all_entries_not_interesting
;
887 if (!ps
->recursive
||
888 !(ps
->magic
& PATHSPEC_MAXDEPTH
) ||
890 return all_entries_interesting
;
891 return within_depth(base
->buf
+ base_offset
, baselen
,
892 !!S_ISDIR(entry
->mode
),
894 entry_interesting
: entry_not_interesting
;
897 pathlen
= tree_entry_len(entry
);
899 for (i
= ps
->nr
- 1; i
>= 0; i
--) {
900 const struct pathspec_item
*item
= ps
->items
+i
;
901 const char *match
= item
->match
;
902 const char *base_str
= base
->buf
+ base_offset
;
903 int matchlen
= item
->len
, matched
= 0;
905 if ((!exclude
&& item
->magic
& PATHSPEC_EXCLUDE
) ||
906 ( exclude
&& !(item
->magic
& PATHSPEC_EXCLUDE
)))
909 if (baselen
>= matchlen
) {
910 /* If it doesn't match, move along... */
911 if (!match_dir_prefix(item
, base_str
, match
, matchlen
))
912 goto match_wildcards
;
914 if (!ps
->recursive
||
915 !(ps
->magic
& PATHSPEC_MAXDEPTH
) ||
917 return all_entries_interesting
;
919 return within_depth(base_str
+ matchlen
+ 1,
920 baselen
- matchlen
- 1,
921 !!S_ISDIR(entry
->mode
),
923 entry_interesting
: entry_not_interesting
;
926 /* Either there must be no base, or the base must match. */
927 if (baselen
== 0 || !basecmp(item
, base_str
, match
, baselen
)) {
928 if (match_entry(item
, entry
, pathlen
,
929 match
+ baselen
, matchlen
- baselen
,
931 return entry_interesting
;
933 if (item
->nowildcard_len
< item
->len
) {
934 if (!git_fnmatch(item
, match
+ baselen
, entry
->path
,
935 item
->nowildcard_len
- baselen
))
936 return entry_interesting
;
939 * Match all directories. We'll try to
940 * match files later on.
942 if (ps
->recursive
&& S_ISDIR(entry
->mode
))
943 return entry_interesting
;
950 if (item
->nowildcard_len
== item
->len
)
953 if (item
->nowildcard_len
&&
954 !match_wildcard_base(item
, base_str
, baselen
, &matched
))
958 * Concatenate base and entry->path into one and do
961 * While we could avoid concatenation in certain cases
962 * [1], which saves a memcpy and potentially a
963 * realloc, it turns out not worth it. Measurement on
964 * linux-2.6 does not show any clear improvements,
965 * partly because of the nowildcard_len optimization
966 * in git_fnmatch(). Avoid micro-optimizations here.
968 * [1] if match_wildcard_base() says the base
969 * directory is already matched, we only need to match
970 * the rest, which is shorter so _in theory_ faster.
973 strbuf_add(base
, entry
->path
, pathlen
);
975 if (!git_fnmatch(item
, match
, base
->buf
+ base_offset
,
976 item
->nowildcard_len
)) {
977 strbuf_setlen(base
, base_offset
+ baselen
);
978 return entry_interesting
;
980 strbuf_setlen(base
, base_offset
+ baselen
);
983 * Match all directories. We'll try to match files
985 * max_depth is ignored but we may consider support it
987 * http://thread.gmane.org/gmane.comp.version-control.git/163757/focus=163840
989 if (ps
->recursive
&& S_ISDIR(entry
->mode
))
990 return entry_interesting
;
992 return never_interesting
; /* No matches */
996 * Is a tree entry interesting given the pathspec we have?
998 * Pre-condition: either baselen == base_offset (i.e. empty path)
999 * or base[baselen-1] == '/' (i.e. with trailing slash).
1001 enum interesting
tree_entry_interesting(const struct name_entry
*entry
,
1002 struct strbuf
*base
, int base_offset
,
1003 const struct pathspec
*ps
)
1005 enum interesting positive
, negative
;
1006 positive
= do_match(entry
, base
, base_offset
, ps
, 0);
1009 * case | entry | positive | negative | result
1010 * -----+-------+----------+----------+-------
1011 * 1 | file | -1 | -1..2 | -1
1012 * 2 | file | 0 | -1..2 | 0
1013 * 3 | file | 1 | -1 | 1
1014 * 4 | file | 1 | 0 | 1
1015 * 5 | file | 1 | 1 | 0
1016 * 6 | file | 1 | 2 | 0
1017 * 7 | file | 2 | -1 | 2
1018 * 8 | file | 2 | 0 | 2
1019 * 9 | file | 2 | 1 | 0
1020 * 10 | file | 2 | 2 | -1
1021 * -----+-------+----------+----------+-------
1022 * 11 | dir | -1 | -1..2 | -1
1023 * 12 | dir | 0 | -1..2 | 0
1024 * 13 | dir | 1 | -1 | 1
1025 * 14 | dir | 1 | 0 | 1
1026 * 15 | dir | 1 | 1 | 1 (*)
1027 * 16 | dir | 1 | 2 | 0
1028 * 17 | dir | 2 | -1 | 2
1029 * 18 | dir | 2 | 0 | 2
1030 * 19 | dir | 2 | 1 | 1 (*)
1031 * 20 | dir | 2 | 2 | -1
1033 * (*) An exclude pattern interested in a directory does not
1034 * necessarily mean it will exclude all of the directory. In
1035 * wildcard case, it can't decide until looking at individual
1036 * files inside. So don't write such directories off yet.
1039 if (!(ps
->magic
& PATHSPEC_EXCLUDE
) ||
1040 positive
<= entry_not_interesting
) /* #1, #2, #11, #12 */
1043 negative
= do_match(entry
, base
, base_offset
, ps
, 1);
1045 /* #3, #4, #7, #8, #13, #14, #17, #18 */
1046 if (negative
<= entry_not_interesting
)
1050 if (S_ISDIR(entry
->mode
) &&
1051 positive
>= entry_interesting
&&
1052 negative
== entry_interesting
)
1053 return entry_interesting
;
1055 if ((positive
== entry_interesting
&&
1056 negative
>= entry_interesting
) || /* #5, #6, #16 */
1057 (positive
== all_entries_interesting
&&
1058 negative
== entry_interesting
)) /* #9 */
1059 return entry_not_interesting
;
1061 return all_entries_not_interesting
; /* #10, #20 */