MCPcopy Index your code
hub / github.com/git/git / init_pathspec_item

Function init_pathspec_item

pathspec.c:447–552  ·  view source on GitHub ↗

* Perform the initialization of a pathspec_item based on a pathspec element. */

Source from the content-addressed store, hash-verified

445 * Perform the initialization of a pathspec_item based on a pathspec element.
446 */
447static 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

Callers 1

parse_pathspecFunction · 0.85

Calls 15

parse_element_magicFunction · 0.85
get_global_magicFunction · 0.85
xstrdupFunction · 0.85
prefix_path_gentlyFunction · 0.85
have_git_dirFunction · 0.85
repo_get_work_treeFunction · 0.85
repo_get_git_dirFunction · 0.85
absolute_pathFunction · 0.85
get_literal_globalFunction · 0.85
prefix_magicFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_detachFunction · 0.85

Tested by

no test coverage detected