Exemple #1
1
func (repo *Repository) TagListMatch(pattern string) ([]string, error) {
	cpattern := C.CString(pattern)
	defer C.free(unsafe.Pointer(cpattern))
	var ctags C.git_strarray
	defer C.git_strarray_free(&ctags)
	ecode := C.git_tag_list_match(&ctags, cpattern, repo.git_repository)
	if ecode != git_SUCCESS {
		return nil, gitError()
	}

	// TODO: Find a safer way if one exists.
	var tagsSlice reflect.SliceHeader
	length := int(ctags.count)
	tagsSlice.Data = uintptr(unsafe.Pointer(ctags.strings))
	tagsSlice.Len = length
	tagsSlice.Cap = length
	ctagStrings := *(*[]*C.char)(unsafe.Pointer(&tagsSlice))

	tags := make([]string, length)
	for i := 0; i < len(ctagStrings); i++ {
		tags[i] = C.GoString(ctagStrings[i])
	}

	return tags, nil
}
Exemple #2
1
func (repo *Repository) ListBranches(flags ...BranchType) ([]string, error) {
	var cnames C.git_strarray
	defer C.git_strarray_free(&cnames)
	var cflags C.uint
	if len(flags) == 0 {
		cflags = C.uint(BRANCH_ALL)
	} else {
		for _, flag := range flags {
			cflags |= C.uint(flag)
		}
	}
	ecode := C.git_branch_list(&cnames, repo.git_repository, cflags)
	if ecode != git_SUCCESS {
		return nil, gitError()
	}

	// TODO: Find a safer way if one exists.
	var namesSlice reflect.SliceHeader
	length := int(cnames.count)
	namesSlice.Data = uintptr(unsafe.Pointer(cnames.strings))
	namesSlice.Len = length
	namesSlice.Cap = length
	cnameStrings := *(*[]*C.char)(unsafe.Pointer(&namesSlice))

	names := make([]string, length)
	for i := 0; i < len(cnameStrings); i++ {
		names[i] = C.GoString(cnameStrings[i])
	}

	return names, nil
}
Exemple #3
1
func (repo *Repository) ListReferences(flags RefType) ([]string, error) {
	var crefs C.git_strarray
	defer C.git_strarray_free(&crefs)
	ecode := C.git_reference_list(&crefs, repo.git_repository, C.uint(flags))
	if ecode != git_SUCCESS {
		return nil, gitError()
	}

	// TODO: Find a safer way if one exists.
	var refsSlice reflect.SliceHeader
	length := int(crefs.count)
	refsSlice.Data = uintptr(unsafe.Pointer(crefs.strings))
	refsSlice.Len = length
	refsSlice.Cap = length
	crefStrings := *(*[]*C.char)(unsafe.Pointer(&refsSlice))

	refs := make([]string, length)
	for i := 0; i < len(crefStrings); i++ {
		refs[i] = C.GoString(crefStrings[i])
	}
	return refs, nil
}
Exemple #4
0
func (repo *Repository) ListRemotes() ([]string, error) {
	var r C.git_strarray
	ecode := C.git_remote_list(&r, repo.ptr)
	if ecode < 0 {
		return nil, MakeGitError(ecode)
	}
	defer C.git_strarray_free(&r)

	remotes := makeStringsFromCStrings(r.strings, int(r.count))
	return remotes, nil
}
Exemple #5
0
func (o *Remote) PushRefspecs() ([]string, error) {
	crefspecs := C.git_strarray{}

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_remote_get_push_refspecs(&crefspecs, o.ptr)
	if ret < 0 {
		return nil, MakeGitError(ret)
	}
	defer C.git_strarray_free(&crefspecs)
	refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
	return refspecs, nil
}
Exemple #6
0
// List returns the names of all the tags in the repository,
// eg: ["v1.0.1", "v2.0.0"].
func (c *TagsCollection) List() ([]string, error) {
	var strC C.git_strarray

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ecode := C.git_tag_list(&strC, c.repo.ptr)
	if ecode < 0 {
		return nil, MakeGitError(ecode)
	}
	defer C.git_strarray_free(&strC)

	tags := makeStringsFromCStrings(strC.strings, int(strC.count))
	return tags, nil
}
Exemple #7
0
func (c *RemoteCollection) List() ([]string, error) {
	var r C.git_strarray

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ecode := C.git_remote_list(&r, c.repo.ptr)
	if ecode < 0 {
		return nil, MakeGitError(ecode)
	}
	defer C.git_strarray_free(&r)

	remotes := makeStringsFromCStrings(r.strings, int(r.count))
	return remotes, nil
}
Exemple #8
0
// ListWithMatch returns the names of all the tags in the repository
// that match a given pattern.
//
// The pattern is a standard fnmatch(3) pattern http://man7.org/linux/man-pages/man3/fnmatch.3.html
func (c *TagsCollection) ListWithMatch(pattern string) ([]string, error) {
	var strC C.git_strarray

	patternC := C.CString(pattern)
	defer C.free(unsafe.Pointer(patternC))

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ecode := C.git_tag_list_match(&strC, patternC, c.repo.ptr)
	if ecode < 0 {
		return nil, MakeGitError(ecode)
	}
	defer C.git_strarray_free(&strC)

	tags := makeStringsFromCStrings(strC.strings, int(strC.count))
	return tags, nil
}