-
Notifications
You must be signed in to change notification settings - Fork 2
/
commits.go
88 lines (73 loc) · 1.84 KB
/
commits.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package gitquery
import (
"gopkg.in/sqle/sqle.v0/sql"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/object"
)
type commitsTable struct {
r *git.Repository
}
func newCommitsTable(r *git.Repository) sql.Table {
return &commitsTable{r: r}
}
func (commitsTable) Resolved() bool {
return true
}
func (commitsTable) Name() string {
return commitsTableName
}
func (commitsTable) Schema() sql.Schema {
return sql.Schema{
{Name: "hash", Type: sql.String, Nullable: false},
{Name: "author_name", Type: sql.String, Nullable: false},
{Name: "author_email", Type: sql.String, Nullable: false},
{Name: "author_when", Type: sql.TimestampWithTimezone, Nullable: false},
{Name: "comitter_name", Type: sql.String, Nullable: false},
{Name: "comitter_email", Type: sql.String, Nullable: false},
{Name: "comitter_when", Type: sql.TimestampWithTimezone, Nullable: false},
{Name: "message", Type: sql.String, Nullable: false},
}
}
func (r *commitsTable) TransformUp(f func(sql.Node) sql.Node) sql.Node {
return f(r)
}
func (r *commitsTable) TransformExpressionsUp(f func(sql.Expression) sql.Expression) sql.Node {
return r
}
func (r commitsTable) RowIter() (sql.RowIter, error) {
cIter, err := r.r.CommitObjects()
if err != nil {
return nil, err
}
iter := &commitIter{i: cIter}
return iter, nil
}
func (commitsTable) Children() []sql.Node {
return []sql.Node{}
}
type commitIter struct {
i object.CommitIter
}
func (i *commitIter) Next() (sql.Row, error) {
commit, err := i.i.Next()
if err != nil {
return nil, err
}
return commitToRow(commit), nil
}
func (i *commitIter) Close() error {
i.i.Close()
return nil
}
func commitToRow(c *object.Commit) sql.Row {
return sql.NewRow(
c.Hash.String(),
c.Author.Name,
c.Author.Email,
c.Author.When,
c.Committer.Name,
c.Committer.Email,
c.Committer.When,
c.Message,
)
}