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

Function ref_and_count_parts_valid

object-name.c:1029–1057  ·  view source on GitHub ↗

* Documentation/revisions.adoc says: * ' ', e.g. 'v1.7.4.2-679-g3bee7fb':: * Output from `git describe`; i.e. a closest tag, optionally * followed by a dash and a number of commits, followed by a dash, a * 'g', and an abbreviated object name. * * which means that the stuff before '-g${HASH}' needs to be a valid * refname, a dash, and a non-negative integer.

Source from the content-addressed store, hash-verified

1027 * we are verifying ${REFNAME}-{INTEGER} part of the name.
1028 */
1029static int ref_and_count_parts_valid(const char *name, int len)
1030{
1031 struct strbuf sb;
1032 const char *cp;
1033 int flags = REFNAME_ALLOW_ONELEVEL;
1034 int ret = 1;
1035
1036 /* Ensure we have at least one digit */
1037 if (!isxdigit(name[len-1]))
1038 return 0;
1039
1040 /* Skip over digits backwards until we get to the dash */
1041 for (cp = name + len - 2; name < cp; cp--) {
1042 if (*cp == '-')
1043 break;
1044 if (!isxdigit(*cp))
1045 return 0;
1046 }
1047 /* Ensure we found the leading dash */
1048 if (*cp != '-')
1049 return 0;
1050
1051 len = cp - name;
1052 strbuf_init(&sb, len);
1053 strbuf_add(&sb, name, len);
1054 ret = !check_refname_format(sb.buf, flags);
1055 strbuf_release(&sb);
1056 return ret;
1057}
1058
1059static int get_describe_name(struct repository *r,
1060 const char *name, int len,

Callers 1

get_describe_nameFunction · 0.85

Calls 4

strbuf_initFunction · 0.85
strbuf_addFunction · 0.85
check_refname_formatFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected