@@ -60,6 +60,7 @@ static size_t common_prefix_len(const char **pathspec)
6060{
6161 const char * n , * first ;
6262 size_t max = 0 ;
63+ int literal = limit_pathspec_to_literal ();
6364
6465 if (!pathspec )
6566 return max ;
@@ -69,7 +70,7 @@ static size_t common_prefix_len(const char **pathspec)
6970 size_t i , len = 0 ;
7071 for (i = 0 ; first == n || i < max ; i ++ ) {
7172 char c = n [i ];
72- if (!c || c != first [i ] || is_glob_special (c ))
73+ if (!c || c != first [i ] || (! literal && is_glob_special (c ) ))
7374 break ;
7475 if (c == '/' )
7576 len = i + 1 ;
@@ -139,6 +140,7 @@ int within_depth(const char *name, int namelen,
139140static int match_one (const char * match , const char * name , int namelen )
140141{
141142 int matchlen ;
143+ int literal = limit_pathspec_to_literal ();
142144
143145 /* If the match was just the prefix, we matched */
144146 if (!* match )
@@ -148,7 +150,7 @@ static int match_one(const char *match, const char *name, int namelen)
148150 for (;;) {
149151 unsigned char c1 = tolower (* match );
150152 unsigned char c2 = tolower (* name );
151- if (c1 == '\0' || is_glob_special (c1 ))
153+ if (c1 == '\0' || (! literal && is_glob_special (c1 ) ))
152154 break ;
153155 if (c1 != c2 )
154156 return 0 ;
@@ -160,7 +162,7 @@ static int match_one(const char *match, const char *name, int namelen)
160162 for (;;) {
161163 unsigned char c1 = * match ;
162164 unsigned char c2 = * name ;
163- if (c1 == '\0' || is_glob_special (c1 ))
165+ if (c1 == '\0' || (! literal && is_glob_special (c1 ) ))
164166 break ;
165167 if (c1 != c2 )
166168 return 0 ;
@@ -170,14 +172,16 @@ static int match_one(const char *match, const char *name, int namelen)
170172 }
171173 }
172174
173-
174175 /*
175176 * If we don't match the matchstring exactly,
176177 * we need to match by fnmatch
177178 */
178179 matchlen = strlen (match );
179- if (strncmp_icase (match , name , matchlen ))
180+ if (strncmp_icase (match , name , matchlen )) {
181+ if (literal )
182+ return 0 ;
180183 return !fnmatch_icase (match , name , 0 ) ? MATCHED_FNMATCH : 0 ;
184+ }
181185
182186 if (namelen == matchlen )
183187 return MATCHED_EXACTLY ;
@@ -1454,13 +1458,17 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
14541458
14551459 item -> match = path ;
14561460 item -> len = strlen (path );
1457- item -> nowildcard_len = simple_length (path );
14581461 item -> flags = 0 ;
1459- if (item -> nowildcard_len < item -> len ) {
1460- pathspec -> has_wildcard = 1 ;
1461- if (path [item -> nowildcard_len ] == '*' &&
1462- no_wildcard (path + item -> nowildcard_len + 1 ))
1463- item -> flags |= PATHSPEC_ONESTAR ;
1462+ if (limit_pathspec_to_literal ()) {
1463+ item -> nowildcard_len = item -> len ;
1464+ } else {
1465+ item -> nowildcard_len = simple_length (path );
1466+ if (item -> nowildcard_len < item -> len ) {
1467+ pathspec -> has_wildcard = 1 ;
1468+ if (path [item -> nowildcard_len ] == '*' &&
1469+ no_wildcard (path + item -> nowildcard_len + 1 ))
1470+ item -> flags |= PATHSPEC_ONESTAR ;
1471+ }
14641472 }
14651473 }
14661474
@@ -1475,3 +1483,11 @@ void free_pathspec(struct pathspec *pathspec)
14751483 free (pathspec -> items );
14761484 pathspec -> items = NULL ;
14771485}
1486+
1487+ int limit_pathspec_to_literal (void )
1488+ {
1489+ static int flag = -1 ;
1490+ if (flag < 0 )
1491+ flag = git_env_bool (GIT_LITERAL_PATHSPECS_ENVIRONMENT , 0 );
1492+ return flag ;
1493+ }
0 commit comments