diff options
author | Russell Belfer <rb@github.com> | 2013-02-11 14:35:41 -0800 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-02-11 14:35:41 -0800 |
commit | 40a605104c2060c2bc5a08dfb62cafe473baeb21 (patch) | |
tree | 90c9ae1b89aea407c34f54ad3a878f2425d186ab /src | |
parent | 390a3c81410a219b13aa6f333949c803524c8bd2 (diff) | |
parent | 2bca5b679b9e1f7f7e5cfafa75a6a94549875197 (diff) | |
download | libgit2-40a605104c2060c2bc5a08dfb62cafe473baeb21.tar.gz |
Merge pull request #1324 from nulltoken/topic/remote_isvalidname
Topic/remote isvalidname
Diffstat (limited to 'src')
-rw-r--r-- | src/refs.c | 17 | ||||
-rw-r--r-- | src/remote.c | 36 |
2 files changed, 31 insertions, 22 deletions
diff --git a/src/refs.c b/src/refs.c index e75f51001..7dabfefae 100644 --- a/src/refs.c +++ b/src/refs.c @@ -1599,6 +1599,7 @@ static int ensure_segment_validity(const char *name) { const char *current = name; char prev = '\0'; + int lock_len = strlen(GIT_FILELOCK_EXTENSION); if (*current == '.') return -1; /* Refname starts with "." */ @@ -1619,6 +1620,11 @@ static int ensure_segment_validity(const char *name) prev = *current; } + /* A refname component can not end with ".lock" */ + if (current - name >= lock_len && + !memcmp(current - lock_len, GIT_FILELOCK_EXTENSION, lock_len)) + return -1; + return (int)(current - name); } @@ -1691,11 +1697,10 @@ int git_reference__normalize_name( segments_count++; } - /* This means that there's a leading slash in the refname */ - if (segment_len == 0 && segments_count == 0) { + /* No empty segment is allowed when not normalizing */ + if (segment_len == 0 && !normalize) goto cleanup; - } - + if (current[segment_len] == '\0') break; @@ -1714,10 +1719,6 @@ int git_reference__normalize_name( if (current[segment_len - 1] == '/') goto cleanup; - /* A refname can not end with ".lock" */ - if (!git__suffixcmp(name, GIT_FILELOCK_EXTENSION)) - goto cleanup; - if ((segments_count == 1 ) && !(flags & GIT_REF_FORMAT_ALLOW_ONELEVEL)) goto cleanup; diff --git a/src/remote.c b/src/remote.c index 920ca7a18..0a1f2b856 100644 --- a/src/remote.c +++ b/src/remote.c @@ -59,21 +59,9 @@ static int download_tags_value(git_remote *remote, git_config *cfg) static int ensure_remote_name_is_valid(const char *name) { - git_buf buf = GIT_BUF_INIT; - git_refspec refspec; - int error = -1; - - if (!name || *name == '\0') - goto cleanup; - - git_buf_printf(&buf, "refs/heads/test:refs/remotes/%s/test", name); - error = git_refspec__parse(&refspec, git_buf_cstr(&buf), true); - - git_buf_free(&buf); - git_refspec__free(&refspec); + int error = 0; -cleanup: - if (error) { + if (!git_remote_is_valid_name(name)) { giterr_set( GITERR_CONFIG, "'%s' is not a valid remote name.", name); @@ -1380,3 +1368,23 @@ void git_remote_set_update_fetchhead(git_remote *remote, int value) { remote->update_fetchhead = value; } + +int git_remote_is_valid_name( + const char *remote_name) +{ + git_buf buf = GIT_BUF_INIT; + git_refspec refspec; + int error = -1; + + if (!remote_name || *remote_name == '\0') + return 0; + + git_buf_printf(&buf, "refs/heads/test:refs/remotes/%s/test", remote_name); + error = git_refspec__parse(&refspec, git_buf_cstr(&buf), true); + + git_buf_free(&buf); + git_refspec__free(&refspec); + + giterr_clear(); + return error == 0; +} |