1 #define USE_THE_REPOSITORY_VARIABLE
2 #define DISABLE_SIGN_COMPARE_WARNINGS
4 #include "git-compat-util.h"
8 #include "environment.h"
12 #include "read-cache.h"
13 #include "repository.h"
18 #include "wildmatch.h"
21 * Finds which of the given pathspecs match items in the index.
23 * For each pathspec, sets the corresponding entry in the seen[] array
24 * (which should be specs items long, i.e. the same size as pathspec)
25 * to the nature of the "closest" (i.e. most specific) match found for
26 * that pathspec in the index, if it was a closer type of match than
27 * the existing entry. As an optimization, matching is skipped
28 * altogether if seen[] already only contains non-zero entries.
30 * If seen[] has not already been written to, it may make sense
31 * to use find_pathspecs_matching_against_index() instead.
33 void add_pathspec_matches_against_index(const struct pathspec
*pathspec
,
34 struct index_state
*istate
,
36 enum ps_skip_worktree_action sw_action
)
38 int num_unmatched
= 0, i
;
41 * Since we are walking the index as if we were walking the directory,
42 * we have to mark the matched pathspec as seen; otherwise we will
43 * mistakenly think that the user gave a pathspec that did not match
46 for (i
= 0; i
< pathspec
->nr
; i
++)
51 for (i
= 0; i
< istate
->cache_nr
; i
++) {
52 const struct cache_entry
*ce
= istate
->cache
[i
];
53 if (sw_action
== PS_IGNORE_SKIP_WORKTREE
&&
54 (ce_skip_worktree(ce
) || !path_in_sparse_checkout(ce
->name
, istate
)))
56 ce_path_match(istate
, ce
, pathspec
, seen
);
61 * Finds which of the given pathspecs match items in the index.
63 * This is a one-shot wrapper around add_pathspec_matches_against_index()
64 * which allocates, populates, and returns a seen[] array indicating the
65 * nature of the "closest" (i.e. most specific) matches which each of the
66 * given pathspecs achieves against all items in the index.
68 char *find_pathspecs_matching_against_index(const struct pathspec
*pathspec
,
69 struct index_state
*istate
,
70 enum ps_skip_worktree_action sw_action
)
72 char *seen
= xcalloc(pathspec
->nr
, 1);
73 add_pathspec_matches_against_index(pathspec
, istate
, seen
, sw_action
);
77 char *find_pathspecs_matching_skip_worktree(const struct pathspec
*pathspec
)
79 struct index_state
*istate
= the_repository
->index
;
80 char *seen
= xcalloc(pathspec
->nr
, 1);
83 for (i
= 0; i
< istate
->cache_nr
; i
++) {
84 struct cache_entry
*ce
= istate
->cache
[i
];
85 if (ce_skip_worktree(ce
) || !path_in_sparse_checkout(ce
->name
, istate
))
86 ce_path_match(istate
, ce
, pathspec
, seen
);
95 * Possible future magic semantics include stuff like:
97 * { PATHSPEC_RECURSIVE, '*', "recursive" },
98 * { PATHSPEC_REGEXP, '\0', "regexp" },
102 static struct pathspec_magic
{
104 char mnemonic
; /* this cannot be ':'! */
106 } pathspec_magic
[] = {
107 { PATHSPEC_FROMTOP
, '/', "top" },
108 { PATHSPEC_LITERAL
, '\0', "literal" },
109 { PATHSPEC_GLOB
, '\0', "glob" },
110 { PATHSPEC_ICASE
, '\0', "icase" },
111 { PATHSPEC_EXCLUDE
, '!', "exclude" },
112 { PATHSPEC_ATTR
, '\0', "attr" },
115 static void prefix_magic(struct strbuf
*sb
, int prefixlen
,
116 unsigned magic
, const char *element
)
118 /* No magic was found in element, just add prefix magic */
120 strbuf_addf(sb
, ":(prefix:%d)", prefixlen
);
125 * At this point, we know that parse_element_magic() was able
126 * to extract some pathspec magic from element. So we know
127 * element is correctly formatted in either shorthand or
130 if (element
[1] != '(') {
131 /* Process an element in shorthand form (e.g. ":!/<match>") */
132 strbuf_addstr(sb
, ":(");
133 for (int i
= 0; i
< ARRAY_SIZE(pathspec_magic
); i
++) {
134 if ((magic
& pathspec_magic
[i
].bit
) &&
135 pathspec_magic
[i
].mnemonic
) {
136 if (sb
->buf
[sb
->len
- 1] != '(')
137 strbuf_addch(sb
, ',');
138 strbuf_addstr(sb
, pathspec_magic
[i
].name
);
142 /* For the longhand form, we copy everything up to the final ')' */
143 size_t len
= strchr(element
, ')') - element
;
144 strbuf_add(sb
, element
, len
);
146 strbuf_addf(sb
, ",prefix:%d)", prefixlen
);
149 static size_t strcspn_escaped(const char *s
, const char *stop
)
153 for (i
= s
; *i
; i
++) {
154 /* skip the escaped character */
155 if (i
[0] == '\\' && i
[1]) {
160 if (strchr(stop
, *i
))
166 static inline int invalid_value_char(const char ch
)
168 if (isalnum(ch
) || strchr(",-_", ch
))
173 static char *attr_value_unescape(const char *value
)
178 ret
= xmallocz(strlen(value
));
179 for (src
= value
, dst
= ret
; *src
; src
++, dst
++) {
182 die(_("Escape character '\\' not allowed as "
183 "last character in attr value"));
186 if (invalid_value_char(*src
))
187 die("cannot use '%c' for value matching", *src
);
194 static void parse_pathspec_attr_match(struct pathspec_item
*item
, const char *value
)
196 struct string_list_item
*si
;
197 struct string_list list
= STRING_LIST_INIT_DUP
;
199 if (item
->attr_check
|| item
->attr_match
)
200 die(_("Only one 'attr:' specification is allowed."));
202 if (!value
|| !*value
)
203 die(_("attr spec must not be empty"));
205 string_list_split(&list
, value
, ' ', -1);
206 string_list_remove_empty_items(&list
, 0);
208 item
->attr_check
= attr_check_alloc();
209 CALLOC_ARRAY(item
->attr_match
, list
.nr
);
211 for_each_string_list_item(si
, &list
) {
214 const struct git_attr
*a
;
216 int j
= item
->attr_match_nr
++;
217 const char *attr
= si
->string
;
218 struct attr_match
*am
= &item
->attr_match
[j
];
222 am
->match_mode
= MATCH_UNSPECIFIED
;
224 attr_len
= strlen(attr
);
227 am
->match_mode
= MATCH_UNSET
;
229 attr_len
= strlen(attr
);
232 attr_len
= strcspn(attr
, "=");
233 if (attr
[attr_len
] != '=')
234 am
->match_mode
= MATCH_SET
;
236 const char *v
= &attr
[attr_len
+ 1];
237 am
->match_mode
= MATCH_VALUE
;
238 am
->value
= attr_value_unescape(v
);
243 attr_name
= xmemdupz(attr
, attr_len
);
244 a
= git_attr(attr_name
);
246 die(_("invalid attribute name %s"), attr_name
);
248 attr_check_append(item
->attr_check
, a
);
253 if (item
->attr_check
->nr
!= item
->attr_match_nr
)
254 BUG("should have same number of entries");
256 string_list_clear(&list
, 0);
259 static inline int get_literal_global(void)
261 static int literal
= -1;
264 literal
= git_env_bool(GIT_LITERAL_PATHSPECS_ENVIRONMENT
, 0);
269 static inline int get_glob_global(void)
271 static int glob
= -1;
274 glob
= git_env_bool(GIT_GLOB_PATHSPECS_ENVIRONMENT
, 0);
279 static inline int get_noglob_global(void)
281 static int noglob
= -1;
284 noglob
= git_env_bool(GIT_NOGLOB_PATHSPECS_ENVIRONMENT
, 0);
289 static inline int get_icase_global(void)
291 static int icase
= -1;
294 icase
= git_env_bool(GIT_ICASE_PATHSPECS_ENVIRONMENT
, 0);
299 static int get_global_magic(int element_magic
)
301 int global_magic
= 0;
303 if (get_literal_global())
304 global_magic
|= PATHSPEC_LITERAL
;
306 /* --glob-pathspec is overridden by :(literal) */
307 if (get_glob_global() && !(element_magic
& PATHSPEC_LITERAL
))
308 global_magic
|= PATHSPEC_GLOB
;
310 if (get_glob_global() && get_noglob_global())
311 die(_("global 'glob' and 'noglob' pathspec settings are incompatible"));
313 if (get_icase_global())
314 global_magic
|= PATHSPEC_ICASE
;
316 if ((global_magic
& PATHSPEC_LITERAL
) &&
317 (global_magic
& ~PATHSPEC_LITERAL
))
318 die(_("global 'literal' pathspec setting is incompatible "
319 "with all other global pathspec settings"));
321 /* --noglob-pathspec adds :(literal) _unless_ :(glob) is specified */
322 if (get_noglob_global() && !(element_magic
& PATHSPEC_GLOB
))
323 global_magic
|= PATHSPEC_LITERAL
;
329 * Parse the pathspec element looking for long magic
331 * saves all magic in 'magic'
332 * if prefix magic is used, save the prefix length in 'prefix_len'
333 * returns the position in 'elem' after all magic has been parsed
335 static const char *parse_long_magic(unsigned *magic
, int *prefix_len
,
336 struct pathspec_item
*item
,
342 for (pos
= elem
+ 2; *pos
&& *pos
!= ')'; pos
= nextat
) {
343 size_t len
= strcspn_escaped(pos
, ",)");
347 nextat
= pos
+ len
+ 1; /* handle ',' */
349 nextat
= pos
+ len
; /* handle ')' and '\0' */
354 if (starts_with(pos
, "prefix:")) {
356 *prefix_len
= strtol(pos
+ 7, &endptr
, 10);
357 if (endptr
- pos
!= len
)
358 die(_("invalid parameter for pathspec magic 'prefix'"));
362 if (starts_with(pos
, "attr:")) {
363 char *attr_body
= xmemdupz(pos
+ 5, len
- 5);
364 parse_pathspec_attr_match(item
, attr_body
);
365 *magic
|= PATHSPEC_ATTR
;
370 for (i
= 0; i
< ARRAY_SIZE(pathspec_magic
); i
++) {
371 if (strlen(pathspec_magic
[i
].name
) == len
&&
372 !strncmp(pathspec_magic
[i
].name
, pos
, len
)) {
373 *magic
|= pathspec_magic
[i
].bit
;
378 if (ARRAY_SIZE(pathspec_magic
) <= i
)
379 die(_("Invalid pathspec magic '%.*s' in '%s'"),
380 (int) len
, pos
, elem
);
384 die(_("Missing ')' at the end of pathspec magic in '%s'"),
392 * Parse the pathspec element looking for short magic
394 * saves all magic in 'magic'
395 * returns the position in 'elem' after all magic has been parsed
397 static const char *parse_short_magic(unsigned *magic
, const char *elem
)
401 for (pos
= elem
+ 1; *pos
&& *pos
!= ':'; pos
++) {
405 /* Special case alias for '!' */
407 *magic
|= PATHSPEC_EXCLUDE
;
411 if (!is_pathspec_magic(ch
))
414 for (i
= 0; i
< ARRAY_SIZE(pathspec_magic
); i
++) {
415 if (pathspec_magic
[i
].mnemonic
== ch
) {
416 *magic
|= pathspec_magic
[i
].bit
;
421 if (ARRAY_SIZE(pathspec_magic
) <= i
)
422 die(_("Unimplemented pathspec magic '%c' in '%s'"),
432 static const char *parse_element_magic(unsigned *magic
, int *prefix_len
,
433 struct pathspec_item
*item
,
436 if (elem
[0] != ':' || get_literal_global())
437 return elem
; /* nothing to do */
438 else if (elem
[1] == '(')
440 return parse_long_magic(magic
, prefix_len
, item
, elem
);
443 return parse_short_magic(magic
, elem
);
447 * Perform the initialization of a pathspec_item based on a pathspec element.
449 static void init_pathspec_item(struct pathspec_item
*item
, unsigned flags
,
450 const char *prefix
, int prefixlen
,
453 unsigned magic
= 0, element_magic
= 0;
454 const char *copyfrom
= elt
;
456 int pathspec_prefix
= -1;
458 item
->attr_check
= NULL
;
459 item
->attr_match
= NULL
;
460 item
->attr_match_nr
= 0;
462 /* PATHSPEC_LITERAL_PATH ignores magic */
463 if (flags
& PATHSPEC_LITERAL_PATH
) {
464 magic
= PATHSPEC_LITERAL
;
466 copyfrom
= parse_element_magic(&element_magic
,
470 magic
|= element_magic
;
471 magic
|= get_global_magic(element_magic
);
476 if (pathspec_prefix
>= 0 &&
477 (prefixlen
|| (prefix
&& *prefix
)))
478 BUG("'prefix' magic is supposed to be used at worktree's root");
480 if ((magic
& PATHSPEC_LITERAL
) && (magic
& PATHSPEC_GLOB
))
481 die(_("%s: 'literal' and 'glob' are incompatible"), elt
);
483 /* Create match string which will be used for pathspec matching */
484 if (pathspec_prefix
>= 0) {
485 match
= xstrdup(copyfrom
);
486 prefixlen
= pathspec_prefix
;
487 } else if (magic
& PATHSPEC_FROMTOP
) {
488 match
= xstrdup(copyfrom
);
491 match
= prefix_path_gently(prefix
, prefixlen
,
492 &prefixlen
, copyfrom
);
494 const char *hint_path
;
497 die(_("'%s' is outside the directory tree"),
499 hint_path
= repo_get_work_tree(the_repository
);
501 hint_path
= repo_get_git_dir(the_repository
);
502 die(_("%s: '%s' is outside repository at '%s'"), elt
,
503 copyfrom
, absolute_path(hint_path
));
508 item
->len
= strlen(item
->match
);
509 item
->prefix
= prefixlen
;
512 * Prefix the pathspec (keep all magic) and assign to
513 * original. Useful for passing to another command.
515 if ((flags
& PATHSPEC_PREFIX_ORIGIN
) &&
516 !get_literal_global()) {
517 struct strbuf sb
= STRBUF_INIT
;
519 /* Preserve the actual prefix length of each pattern */
520 prefix_magic(&sb
, prefixlen
, element_magic
, elt
);
522 strbuf_addstr(&sb
, match
);
523 item
->original
= strbuf_detach(&sb
, NULL
);
525 item
->original
= xstrdup(elt
);
528 if (magic
& PATHSPEC_LITERAL
) {
529 item
->nowildcard_len
= item
->len
;
531 item
->nowildcard_len
= simple_length(item
->match
);
532 if (item
->nowildcard_len
< prefixlen
)
533 item
->nowildcard_len
= prefixlen
;
537 if (magic
& PATHSPEC_GLOB
) {
539 * FIXME: should we enable ONESTAR in _GLOB for
540 * pattern "* * / * . c"?
543 if (item
->nowildcard_len
< item
->len
&&
544 item
->match
[item
->nowildcard_len
] == '*' &&
545 no_wildcard(item
->match
+ item
->nowildcard_len
+ 1))
546 item
->flags
|= PATHSPEC_ONESTAR
;
549 /* sanity checks, pathspec matchers assume these are sane */
550 if (item
->nowildcard_len
> item
->len
||
551 item
->prefix
> item
->len
) {
552 BUG("error initializing pathspec_item");
556 static int pathspec_item_cmp(const void *a_
, const void *b_
)
558 struct pathspec_item
*a
, *b
;
560 a
= (struct pathspec_item
*)a_
;
561 b
= (struct pathspec_item
*)b_
;
562 return strcmp(a
->match
, b
->match
);
565 void pathspec_magic_names(unsigned magic
, struct strbuf
*out
)
568 for (i
= 0; i
< ARRAY_SIZE(pathspec_magic
); i
++) {
569 const struct pathspec_magic
*m
= pathspec_magic
+ i
;
570 if (!(magic
& m
->bit
))
573 strbuf_addstr(out
, ", ");
576 strbuf_addf(out
, _("'%s' (mnemonic: '%c')"),
577 m
->name
, m
->mnemonic
);
579 strbuf_addf(out
, "'%s'", m
->name
);
583 static void NORETURN
unsupported_magic(const char *pattern
,
586 struct strbuf sb
= STRBUF_INIT
;
587 pathspec_magic_names(magic
, &sb
);
589 * We may want to substitute "this command" with a command
590 * name. E.g. when "git add -p" or "git add -i" dies when running
593 die(_("%s: pathspec magic not supported by this command: %s"),
597 void parse_pathspec(struct pathspec
*pathspec
,
598 unsigned magic_mask
, unsigned flags
,
599 const char *prefix
, const char **argv
)
601 struct pathspec_item
*item
;
602 const char *entry
= argv
? *argv
: NULL
;
603 int i
, n
, prefixlen
, nr_exclude
= 0;
605 memset(pathspec
, 0, sizeof(*pathspec
));
607 if (flags
& PATHSPEC_MAXDEPTH_VALID
)
608 pathspec
->magic
|= PATHSPEC_MAXDEPTH
;
610 /* No arguments, no prefix -> no pathspec */
611 if (!entry
&& !prefix
)
614 if ((flags
& PATHSPEC_PREFER_CWD
) &&
615 (flags
& PATHSPEC_PREFER_FULL
))
616 BUG("PATHSPEC_PREFER_CWD and PATHSPEC_PREFER_FULL are incompatible");
618 /* No arguments with prefix -> prefix pathspec */
620 if (flags
& PATHSPEC_PREFER_FULL
)
623 if (!(flags
& PATHSPEC_PREFER_CWD
))
624 BUG("PATHSPEC_PREFER_CWD requires arguments");
626 pathspec
->items
= CALLOC_ARRAY(item
, 1);
627 item
->match
= xstrdup(prefix
);
628 item
->original
= xstrdup(prefix
);
629 item
->nowildcard_len
= item
->len
= strlen(prefix
);
630 item
->prefix
= item
->len
;
637 if (*argv
[n
] == '\0')
638 die("empty string is not a valid pathspec. "
639 "please use . instead if you meant to match all paths");
644 ALLOC_ARRAY(pathspec
->items
, n
+ 1);
645 item
= pathspec
->items
;
646 prefixlen
= prefix
? strlen(prefix
) : 0;
648 for (i
= 0; i
< n
; i
++) {
651 init_pathspec_item(item
+ i
, flags
, prefix
, prefixlen
, entry
);
653 if (item
[i
].magic
& PATHSPEC_EXCLUDE
)
655 if (item
[i
].magic
& magic_mask
)
656 unsupported_magic(entry
, item
[i
].magic
& magic_mask
);
658 if ((flags
& PATHSPEC_SYMLINK_LEADING_PATH
) &&
659 has_symlink_leading_path(item
[i
].match
, item
[i
].len
)) {
660 die(_("pathspec '%s' is beyond a symbolic link"), entry
);
663 if (item
[i
].nowildcard_len
< item
[i
].len
)
664 pathspec
->has_wildcard
= 1;
665 pathspec
->magic
|= item
[i
].magic
;
669 * If everything is an exclude pattern, add one positive pattern
670 * that matches everything. We allocated an extra one for this.
672 if (nr_exclude
== n
) {
673 int plen
= (!(flags
& PATHSPEC_PREFER_CWD
)) ? 0 : prefixlen
;
674 init_pathspec_item(item
+ n
, 0, prefix
, plen
, ".");
678 if (pathspec
->magic
& PATHSPEC_MAXDEPTH
) {
679 if (flags
& PATHSPEC_KEEP_ORDER
)
680 BUG("PATHSPEC_MAXDEPTH_VALID and PATHSPEC_KEEP_ORDER are incompatible");
681 QSORT(pathspec
->items
, pathspec
->nr
, pathspec_item_cmp
);
685 void parse_pathspec_file(struct pathspec
*pathspec
, unsigned magic_mask
,
686 unsigned flags
, const char *prefix
,
687 const char *file
, int nul_term_line
)
689 struct strvec parsed_file
= STRVEC_INIT
;
690 strbuf_getline_fn getline_fn
= nul_term_line
? strbuf_getline_nul
:
692 struct strbuf buf
= STRBUF_INIT
;
693 struct strbuf unquoted
= STRBUF_INIT
;
696 if (!strcmp(file
, "-"))
699 in
= xfopen(file
, "r");
701 while (getline_fn(&buf
, in
) != EOF
) {
702 if (!nul_term_line
&& buf
.buf
[0] == '"') {
703 strbuf_reset(&unquoted
);
704 if (unquote_c_style(&unquoted
, buf
.buf
, NULL
))
705 die(_("line is badly quoted: %s"), buf
.buf
);
706 strbuf_swap(&buf
, &unquoted
);
708 strvec_push(&parsed_file
, buf
.buf
);
712 strbuf_release(&unquoted
);
713 strbuf_release(&buf
);
717 parse_pathspec(pathspec
, magic_mask
, flags
, prefix
, parsed_file
.v
);
718 strvec_clear(&parsed_file
);
721 void copy_pathspec(struct pathspec
*dst
, const struct pathspec
*src
)
726 DUP_ARRAY(dst
->items
, src
->items
, dst
->nr
);
728 for (i
= 0; i
< dst
->nr
; i
++) {
729 struct pathspec_item
*d
= &dst
->items
[i
];
730 struct pathspec_item
*s
= &src
->items
[i
];
732 d
->match
= xstrdup(s
->match
);
733 d
->original
= xstrdup(s
->original
);
735 DUP_ARRAY(d
->attr_match
, s
->attr_match
, d
->attr_match_nr
);
736 for (j
= 0; j
< d
->attr_match_nr
; j
++) {
737 const char *value
= s
->attr_match
[j
].value
;
738 d
->attr_match
[j
].value
= xstrdup_or_null(value
);
741 d
->attr_check
= attr_check_dup(s
->attr_check
);
745 void clear_pathspec(struct pathspec
*pathspec
)
749 for (i
= 0; i
< pathspec
->nr
; i
++) {
750 free(pathspec
->items
[i
].match
);
751 free(pathspec
->items
[i
].original
);
753 for (j
= 0; j
< pathspec
->items
[i
].attr_match_nr
; j
++)
754 free(pathspec
->items
[i
].attr_match
[j
].value
);
755 free(pathspec
->items
[i
].attr_match
);
757 if (pathspec
->items
[i
].attr_check
)
758 attr_check_free(pathspec
->items
[i
].attr_check
);
761 FREE_AND_NULL(pathspec
->items
);
765 int match_pathspec_attrs(struct index_state
*istate
,
766 const char *name
, int namelen
,
767 const struct pathspec_item
*item
)
770 char *to_free
= NULL
;
773 name
= to_free
= xmemdupz(name
, namelen
);
775 git_check_attr(istate
, name
, item
->attr_check
);
779 for (i
= 0; i
< item
->attr_match_nr
; i
++) {
782 enum attr_match_mode match_mode
;
784 value
= item
->attr_check
->items
[i
].value
;
785 match_mode
= item
->attr_match
[i
].match_mode
;
787 if (ATTR_TRUE(value
))
788 matched
= (match_mode
== MATCH_SET
);
789 else if (ATTR_FALSE(value
))
790 matched
= (match_mode
== MATCH_UNSET
);
791 else if (ATTR_UNSET(value
))
792 matched
= (match_mode
== MATCH_UNSPECIFIED
);
794 matched
= (match_mode
== MATCH_VALUE
&&
795 !strcmp(item
->attr_match
[i
].value
, value
));
803 int pathspec_needs_expanded_index(struct index_state
*istate
,
804 const struct pathspec
*pathspec
)
808 char *skip_worktree_seen
= NULL
;
811 * If index is not sparse, no index expansion is needed.
813 if (!istate
->sparse_index
)
817 * When using a magic pathspec, assume for the sake of simplicity that
818 * the index needs to be expanded to match all matchable files.
823 for (i
= 0; i
< pathspec
->nr
; i
++) {
824 struct pathspec_item item
= pathspec
->items
[i
];
827 * If the pathspec item has a wildcard, the index should be expanded
828 * if the pathspec has the possibility of matching a subset of entries inside
829 * of a sparse directory (but not the entire directory).
831 * If the pathspec item is a literal path, the index only needs to be expanded
832 * if a) the pathspec isn't in the sparse checkout cone (to make sure we don't
833 * expand for in-cone files) and b) it doesn't match any sparse directories
834 * (since we can reset whole sparse directories without expanding them).
836 if (item
.nowildcard_len
< item
.len
) {
838 * Special case: if the pattern is a path inside the cone
839 * followed by only wildcards, the pattern cannot match
840 * partial sparse directories, so we know we don't need to
844 * - in-cone/foo***: doesn't need expanded index
845 * - not-in-cone/bar*: may need expanded index
846 * - **.c: may need expanded index
848 if (strspn(item
.original
+ item
.nowildcard_len
, "*") == item
.len
- item
.nowildcard_len
&&
849 path_in_cone_mode_sparse_checkout(item
.original
, istate
))
852 for (pos
= 0; pos
< istate
->cache_nr
; pos
++) {
853 struct cache_entry
*ce
= istate
->cache
[pos
];
855 if (!S_ISSPARSEDIR(ce
->ce_mode
))
859 * If the pre-wildcard length is longer than the sparse
860 * directory name and the sparse directory is the first
861 * component of the pathspec, need to expand the index.
863 if (item
.nowildcard_len
> ce_namelen(ce
) &&
864 !strncmp(item
.original
, ce
->name
, ce_namelen(ce
))) {
870 * If the pre-wildcard length is shorter than the sparse
871 * directory and the pathspec does not match the whole
872 * directory, need to expand the index.
874 if (!strncmp(item
.original
, ce
->name
, item
.nowildcard_len
) &&
875 wildmatch(item
.original
, ce
->name
, 0)) {
880 } else if (!path_in_cone_mode_sparse_checkout(item
.original
, istate
) &&
881 !matches_skip_worktree(pathspec
, i
, &skip_worktree_seen
))
888 free(skip_worktree_seen
);