MCPcopy Create free account
hub / github.com/git/git / pathspec_needs_expanded_index

Function pathspec_needs_expanded_index

pathspec.c:805–895  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

803}
804
805int pathspec_needs_expanded_index(struct index_state *istate,
806 const struct pathspec *pathspec)
807{
808 unsigned int pos;
809 int i, res = 0;
810 char *skip_worktree_seen = NULL;
811
812 /*
813 * If index is not sparse, no index expansion is needed.
814 */
815 if (!istate->sparse_index)
816 return 0;
817
818 /*
819 * When using a magic pathspec, assume for the sake of simplicity that
820 * the index needs to be expanded to match all matchable files.
821 */
822 if (pathspec->magic)
823 return 1;
824
825 for (i = 0; i < pathspec->nr; i++) {
826 struct pathspec_item item = pathspec->items[i];
827
828 /*
829 * If the pathspec item has a wildcard, the index should be expanded
830 * if the pathspec has the possibility of matching a subset of entries inside
831 * of a sparse directory (but not the entire directory).
832 *
833 * If the pathspec item is a literal path, the index only needs to be expanded
834 * if a) the pathspec isn't in the sparse checkout cone (to make sure we don't
835 * expand for in-cone files) and b) it doesn't match any sparse directories
836 * (since we can reset whole sparse directories without expanding them).
837 */
838 if (item.nowildcard_len < item.len) {
839 /*
840 * Special case: if the pattern is a path inside the cone
841 * followed by only wildcards, the pattern cannot match
842 * partial sparse directories, so we know we don't need to
843 * expand the index.
844 *
845 * Examples:
846 * - in-cone/foo***: doesn't need expanded index
847 * - not-in-cone/bar*: may need expanded index
848 * - **.c: may need expanded index
849 */
850 if (strspn(item.original + item.nowildcard_len, "*") ==
851 (unsigned int)(item.len - item.nowildcard_len) &&
852 path_in_cone_mode_sparse_checkout(item.original, istate))
853 continue;
854
855 for (pos = 0; pos < istate->cache_nr; pos++) {
856 struct cache_entry *ce = istate->cache[pos];
857
858 if (!S_ISSPARSEDIR(ce->ce_mode))
859 continue;
860
861 /*
862 * If the pre-wildcard length is longer than the sparse

Callers 2

read_from_treeFunction · 0.85
cmd_rmFunction · 0.85

Calls 3

wildmatchFunction · 0.85
matches_skip_worktreeFunction · 0.85

Tested by

no test coverage detected