Oid: make NewOid take a string

This is the most common way of having an id that's not in Oid form, so
let's make it the "default" and rename to NewOidFromBytes() the one that
takes []byte.
This commit is contained in:
Carlos Martín Nieto 2014-03-18 05:04:26 +01:00
parent b6703d4767
commit c9c7c1e779
2 changed files with 4 additions and 4 deletions

4
git.go
View File

@ -41,7 +41,7 @@ func newOidFromC(coid *C.git_oid) *Oid {
return oid return oid
} }
func NewOid(b []byte) *Oid { func NewOidFromBytes(b []byte) *Oid {
oid := new(Oid) oid := new(Oid)
copy(oid[0:20], b[0:20]) copy(oid[0:20], b[0:20])
return oid return oid
@ -51,7 +51,7 @@ func (oid *Oid) toC() *C.git_oid {
return (*C.git_oid)(unsafe.Pointer(oid)) return (*C.git_oid)(unsafe.Pointer(oid))
} }
func NewOidFromString(s string) (*Oid, error) { func NewOid(s string) (*Oid, error) {
o := new(Oid) o := new(Oid)
cs := C.CString(s) cs := C.CString(s)
defer C.free(unsafe.Pointer(cs)) defer C.free(unsafe.Pointer(cs))

View File

@ -27,7 +27,7 @@ func TestOdbStream(t *testing.T) {
error = stream.Close() error = stream.Close()
checkFatal(t, error) checkFatal(t, error)
expectedId, error := NewOidFromString("30f51a3fba5274d53522d0f19748456974647b4f") expectedId, error := NewOid("30f51a3fba5274d53522d0f19748456974647b4f")
checkFatal(t, error) checkFatal(t, error)
if stream.Id.Cmp(expectedId) != 0 { if stream.Id.Cmp(expectedId) != 0 {
t.Fatal("Wrong data written") t.Fatal("Wrong data written")