-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitlib.go
More file actions
65 lines (46 loc) · 1.73 KB
/
gitlib.go
File metadata and controls
65 lines (46 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package gitlib
type GitLib interface {
GetBranches() ([]string, error)
HasCommits() (bool, error)
GetTreeEntries(branch, treePath string) ([]TreeEntry, error)
GetTreeNames(branch string) ([]string, error)
ShowFile(branch, path string) ([]byte, error)
GetLogCommits(branch string, limit int) ([]CommitLogEntry, error)
ArchiveTarGz(branch string) ([]byte, error)
}
type repoGitLib struct {
repoPath string
}
func NewGitLib(repoPath string) GitLib {
return &repoGitLib{repoPath: repoPath}
}
func (a *repoGitLib) GetBranches() ([]string, error) {
return callWithRepo0(a.repoPath, GetBranches)
}
func (a *repoGitLib) HasCommits() (bool, error) {
return callWithRepo0(a.repoPath, HasCommits)
}
func (a *repoGitLib) GetTreeEntries(branch, treePath string) ([]TreeEntry, error) {
return callWithRepo2(a.repoPath, branch, treePath, GetTreeEntries)
}
func (a *repoGitLib) GetTreeNames(branch string) ([]string, error) {
return callWithRepo1(a.repoPath, branch, GetTreeNames)
}
func (a *repoGitLib) ShowFile(branch, path string) ([]byte, error) {
return callWithRepo2(a.repoPath, branch, path, ShowFile)
}
func (a *repoGitLib) GetLogCommits(branch string, limit int) ([]CommitLogEntry, error) {
return callWithRepo2(a.repoPath, branch, limit, GetLogCommits)
}
func (a *repoGitLib) ArchiveTarGz(branch string) ([]byte, error) {
return callWithRepo1(a.repoPath, branch, ArchiveTarGz)
}
func callWithRepo0[T any](repoPath string, fn func(string) (T, error)) (T, error) {
return fn(repoPath)
}
func callWithRepo1[A, T any](repoPath string, a A, fn func(string, A) (T, error)) (T, error) {
return fn(repoPath, a)
}
func callWithRepo2[A, B, T any](repoPath string, a A, b B, fn func(string, A, B) (T, error)) (T, error) {
return fn(repoPath, a, b)
}