* Parse the pathspec element looking for long magic * * saves all magic in 'magic' * if prefix magic is used, save the prefix length in 'prefix_len' * returns the position in 'elem' after all magic has been parsed */
| 331 | * returns the position in 'elem' after all magic has been parsed |
| 332 | */ |
| 333 | static const char *parse_long_magic(unsigned *magic, int *prefix_len, |
| 334 | struct pathspec_item *item, |
| 335 | const char *elem) |
| 336 | { |
| 337 | const char *pos; |
| 338 | const char *nextat; |
| 339 | |
| 340 | for (pos = elem + 2; *pos && *pos != ')'; pos = nextat) { |
| 341 | size_t len = strcspn_escaped(pos, ",)"); |
| 342 | unsigned int i; |
| 343 | |
| 344 | if (pos[len] == ',') |
| 345 | nextat = pos + len + 1; /* handle ',' */ |
| 346 | else |
| 347 | nextat = pos + len; /* handle ')' and '\0' */ |
| 348 | |
| 349 | if (!len) |
| 350 | continue; |
| 351 | |
| 352 | if (starts_with(pos, "prefix:")) { |
| 353 | char *endptr; |
| 354 | *prefix_len = strtol(pos + 7, &endptr, 10); |
| 355 | if ((size_t)(endptr - pos) != len) |
| 356 | die(_("invalid parameter for pathspec magic 'prefix'")); |
| 357 | continue; |
| 358 | } |
| 359 | |
| 360 | if (starts_with(pos, "attr:")) { |
| 361 | char *attr_body = xmemdupz(pos + 5, len - 5); |
| 362 | parse_pathspec_attr_match(item, attr_body); |
| 363 | *magic |= PATHSPEC_ATTR; |
| 364 | free(attr_body); |
| 365 | continue; |
| 366 | } |
| 367 | |
| 368 | for (i = 0; i < ARRAY_SIZE(pathspec_magic); i++) { |
| 369 | if (strlen(pathspec_magic[i].name) == len && |
| 370 | !strncmp(pathspec_magic[i].name, pos, len)) { |
| 371 | *magic |= pathspec_magic[i].bit; |
| 372 | break; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | if (ARRAY_SIZE(pathspec_magic) <= i) |
| 377 | die(_("Invalid pathspec magic '%.*s' in '%s'"), |
| 378 | (int) len, pos, elem); |
| 379 | } |
| 380 | |
| 381 | if (*pos != ')') |
| 382 | die(_("Missing ')' at the end of pathspec magic in '%s'"), |
| 383 | elem); |
| 384 | pos++; |
| 385 | |
| 386 | return pos; |
| 387 | } |
| 388 | |
| 389 | /* |
| 390 | * Parse the pathspec element looking for short magic |
no test coverage detected