@@ -103,26 +103,25 @@ static int fnmatch_icase_mem(const char *pattern, int patternlen,
103
103
return match_status ;
104
104
}
105
105
106
- static size_t common_prefix_len (const char * * pathspec )
106
+ static size_t common_prefix_len (const struct pathspec * pathspec )
107
107
{
108
- const char * n , * first ;
108
+ int n ;
109
109
size_t max = 0 ;
110
- int literal = limit_pathspec_to_literal ();
111
110
112
- if (!pathspec )
113
- return max ;
114
-
115
- first = * pathspec ;
116
- while ((n = * pathspec ++ )) {
117
- size_t i , len = 0 ;
118
- for (i = 0 ; first == n || i < max ; i ++ ) {
119
- char c = n [i ];
120
- if (!c || c != first [i ] || (!literal && is_glob_special (c )))
111
+ GUARD_PATHSPEC (pathspec , PATHSPEC_FROMTOP | PATHSPEC_MAXDEPTH );
112
+
113
+ for (n = 0 ; n < pathspec -> nr ; n ++ ) {
114
+ size_t i = 0 , len = 0 ;
115
+ while (i < pathspec -> items [n ].nowildcard_len &&
116
+ (n == 0 || i < max )) {
117
+ char c = pathspec -> items [n ].match [i ];
118
+ if (c != pathspec -> items [0 ].match [i ])
121
119
break ;
122
120
if (c == '/' )
123
121
len = i + 1 ;
122
+ i ++ ;
124
123
}
125
- if (first == n || len < max ) {
124
+ if (n == 0 || len < max ) {
126
125
max = len ;
127
126
if (!max )
128
127
break ;
@@ -135,11 +134,11 @@ static size_t common_prefix_len(const char **pathspec)
135
134
* Returns a copy of the longest leading path common among all
136
135
* pathspecs.
137
136
*/
138
- char * common_prefix (const char * * pathspec )
137
+ char * common_prefix (const struct pathspec * pathspec )
139
138
{
140
139
unsigned long len = common_prefix_len (pathspec );
141
140
142
- return len ? xmemdupz (* pathspec , len ) : NULL ;
141
+ return len ? xmemdupz (pathspec -> items [ 0 ]. match , len ) : NULL ;
143
142
}
144
143
145
144
int fill_directory (struct dir_struct * dir , const struct pathspec * pathspec )
@@ -150,7 +149,7 @@ int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec)
150
149
* Calculate common prefix for the pathspec, and
151
150
* use that to optimize the directory walk
152
151
*/
153
- len = common_prefix_len (pathspec -> raw );
152
+ len = common_prefix_len (pathspec );
154
153
155
154
/* Read the directory and prune it */
156
155
read_directory (dir , pathspec -> nr ? pathspec -> raw [0 ] : "" , len , pathspec );
0 commit comments