| 213 | } |
| 214 | |
| 215 | static size_t common_prefix_len(const struct pathspec *pathspec) |
| 216 | { |
| 217 | int n; |
| 218 | size_t max = 0; |
| 219 | |
| 220 | /* |
| 221 | * ":(icase)path" is treated as a pathspec full of |
| 222 | * wildcard. In other words, only prefix is considered common |
| 223 | * prefix. If the pathspec is abc/foo abc/bar, running in |
| 224 | * subdir xyz, the common prefix is still xyz, not xyz/abc as |
| 225 | * in non-:(icase). |
| 226 | */ |
| 227 | GUARD_PATHSPEC(pathspec, |
| 228 | PATHSPEC_FROMTOP | |
| 229 | PATHSPEC_MAXDEPTH | |
| 230 | PATHSPEC_LITERAL | |
| 231 | PATHSPEC_GLOB | |
| 232 | PATHSPEC_ICASE | |
| 233 | PATHSPEC_EXCLUDE | |
| 234 | PATHSPEC_ATTR); |
| 235 | |
| 236 | for (n = 0; n < pathspec->nr; n++) { |
| 237 | size_t i = 0, len = 0, item_len; |
| 238 | if (pathspec->items[n].magic & PATHSPEC_EXCLUDE) |
| 239 | continue; |
| 240 | if (pathspec->items[n].magic & PATHSPEC_ICASE) |
| 241 | item_len = pathspec->items[n].prefix; |
| 242 | else |
| 243 | item_len = pathspec->items[n].nowildcard_len; |
| 244 | while (i < item_len && (n == 0 || i < max)) { |
| 245 | char c = pathspec->items[n].match[i]; |
| 246 | if (c != pathspec->items[0].match[i]) |
| 247 | break; |
| 248 | if (c == '/') |
| 249 | len = i + 1; |
| 250 | i++; |
| 251 | } |
| 252 | if (n == 0 || len < max) { |
| 253 | max = len; |
| 254 | if (!max) |
| 255 | break; |
| 256 | } |
| 257 | } |
| 258 | return max; |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Returns a copy of the longest leading path common among all |
no outgoing calls
no test coverage detected