Пример #1
0
func (repo *Repository) LookupObject(id *Oid, form ObjectType) (*Object, error) {
	obj := new(Object)
	ecode := C.git_object_lookup(&obj.git_object, repo.git_repository, id.git_oid, C.git_otype(form))
	if ecode != git_SUCCESS {
		return nil, gitError()
	}
	return obj, nil
}
Пример #2
0
func (v *Repository) lookupType(oid *Oid, t ObjectType) (Object, error) {
	var ptr *C.git_object
	ret := C.git_object_lookup(&ptr, v.ptr, oid.toC(), C.git_otype(t))
	if ret < 0 {
		return nil, LastError()
	}

	return allocObject(ptr), nil
}
Пример #3
0
// NewWriteStream opens a write stream to the ODB, which allows you to
// create a new object in the database. The size and type must be
// known in advance
func (v *Odb) NewWriteStream(size int, otype ObjectType) (*OdbWriteStream, error) {
	stream := new(OdbWriteStream)
	ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.size_t(size), C.git_otype(otype))
	if ret < 0 {
		return nil, MakeGitError(ret)
	}

	runtime.SetFinalizer(stream, (*OdbWriteStream).Free)
	return stream, nil
}
Пример #4
0
func (odb *Odb) HashFile(path string, form ObjectType) (*Oid, error) {
	oid := new(Oid)
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))
	ecode := C.git_odb_hashfile(oid.git_oid, cpath, C.git_otype(form))
	if ecode != git_SUCCESS {
		return nil, gitError()
	}
	return oid, nil
}
Пример #5
0
func (odb *Odb) Hash(data []byte, form ObjectType) (*Oid, error) {
	oid := new(Oid)
	cdata := unsafe.Pointer(&data[0])
	defer C.free(cdata)
	length := C.size_t(len(data))
	ecode := C.git_odb_hash(oid.git_oid, cdata, length, C.git_otype(form))
	if ecode != git_SUCCESS {
		return nil, gitError()
	}
	return oid, nil
}
Пример #6
0
func (v *Reference) Peel(t ObjectType) (Object, error) {
	var cobj *C.git_object

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	if err := C.git_reference_peel(&cobj, v.ptr, C.git_otype(t)); err < 0 {
		return nil, MakeGitError(err)
	}

	return allocObject(cobj, v.repo), nil
}
Пример #7
0
func (v *Repository) lookupType(id *Oid, t ObjectType) (Object, error) {
	var ptr *C.git_object

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_object_lookup(&ptr, v.ptr, id.toC(), C.git_otype(t))
	if ret < 0 {
		return nil, MakeGitError(ret)
	}

	return allocObject(ptr, v), nil
}
Пример #8
0
// Hash determines the object-ID (sha1) of a data buffer.
func (v *Odb) Hash(data []byte, otype ObjectType) (oid *Oid, err error) {
	oid = new(Oid)
	header := (*reflect.SliceHeader)(unsafe.Pointer(&data))
	ptr := unsafe.Pointer(header.Data)

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_odb_hash(oid.toC(), ptr, C.size_t(header.Len), C.git_otype(otype))
	if ret < 0 {
		return nil, MakeGitError(ret)
	}
	return oid, nil
}
Пример #9
0
func (v *Odb) Write(data []byte, otype ObjectType) (oid *Oid, err error) {
	oid = new(Oid)
	var cptr unsafe.Pointer
	if len(data) > 0 {
		cptr = unsafe.Pointer(&data[0])
	}

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_odb_write(oid.toC(), v.ptr, cptr, C.size_t(len(data)), C.git_otype(otype))

	if ret < 0 {
		return nil, MakeGitError(ret)
	}

	return oid, nil
}
Пример #10
0
func ObjectTypeIsLoose(form ObjectType) bool {
	return C.git_object_typeisloose(C.git_otype(form)) != c_FALSE
}
Пример #11
0
func ObjectType2String(form ObjectType) string {
	return C.GoString(C.git_object_type2string(C.git_otype(form)))
}
Пример #12
0
func (v *Odb) Write(data []byte, otype ObjectType) (oid *Oid, err error) {
	oid = new(Oid)
	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&data))
	ret := C.git_odb_write(oid.toC(), v.ptr, unsafe.Pointer(hdr.Data), C.size_t(hdr.Len), C.git_otype(otype))

	if ret < 0 {
		err = LastError()
	}

	return
}
Пример #13
0
func (odb *Odb) OpenWStream(size int, form ObjectType) (*OdbStream, error) {
	stream := new(OdbStream)
	ecode := C.git_odb_open_wstream(&stream.git_odb_stream, odb.git_odb, C.size_t(size), C.git_otype(form))
	if ecode != git_SUCCESS {
		return nil, gitError()
	}
	return stream, nil
}
Пример #14
0
func (v *Odb) Write(data []byte, otype ObjectType) (oid *Oid, err error) {
	oid = new(Oid)
	hdr := (*reflect.SliceHeader)(unsafe.Pointer(&data))

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_odb_write(oid.toC(), v.ptr, unsafe.Pointer(hdr.Data), C.size_t(hdr.Len), C.git_otype(otype))

	if ret < 0 {
		err = MakeGitError(ret)
	}

	return
}