Skip to content

Commit 0bd1c13

Browse files
authored
Merge pull request #238 from mcarmonaa/feature/expose-commits-parents
Expose commit parents attribute in commit table
2 parents 693515d + ad6428d commit 0bd1c13

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

Diff for: commits.go

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var CommitsSchema = sql.Schema{
2323
{Name: "committer_when", Type: sql.Timestamp, Nullable: false, Source: CommitsTableName},
2424
{Name: "message", Type: sql.Text, Nullable: false, Source: CommitsTableName},
2525
{Name: "tree_hash", Type: sql.Text, Nullable: false, Source: CommitsTableName},
26+
{Name: "parents", Type: sql.Array(sql.Text), Nullable: false, Source: CommitsTableName},
2627
}
2728

2829
var _ sql.PushdownProjectionAndFiltersTable = (*commitsTable)(nil)
@@ -186,5 +187,15 @@ func commitToRow(c *object.Commit) sql.Row {
186187
c.Committer.When,
187188
c.Message,
188189
c.TreeHash.String(),
190+
getParentHashes(c),
189191
)
190192
}
193+
194+
func getParentHashes(c *object.Commit) []interface{} {
195+
parentHashes := make([]interface{}, 0, len(c.ParentHashes))
196+
for _, plumbingHash := range c.ParentHashes {
197+
parentHashes = append(parentHashes, plumbingHash.String())
198+
}
199+
200+
return parentHashes
201+
}

Diff for: commits_test.go

+93
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,96 @@ func TestCommitsPushdown(t *testing.T) {
111111
require.NoError(err)
112112
require.Len(rows, 1)
113113
}
114+
115+
func TestCommitsParents(t *testing.T) {
116+
session, _, cleanup := setup(t)
117+
defer cleanup()
118+
119+
table := newCommitsTable()
120+
iter, err := table.RowIter(session)
121+
require.NoError(t, err)
122+
123+
rows, err := sql.RowIterToRows(iter)
124+
require.NoError(t, err)
125+
require.Len(t, rows, 9)
126+
127+
tests := []struct {
128+
name string
129+
hash string
130+
parents []string
131+
}{
132+
{
133+
name: "test commits parents 1",
134+
hash: "e8d3ffab552895c19b9fcf7aa264d277cde33881",
135+
parents: []string{
136+
"918c48b83bd081e863dbe1b80f8998f058cd8294",
137+
},
138+
},
139+
{
140+
name: "test commits parents 2",
141+
hash: "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
142+
parents: []string{
143+
"918c48b83bd081e863dbe1b80f8998f058cd8294",
144+
},
145+
},
146+
{
147+
name: "test commits parents 3",
148+
hash: "918c48b83bd081e863dbe1b80f8998f058cd8294",
149+
parents: []string{
150+
"af2d6a6954d532f8ffb47615169c8fdf9d383a1a",
151+
},
152+
},
153+
{
154+
name: "test commits parents 4",
155+
hash: "af2d6a6954d532f8ffb47615169c8fdf9d383a1a",
156+
parents: []string{
157+
"1669dce138d9b841a518c64b10914d88f5e488ea",
158+
},
159+
},
160+
{
161+
name: "test commits parents 5",
162+
hash: "1669dce138d9b841a518c64b10914d88f5e488ea",
163+
parents: []string{
164+
"35e85108805c84807bc66a02d91535e1e24b38b9",
165+
"a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69",
166+
},
167+
},
168+
{
169+
name: "test commits parents 6",
170+
hash: "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69",
171+
parents: []string{
172+
"b029517f6300c2da0f4b651b8642506cd6aaf45d",
173+
"b8e471f58bcbca63b07bda20e428190409c2db47",
174+
},
175+
},
176+
{
177+
name: "test commits parents 7",
178+
hash: "b8e471f58bcbca63b07bda20e428190409c2db47",
179+
parents: []string{
180+
"b029517f6300c2da0f4b651b8642506cd6aaf45d",
181+
},
182+
},
183+
{
184+
name: "test commits parents 8",
185+
hash: "35e85108805c84807bc66a02d91535e1e24b38b9",
186+
parents: []string{
187+
"b029517f6300c2da0f4b651b8642506cd6aaf45d",
188+
},
189+
},
190+
{
191+
name: "test commits parents 9",
192+
hash: "b029517f6300c2da0f4b651b8642506cd6aaf45d",
193+
parents: []string{},
194+
},
195+
}
196+
197+
for i, test := range tests {
198+
t.Run(test.name, func(t *testing.T) {
199+
hash := rows[i][0]
200+
parents := rows[i][9]
201+
require.Equal(t, test.hash, hash)
202+
require.ElementsMatch(t, test.parents, parents)
203+
})
204+
}
205+
206+
}

Diff for: internal/rule/squashjoins_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestSquashJoins(t *testing.T) {
7373
nil,
7474
false,
7575
),
76-
[]int{4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 3},
76+
[]int{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 1, 2, 3},
7777
gitbase.RepositoriesTableName,
7878
gitbase.ReferencesTableName,
7979
gitbase.CommitsTableName,

0 commit comments

Comments
 (0)