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

Function match_entry

tree-walk.c:840–929  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

838}
839
840static int match_entry(const struct pathspec_item *item,
841 const struct name_entry *entry, int pathlen,
842 const char *match, int matchlen,
843 enum interesting *never_interesting)
844{
845 int m = -1; /* signals that we haven't called strncmp() */
846
847 if (item->magic & PATHSPEC_ICASE)
848 /*
849 * "Never interesting" trick requires exact
850 * matching. We could do something clever with inexact
851 * matching, but it's trickier (and not to forget that
852 * strcasecmp is locale-dependent, at least in
853 * glibc). Just disable it for now. It can't be worse
854 * than the wildcard's codepath of '[Tt][Hi][Is][Ss]'
855 * pattern.
856 */
857 *never_interesting = entry_not_interesting;
858 else if (*never_interesting != entry_not_interesting) {
859 /*
860 * We have not seen any match that sorts later
861 * than the current path.
862 */
863
864 /*
865 * Does match sort strictly earlier than path
866 * with their common parts?
867 */
868 m = strncmp(match, entry->path,
869 (matchlen < pathlen) ? matchlen : pathlen);
870 if (m < 0)
871 return 0;
872
873 /*
874 * If we come here even once, that means there is at
875 * least one pathspec that would sort equal to or
876 * later than the path we are currently looking at.
877 * In other words, if we have never reached this point
878 * after iterating all pathspecs, it means all
879 * pathspecs are either outside of base, or inside the
880 * base but sorts strictly earlier than the current
881 * one. In either case, they will never match the
882 * subsequent entries. In such a case, we initialized
883 * the variable to -1 and that is what will be
884 * returned, allowing the caller to terminate early.
885 */
886 *never_interesting = entry_not_interesting;
887 }
888
889 if (pathlen > matchlen)
890 return 0;
891
892 if (matchlen > pathlen) {
893 if (match[pathlen] != '/')
894 return 0;
895 /*
896 * Reject non-directories as partial pathnames, except
897 * when match is a submodule with a trailing slash and

Callers 1

do_matchFunction · 0.85

Calls 1

ps_strncmpFunction · 0.85

Tested by

no test coverage detected