mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-11 16:34:33 +00:00
Rev-parse: regex check for "git describe" output.
This commit is contained in:
parent
b41384b473
commit
7e79d389a4
@ -37,6 +37,22 @@ static int revparse_lookup_fully_qualifed_ref(git_object **out, git_repository *
|
|||||||
return git_object_lookup(out, repo, &resolved, GIT_OBJ_ANY);
|
return git_object_lookup(out, repo, &resolved, GIT_OBJ_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns non-zero if yes */
|
||||||
|
static int spec_looks_like_describe_output(const char *spec)
|
||||||
|
{
|
||||||
|
regex_t regex;
|
||||||
|
int regex_error, retcode;
|
||||||
|
|
||||||
|
regex_error = regcomp(®ex, ".+-[0-9]+-g[0-9a-fA-F]+", REG_EXTENDED);
|
||||||
|
if (regex_error != 0) {
|
||||||
|
giterr_set_regex(®ex, regex_error);
|
||||||
|
return 1; /* To be safe */
|
||||||
|
}
|
||||||
|
retcode = regexec(®ex, spec, 0, NULL, 0);
|
||||||
|
regfree(®ex);
|
||||||
|
return retcode == 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int revparse_lookup_object(git_object **out, git_repository *repo, const char *spec)
|
static int revparse_lookup_object(git_object **out, git_repository *repo, const char *spec)
|
||||||
{
|
{
|
||||||
size_t speclen = strlen(spec);
|
size_t speclen = strlen(spec);
|
||||||
@ -57,6 +73,7 @@ static int revparse_lookup_object(git_object **out, git_repository *repo, const
|
|||||||
/* "git describe" output; snip everything before/including "-g" */
|
/* "git describe" output; snip everything before/including "-g" */
|
||||||
substr = strstr(spec, "-g");
|
substr = strstr(spec, "-g");
|
||||||
if (substr &&
|
if (substr &&
|
||||||
|
spec_looks_like_describe_output(spec) &&
|
||||||
!revparse_lookup_object(out, repo, substr+2)) {
|
!revparse_lookup_object(out, repo, substr+2)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user