summaryrefslogtreecommitdiff
path: root/src/refs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/refs.c')
-rw-r--r--src/refs.c17
1 files changed, 9 insertions, 8 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;