MCPcopy Create free account
hub / github.com/git/git / find_name_common

Function find_name_common

apply.c:654–703  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

652}
653
654static char *find_name_common(struct strbuf *root,
655 const char *line,
656 const char *def,
657 int p_value,
658 const char *end,
659 int terminate)
660{
661 int len;
662 const char *start = NULL;
663
664 if (p_value == 0)
665 start = line;
666 while (line != end) {
667 char c = *line;
668
669 if (!end && isspace(c)) {
670 if (c == '\n')
671 break;
672 if (name_terminate(c, terminate))
673 break;
674 }
675 line++;
676 if (c == '/' && !--p_value)
677 start = line;
678 }
679 if (!start)
680 return squash_slash(xstrdup_or_null(def));
681 len = line - start;
682 if (!len)
683 return squash_slash(xstrdup_or_null(def));
684
685 /*
686 * Generally we prefer the shorter name, especially
687 * if the other one is just a variation of that with
688 * something else tacked on to the end (ie "file.orig"
689 * or "file~").
690 */
691 if (def) {
692 int deflen = strlen(def);
693 if (deflen < len && !strncmp(start, def, deflen))
694 return squash_slash(xstrdup(def));
695 }
696
697 if (root->len) {
698 char *ret = xstrfmt("%s%.*s", root->buf, len, start);
699 return squash_slash(ret);
700 }
701
702 return squash_slash(xmemdupz(start, len));
703}
704
705static char *find_name(struct strbuf *root,
706 const char *line,

Callers 2

find_nameFunction · 0.85
find_name_traditionalFunction · 0.85

Calls 6

name_terminateFunction · 0.85
squash_slashFunction · 0.85
xstrdup_or_nullFunction · 0.85
xstrdupFunction · 0.85
xstrfmtFunction · 0.85
xmemdupzFunction · 0.85

Tested by

no test coverage detected