summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2013-02-07 23:44:18 +0100
committernulltoken <emeric.fermas@gmail.com>2013-02-11 23:19:41 +0100
commit2bca5b679b9e1f7f7e5cfafa75a6a94549875197 (patch)
tree90c9ae1b89aea407c34f54ad3a878f2425d186ab /src
parent4d811c3b77158fdb7ee50b389c3aa8763482c61a (diff)
downloadlibgit2-2bca5b679b9e1f7f7e5cfafa75a6a94549875197.tar.gz
remote: Introduce git_remote_is_valid_name()
Fix libgit2/libgit2sharp#318
Diffstat (limited to 'src')
-rw-r--r--src/refs.c9
-rw-r--r--src/remote.c36
2 files changed, 26 insertions, 19 deletions
diff --git a/src/refs.c b/src/refs.c
index fd57ce8f7..7dabfefae 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -1622,7 +1622,7 @@ static int ensure_segment_validity(const char *name)
/* A refname component can not end with ".lock" */
if (current - name >= lock_len &&
- !git__strncmp(current - lock_len, GIT_FILELOCK_EXTENSION, lock_len))
+ !memcmp(current - lock_len, GIT_FILELOCK_EXTENSION, lock_len))
return -1;
return (int)(current - name);
@@ -1697,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;
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;
+}