コード例 #1
0
ファイル: git.go プロジェクト: fsouza/gogit
// DiscoverRepositoryPath looks for a git repository and returns the path, or
// an error if it cannot find the repository.
//
// For more details, check the documentation of the git_repository_discover
// function in libgit2.
func DiscoverRepositoryPath(path string) (string, error) {
	cpath := (*C.char)(C.malloc(C.size_t(128 * unsafe.Sizeof('a'))))
	defer C.free(unsafe.Pointer(cpath))
	cstartpath := C.CString(path)
	defer C.free(unsafe.Pointer(cstartpath))
	ceiling := C.CString("/")
	defer C.free(unsafe.Pointer(ceiling))
	if C.git_repository_discover(cpath, 128, cstartpath, 0, ceiling) != C.GIT_OK {
		return "", lastErr()
	}
	return C.GoString(cpath), nil
}
コード例 #2
0
ファイル: git.go プロジェクト: pjvds/git2go
func Discover(start string, across_fs bool, ceiling_dirs []string) (string, error) {
	ceildirs := C.CString(strings.Join(ceiling_dirs, string(C.GIT_PATH_LIST_SEPARATOR)))
	defer C.free(unsafe.Pointer(ceildirs))

	cstart := C.CString(start)
	defer C.free(unsafe.Pointer(cstart))

	retpath := (*C.char)(C.malloc(C.GIT_PATH_MAX))
	defer C.free(unsafe.Pointer(retpath))

	r := C.git_repository_discover(retpath, C.GIT_PATH_MAX, cstart, cbool(across_fs), ceildirs)

	if r == 0 {
		return C.GoString(retpath), nil
	}

	return "", LastError()
}
コード例 #3
0
ファイル: git.go プロジェクト: kissthink/libpack
func Discover(start string, across_fs bool, ceiling_dirs []string) (string, error) {
	ceildirs := C.CString(strings.Join(ceiling_dirs, string(C.GIT_PATH_LIST_SEPARATOR)))
	defer C.free(unsafe.Pointer(ceildirs))

	cstart := C.CString(start)
	defer C.free(unsafe.Pointer(cstart))

	var buf C.git_buf
	defer C.git_buf_free(&buf)

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	ret := C.git_repository_discover(&buf, cstart, cbool(across_fs), ceildirs)
	if ret < 0 {
		return "", MakeGitError(ret)
	}

	return C.GoString(buf.ptr), nil
}
コード例 #4
0
ファイル: repository.go プロジェクト: jgrocho/go-git2
func Discover(start string, across_fs bool, ceilings []string) (string, error) {
	cstart := C.CString(start)
	defer C.free(unsafe.Pointer(cstart))

	var path [git_PATH_MAX]int8
	cpath := (*C.char)(&path[0])

	cacross_fs := C.int(c_FALSE)
	if across_fs {
		cacross_fs = C.int(c_TRUE)
	}

	ceiling_dirs := strings.Join(ceilings, git_PATH_LIST_SEPARATOR)
	cceiling_dirs := C.CString(ceiling_dirs)
	defer C.free(unsafe.Pointer(cceiling_dirs))

	ecode := C.git_repository_discover(cpath, git_PATH_MAX, cstart, cacross_fs, nil)
	if ecode != git_SUCCESS {
		return "", gitError()
	}
	return C.GoString(cpath), nil
}