diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2020-10-11 13:20:52 +0100 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-10-25 16:33:27 +0000 |
| commit | b52bb4d4b2548d0c7f00de0eab5073cc8fe9e899 (patch) | |
| tree | 89b5bc95613013bc79e922ad7de85135dbcbd534 /src | |
| parent | 29715d4082ef97d54ce2bf24943425f558335796 (diff) | |
| download | libgit2-b52bb4d4b2548d0c7f00de0eab5073cc8fe9e899.tar.gz | |
refs: use git_reference_name_is_valid
Diffstat (limited to 'src')
| -rw-r--r-- | src/refs.c | 7 | ||||
| -rw-r--r-- | src/remote.c | 13 | ||||
| -rw-r--r-- | src/repository.c | 7 |
3 files changed, 18 insertions, 9 deletions
diff --git a/src/refs.c b/src/refs.c index da12d02f2..90b9b06ff 100644 --- a/src/refs.c +++ b/src/refs.c @@ -239,7 +239,7 @@ int git_reference_lookup_resolved( int git_reference_dwim(git_reference **out, git_repository *repo, const char *refname) { - int error = 0, i; + int error = 0, i, valid; bool fallbackmode = true, foundvalid = false; git_reference *ref; git_buf refnamebuf = GIT_BUF_INIT, name = GIT_BUF_INIT; @@ -265,10 +265,11 @@ int git_reference_dwim(git_reference **out, git_repository *repo, const char *re git_buf_clear(&refnamebuf); - if ((error = git_buf_printf(&refnamebuf, formatters[i], git_buf_cstr(&name))) < 0) + if ((error = git_buf_printf(&refnamebuf, formatters[i], git_buf_cstr(&name))) < 0 || + (error = git_reference_name_is_valid(&valid, git_buf_cstr(&refnamebuf))) < 0) goto cleanup; - if (!git_reference_is_valid_name(git_buf_cstr(&refnamebuf))) { + if (!valid) { error = GIT_EINVALIDSPEC; continue; } diff --git a/src/remote.c b/src/remote.c index 51e99dc94..b69526c42 100644 --- a/src/remote.c +++ b/src/remote.c @@ -1362,7 +1362,7 @@ static int update_tips_for_spec( git_vector *refs, const char *log_message) { - int error = 0, autotag; + int error = 0, autotag, valid; unsigned int i = 0; git_buf refname = GIT_BUF_INIT; git_oid old; @@ -1390,7 +1390,10 @@ static int update_tips_for_spec( git_buf_clear(&refname); /* Ignore malformed ref names (which also saves us from tag^{} */ - if (!git_reference_is_valid_name(head->name)) + if (git_reference_name_is_valid(&valid, head->name) < 0) + goto on_error; + + if (!valid) continue; /* If we have a tag, see if the auto-follow rules say to update it */ @@ -1499,6 +1502,7 @@ static int next_head(const git_remote *remote, git_vector *refs, git_remote_head *head; git_refspec *spec, *passive_spec; size_t i, j, k; + int valid; active = &remote->active_refspecs; passive = &remote->passive_refspecs; @@ -1510,7 +1514,10 @@ static int next_head(const git_remote *remote, git_vector *refs, for (; i < refs->length; i++) { head = git_vector_get(refs, i); - if (!git_reference_is_valid_name(head->name)) + if (git_reference_name_is_valid(&valid, head->name) < 0) + return -1; + + if (!valid) continue; for (; j < active->length; j++) { diff --git a/src/repository.c b/src/repository.c index 513dbd61f..f0d4b06aa 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2359,7 +2359,7 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo) git_config *config; git_config_entry *entry = NULL; const char *branch; - int error; + int valid, error; if ((error = git_repository_config__weakptr(&config, repo)) < 0) return error; @@ -2375,10 +2375,11 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo) } if ((error = git_buf_puts(out, GIT_REFS_HEADS_DIR)) < 0 || - (error = git_buf_puts(out, branch)) < 0) + (error = git_buf_puts(out, branch)) < 0 || + (error = git_reference_name_is_valid(&valid, out->ptr)) < 0) goto done; - if (!git_reference_is_valid_name(out->ptr)) { + if (!valid) { git_error_set(GIT_ERROR_INVALID, "the value of init.defaultBranch is not a valid reference name"); error = -1; } |
