Code review fixes

This commit is contained in:
Segev Finer 2020-11-13 16:56:25 +02:00
parent e69f003813
commit af9ac641c1
2 changed files with 8 additions and 3 deletions

View File

@ -489,6 +489,11 @@ func ReferenceIsValidName(name string) bool {
return false return false
} }
const (
// This should match GIT_REFNAME_MAX in src/refs.h
refnameMaxLength = 1024
)
type ReferenceFormat uint type ReferenceFormat uint
const ( const (
@ -509,7 +514,7 @@ func ReferenceNormalizeName(name string, flags ReferenceFormat) (string, error)
cname := C.CString(name) cname := C.CString(name)
defer C.free(unsafe.Pointer(cname)) defer C.free(unsafe.Pointer(cname))
bufSize := C.size_t(1024) bufSize := C.size_t(refnameMaxLength)
buf := (*C.char)(C.malloc(bufSize)) buf := (*C.char)(C.malloc(bufSize))
defer C.free(unsafe.Pointer(buf)) defer C.free(unsafe.Pointer(buf))

View File

@ -231,14 +231,14 @@ func TestReferenceNormalizeName(t *testing.T) {
checkFatal(t, err) checkFatal(t, err)
if ref != "refs/heads/master" { if ref != "refs/heads/master" {
t.Errorf("ReferenceNormalizeName(%q) = %q; want %q", "refs/heads//master", ref, want) t.Errorf("ReferenceNormalizeName(%q) = %q; want %q", "refs/heads//master", ref, "refs/heads/master")
} }
ref, err = ReferenceNormalizeName("master", ReferenceFormatAllowOnelevel|ReferenceFormatRefspecShorthand) ref, err = ReferenceNormalizeName("master", ReferenceFormatAllowOnelevel|ReferenceFormatRefspecShorthand)
checkFatal(t, err) checkFatal(t, err)
if ref != "master" { if ref != "master" {
t.Errorf("master should be normalized correctly") t.Errorf("ReferenceNormalizeName(%q) = %q; want %q", "master", ref, "master")
} }
ref, err = ReferenceNormalizeName("foo^", ReferenceFormatNormal) ref, err = ReferenceNormalizeName("foo^", ReferenceFormatNormal)