1+ #define NO_THE_INDEX_COMPATIBILITY_MACROS
12#include "cache.h"
23#include "dir.h"
34#include "pathspec.h"
1718 * to use find_pathspecs_matching_against_index() instead.
1819 */
1920void add_pathspec_matches_against_index (const struct pathspec * pathspec ,
21+ const struct index_state * istate ,
2022 char * seen )
2123{
2224 int num_unmatched = 0 , i ;
@@ -32,8 +34,8 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
3234 num_unmatched ++ ;
3335 if (!num_unmatched )
3436 return ;
35- for (i = 0 ; i < active_nr ; i ++ ) {
36- const struct cache_entry * ce = active_cache [i ];
37+ for (i = 0 ; i < istate -> cache_nr ; i ++ ) {
38+ const struct cache_entry * ce = istate -> cache [i ];
3739 ce_path_match (ce , pathspec , seen );
3840 }
3941}
@@ -46,10 +48,11 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec,
4648 * nature of the "closest" (i.e. most specific) matches which each of the
4749 * given pathspecs achieves against all items in the index.
4850 */
49- char * find_pathspecs_matching_against_index (const struct pathspec * pathspec )
51+ char * find_pathspecs_matching_against_index (const struct pathspec * pathspec ,
52+ const struct index_state * istate )
5053{
5154 char * seen = xcalloc (pathspec -> nr , 1 );
52- add_pathspec_matches_against_index (pathspec , seen );
55+ add_pathspec_matches_against_index (pathspec , istate , seen );
5356 return seen ;
5457}
5558
@@ -386,65 +389,6 @@ static const char *parse_element_magic(unsigned *magic, int *prefix_len,
386389 return parse_short_magic (magic , elem );
387390}
388391
389- static void strip_submodule_slash_cheap (struct pathspec_item * item )
390- {
391- if (item -> len >= 1 && item -> match [item -> len - 1 ] == '/' ) {
392- int i = cache_name_pos (item -> match , item -> len - 1 );
393-
394- if (i >= 0 && S_ISGITLINK (active_cache [i ]-> ce_mode )) {
395- item -> len -- ;
396- item -> match [item -> len ] = '\0' ;
397- }
398- }
399- }
400-
401- static void strip_submodule_slash_expensive (struct pathspec_item * item )
402- {
403- int i ;
404-
405- for (i = 0 ; i < active_nr ; i ++ ) {
406- struct cache_entry * ce = active_cache [i ];
407- int ce_len = ce_namelen (ce );
408-
409- if (!S_ISGITLINK (ce -> ce_mode ))
410- continue ;
411-
412- if (item -> len <= ce_len || item -> match [ce_len ] != '/' ||
413- memcmp (ce -> name , item -> match , ce_len ))
414- continue ;
415-
416- if (item -> len == ce_len + 1 ) {
417- /* strip trailing slash */
418- item -> len -- ;
419- item -> match [item -> len ] = '\0' ;
420- } else {
421- die (_ ("Pathspec '%s' is in submodule '%.*s'" ),
422- item -> original , ce_len , ce -> name );
423- }
424- }
425- }
426-
427- static void die_inside_submodule_path (struct pathspec_item * item )
428- {
429- int i ;
430-
431- for (i = 0 ; i < active_nr ; i ++ ) {
432- struct cache_entry * ce = active_cache [i ];
433- int ce_len = ce_namelen (ce );
434-
435- if (!S_ISGITLINK (ce -> ce_mode ))
436- continue ;
437-
438- if (item -> len < ce_len ||
439- !(item -> match [ce_len ] == '/' || item -> match [ce_len ] == '\0' ) ||
440- memcmp (ce -> name , item -> match , ce_len ))
441- continue ;
442-
443- die (_ ("Pathspec '%s' is in submodule '%.*s'" ),
444- item -> original , ce_len , ce -> name );
445- }
446- }
447-
448392/*
449393 * Perform the initialization of a pathspec_item based on a pathspec element.
450394 */
@@ -517,12 +461,6 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags,
517461 item -> original = xstrdup (elt );
518462 }
519463
520- if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP )
521- strip_submodule_slash_cheap (item );
522-
523- if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE )
524- strip_submodule_slash_expensive (item );
525-
526464 if (magic & PATHSPEC_LITERAL ) {
527465 item -> nowildcard_len = item -> len ;
528466 } else {
@@ -547,15 +485,7 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags,
547485 /* sanity checks, pathspec matchers assume these are sane */
548486 if (item -> nowildcard_len > item -> len ||
549487 item -> prefix > item -> len ) {
550- /*
551- * This case can be triggered by the user pointing us to a
552- * pathspec inside a submodule, which is an input error.
553- * Detect that here and complain, but fallback in the
554- * non-submodule case to a BUG, as we have no idea what
555- * would trigger that.
556- */
557- die_inside_submodule_path (item );
558- die ("BUG: item->nowildcard_len > item->len || item->prefix > item->len)" );
488+ die ("BUG: error initializing pathspec_item" );
559489 }
560490}
561491
0 commit comments