* Perform the initialization of a pathspec_item based on a pathspec element. */
| 445 | * Perform the initialization of a pathspec_item based on a pathspec element. |
| 446 | */ |
| 447 | static void init_pathspec_item(struct pathspec_item *item, unsigned flags, |
| 448 | const char *prefix, int prefixlen, |
| 449 | const char *elt) |
| 450 | { |
| 451 | unsigned magic = 0, element_magic = 0; |
| 452 | const char *copyfrom = elt; |
| 453 | char *match; |
| 454 | int pathspec_prefix = -1; |
| 455 | |
| 456 | item->attr_check = NULL; |
| 457 | item->attr_match = NULL; |
| 458 | item->attr_match_nr = 0; |
| 459 | |
| 460 | /* PATHSPEC_LITERAL_PATH ignores magic */ |
| 461 | if (flags & PATHSPEC_LITERAL_PATH) { |
| 462 | magic = PATHSPEC_LITERAL; |
| 463 | } else { |
| 464 | copyfrom = parse_element_magic(&element_magic, |
| 465 | &pathspec_prefix, |
| 466 | item, |
| 467 | elt); |
| 468 | magic |= element_magic; |
| 469 | magic |= get_global_magic(element_magic); |
| 470 | } |
| 471 | |
| 472 | item->magic = magic; |
| 473 | |
| 474 | if (pathspec_prefix >= 0 && |
| 475 | (prefixlen || (prefix && *prefix))) |
| 476 | BUG("'prefix' magic is supposed to be used at worktree's root"); |
| 477 | |
| 478 | if ((magic & PATHSPEC_LITERAL) && (magic & PATHSPEC_GLOB)) |
| 479 | die(_("%s: 'literal' and 'glob' are incompatible"), elt); |
| 480 | |
| 481 | /* Create match string which will be used for pathspec matching */ |
| 482 | if (pathspec_prefix >= 0) { |
| 483 | match = xstrdup(copyfrom); |
| 484 | prefixlen = pathspec_prefix; |
| 485 | } else if (magic & PATHSPEC_FROMTOP) { |
| 486 | match = xstrdup(copyfrom); |
| 487 | prefixlen = 0; |
| 488 | } else { |
| 489 | match = prefix_path_gently(the_repository, prefix, prefixlen, |
| 490 | &prefixlen, copyfrom); |
| 491 | if (!match) { |
| 492 | const char *hint_path; |
| 493 | |
| 494 | if ((flags & PATHSPEC_NO_REPOSITORY) || !have_git_dir()) |
| 495 | die(_("'%s' is outside the directory tree"), |
| 496 | copyfrom); |
| 497 | hint_path = repo_get_work_tree(the_repository); |
| 498 | if (!hint_path) |
| 499 | hint_path = repo_get_git_dir(the_repository); |
| 500 | die(_("%s: '%s' is outside repository at '%s'"), elt, |
| 501 | copyfrom, absolute_path(hint_path)); |
| 502 | } |
| 503 | } |
| 504 |
no test coverage detected