diff --git a/commits.go b/commits.go index e817057ea..fd6d87535 100644 --- a/commits.go +++ b/commits.go @@ -23,6 +23,7 @@ var CommitsSchema = sql.Schema{ {Name: "committer_when", Type: sql.Timestamp, Nullable: false, Source: CommitsTableName}, {Name: "message", Type: sql.Text, Nullable: false, Source: CommitsTableName}, {Name: "tree_hash", Type: sql.Text, Nullable: false, Source: CommitsTableName}, + {Name: "parents", Type: sql.Array(sql.Text), Nullable: false, Source: CommitsTableName}, } var _ sql.PushdownProjectionAndFiltersTable = (*commitsTable)(nil) @@ -186,5 +187,15 @@ func commitToRow(c *object.Commit) sql.Row { c.Committer.When, c.Message, c.TreeHash.String(), + getParentHashes(c), ) } + +func getParentHashes(c *object.Commit) []interface{} { + parentHashes := make([]interface{}, 0, len(c.ParentHashes)) + for _, plumbingHash := range c.ParentHashes { + parentHashes = append(parentHashes, plumbingHash.String()) + } + + return parentHashes +} diff --git a/commits_test.go b/commits_test.go index 9967697ad..2dd62d97d 100644 --- a/commits_test.go +++ b/commits_test.go @@ -111,3 +111,96 @@ func TestCommitsPushdown(t *testing.T) { require.NoError(err) require.Len(rows, 1) } + +func TestCommitsParents(t *testing.T) { + session, _, cleanup := setup(t) + defer cleanup() + + table := newCommitsTable() + iter, err := table.RowIter(session) + require.NoError(t, err) + + rows, err := sql.RowIterToRows(iter) + require.NoError(t, err) + require.Len(t, rows, 9) + + tests := []struct { + name string + hash string + parents []string + }{ + { + name: "test commits parents 1", + hash: "e8d3ffab552895c19b9fcf7aa264d277cde33881", + parents: []string{ + "918c48b83bd081e863dbe1b80f8998f058cd8294", + }, + }, + { + name: "test commits parents 2", + hash: "6ecf0ef2c2dffb796033e5a02219af86ec6584e5", + parents: []string{ + "918c48b83bd081e863dbe1b80f8998f058cd8294", + }, + }, + { + name: "test commits parents 3", + hash: "918c48b83bd081e863dbe1b80f8998f058cd8294", + parents: []string{ + "af2d6a6954d532f8ffb47615169c8fdf9d383a1a", + }, + }, + { + name: "test commits parents 4", + hash: "af2d6a6954d532f8ffb47615169c8fdf9d383a1a", + parents: []string{ + "1669dce138d9b841a518c64b10914d88f5e488ea", + }, + }, + { + name: "test commits parents 5", + hash: "1669dce138d9b841a518c64b10914d88f5e488ea", + parents: []string{ + "35e85108805c84807bc66a02d91535e1e24b38b9", + "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69", + }, + }, + { + name: "test commits parents 6", + hash: "a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69", + parents: []string{ + "b029517f6300c2da0f4b651b8642506cd6aaf45d", + "b8e471f58bcbca63b07bda20e428190409c2db47", + }, + }, + { + name: "test commits parents 7", + hash: "b8e471f58bcbca63b07bda20e428190409c2db47", + parents: []string{ + "b029517f6300c2da0f4b651b8642506cd6aaf45d", + }, + }, + { + name: "test commits parents 8", + hash: "35e85108805c84807bc66a02d91535e1e24b38b9", + parents: []string{ + "b029517f6300c2da0f4b651b8642506cd6aaf45d", + }, + }, + { + name: "test commits parents 9", + hash: "b029517f6300c2da0f4b651b8642506cd6aaf45d", + parents: []string{}, + }, + } + + for i, test := range tests { + t.Run(test.name, func(t *testing.T) { + hash := rows[i][0] + parents := rows[i][9] + require.Equal(t, test.hash, hash) + require.ElementsMatch(t, test.parents, parents) + }) + } + +} diff --git a/internal/rule/squashjoins_test.go b/internal/rule/squashjoins_test.go index 2d5b9b19f..b70345991 100644 --- a/internal/rule/squashjoins_test.go +++ b/internal/rule/squashjoins_test.go @@ -73,7 +73,7 @@ func TestSquashJoins(t *testing.T) { nil, false, ), - []int{4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 3}, + []int{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 1, 2, 3}, gitbase.RepositoriesTableName, gitbase.ReferencesTableName, gitbase.CommitsTableName,