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

Function parse_pathspec

pathspec.c:595–685  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

593}
594
595void parse_pathspec(struct pathspec *pathspec,
596 unsigned magic_mask, unsigned flags,
597 const char *prefix, const char **argv)
598{
599 struct pathspec_item *item;
600 const char *entry = argv ? *argv : NULL;
601 int i, n, prefixlen, nr_exclude = 0;
602
603 memset(pathspec, 0, sizeof(*pathspec));
604
605 if (flags & PATHSPEC_MAXDEPTH_VALID)
606 pathspec->magic |= PATHSPEC_MAXDEPTH;
607
608 /* No arguments, no prefix -> no pathspec */
609 if (!entry && !prefix)
610 return;
611
612 if ((flags & PATHSPEC_PREFER_CWD) &&
613 (flags & PATHSPEC_PREFER_FULL))
614 BUG("PATHSPEC_PREFER_CWD and PATHSPEC_PREFER_FULL are incompatible");
615
616 if ((flags & PATHSPEC_NO_REPOSITORY) &&
617 (~magic_mask & (PATHSPEC_ATTR | PATHSPEC_FROMTOP)))
618 BUG("PATHSPEC_NO_REPOSITORY is incompatible with PATHSPEC_ATTR and PATHSPEC_FROMTOP");
619
620 /* No arguments with prefix -> prefix pathspec */
621 if (!entry) {
622 if (flags & PATHSPEC_PREFER_FULL)
623 return;
624
625 if (!(flags & PATHSPEC_PREFER_CWD))
626 BUG("PATHSPEC_PREFER_CWD requires arguments");
627
628 pathspec->items = CALLOC_ARRAY(item, 1);
629 item->match = xstrdup(prefix);
630 item->original = xstrdup(prefix);
631 item->nowildcard_len = item->len = strlen(prefix);
632 item->prefix = item->len;
633 pathspec->nr = 1;
634 return;
635 }
636
637 n = 0;
638 while (argv[n]) {
639 if (*argv[n] == '\0')
640 die("empty string is not a valid pathspec. "
641 "please use . instead if you meant to match all paths");
642 n++;
643 }
644
645 pathspec->nr = n;
646 ALLOC_ARRAY(pathspec->items, n + 1);
647 item = pathspec->items;
648 prefixlen = prefix ? strlen(prefix) : 0;
649
650 for (i = 0; i < n; i++) {
651 entry = argv[i];
652

Callers 15

is_tree_submodule_activeFunction · 0.85
parse_pathspec_fileFunction · 0.85
try_to_follow_renamesFunction · 0.85
find_originFunction · 0.85
path_existsFunction · 0.85
parse_pathspec_argFunction · 0.85
prepare_show_mergeFunction · 0.85
setup_revisionsFunction · 0.85
diff_no_indexFunction · 0.85
run_revertFunction · 0.85
run_patchFunction · 0.85

Calls 5

xstrdupFunction · 0.85
init_pathspec_itemFunction · 0.85
unsupported_magicFunction · 0.85
has_symlink_leading_pathFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected