diff options
author | yuangli <yuangli@mathworks.com> | 2022-07-11 15:35:15 +0100 |
---|---|---|
committer | yuangli <yuangli@mathworks.com> | 2022-07-11 15:35:15 +0100 |
commit | fe9bfec46b90443d8c64990858e5b31fbd4a7a2f (patch) | |
tree | e69e23ecdb84fd6a8b8ac8d2a8076643f2cc1f67 | |
parent | 7560ac4d2f19906729963cbdf7c8c7fb675b8f8a (diff) | |
download | libgit2-fe9bfec46b90443d8c64990858e5b31fbd4a7a2f.tar.gz |
tag: refactor tag name validity checks
-rw-r--r-- | src/tag.c | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -244,6 +244,15 @@ on_error: return -1; } +static bool tag_name_follows_pattern(const char *tag_name) +{ + /* + * Discourage tag name starting with dash, + * https://github.com/git/git/commit/4f0accd638b8d2 + */ + return tag_name[0] != '-'; +} + static int git_tag_create__internal( git_oid *oid, git_repository *repo, @@ -269,6 +278,11 @@ static int git_tag_create__internal( return -1; } + if (!tag_name_follows_pattern(tag_name)) { + git_error_set(GIT_ERROR_TAG, "'%s' is not a valid tag name", tag_name); + return -1; + } + error = retrieve_tag_reference_oid(oid, &ref_name, repo, tag_name); if (error < 0 && error != GIT_ENOTFOUND) goto cleanup; @@ -540,11 +554,7 @@ int git_tag_name_is_valid(int *valid, const char *name) GIT_ASSERT(valid); - /* - * Discourage tag name starting with dash, - * https://github.com/git/git/commit/4f0accd638b8d2 - */ - if (!name || name[0] == '-') + if (!name || !tag_name_follows_pattern(name)) goto done; if ((error = git_buf_puts(&ref_name, GIT_REFS_TAGS_DIR)) < 0 || |