Skip to content

Commit 3d59581

Browse files
authored
Merge pull request #287 from erizocosmico/feature/commit_trees-squash
*: commit_trees squash rules and tree_entries refactor
2 parents eaaba90 + 7570c7a commit 3d59581

11 files changed

+1148
-1152
lines changed

commit_trees_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ func TestCommitTreesRowIter(t *testing.T) {
4545
{"af2d6a6954d532f8ffb47615169c8fdf9d383a1a", "5a877e6a906a2743ad6e45d99c1793642aaf8eda"},
4646

4747
{"1669dce138d9b841a518c64b10914d88f5e488ea", "eba74343e2f15d62adedfd8c883ee0262b5c8021"},
48+
4849
{"a5b8b09e2f8fcb0bb99d3ccb0958157b40890d69", "c2d30fa8ef288618f65f6eed6e168e0d514886f4"},
50+
4951
{"b8e471f58bcbca63b07bda20e428190409c2db47", "c2d30fa8ef288618f65f6eed6e168e0d514886f4"},
52+
5053
{"35e85108805c84807bc66a02d91535e1e24b38b9", "8dcef98b1d52143e1e2dbc458ffe38f925786bf2"},
54+
5155
{"b029517f6300c2da0f4b651b8642506cd6aaf45d", "aa9b383c260e1d05fbbf6b30a02914555e20c725"},
5256
}
5357

integration_test.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ func TestIntegration(t *testing.T) {
8585
`SELECT COUNT(first_commit_year), first_commit_year
8686
FROM (
8787
SELECT YEAR(c.commit_author_when) AS first_commit_year
88-
FROM repositories r
89-
INNER JOIN ref_commits rc
90-
ON r.repository_id = rc.repository_id
88+
FROM ref_commits rc
9189
INNER JOIN commits c
9290
ON rc.commit_hash = c.commit_hash
9391
ORDER BY c.commit_author_when
@@ -101,13 +99,11 @@ func TestIntegration(t *testing.T) {
10199
FROM (
102100
SELECT
103101
MONTH(committer_when) as month,
104-
r.repository_id as repo_id,
102+
rc.repository_id as repo_id,
105103
committer_email
106-
FROM repositories r
107-
INNER JOIN ref_commits rc ON rc.repository_id = r.repository_id
108-
AND rc.ref_name = 'refs/heads/master'
104+
FROM ref_commits rc
109105
INNER JOIN commits c ON rc.commit_hash = c.commit_hash
110-
WHERE YEAR(committer_when) = 2015
106+
WHERE YEAR(committer_when) = 2015 AND rc.ref_name = 'refs/heads/master'
111107
) as t
112108
GROUP BY committer_email, month, repo_id`,
113109
[]sql.Row{
@@ -184,13 +180,13 @@ func TestUastQueries(t *testing.T) {
184180
FROM tree_entries te
185181
INNER JOIN blobs b
186182
ON b.blob_hash = te.blob_hash
187-
WHERE te.tree_entry_name = 'php/crappy.php'`,
183+
WHERE te.tree_entry_name = 'crappy.php'`,
188184
)
189185
require.NoError(err)
190186

191187
rows, err := sql.RowIterToRows(iter)
192188
require.NoError(err)
193-
require.Len(rows, 3)
189+
require.Len(rows, 1)
194190
}
195191

196192
func TestSquashCorrectness(t *testing.T) {
@@ -226,9 +222,9 @@ func TestSquashCorrectness(t *testing.T) {
226222
`SELECT * FROM refs r INNER JOIN remotes re ON r.repository_id = re.repository_id`,
227223
`SELECT * FROM refs r INNER JOIN commits c ON r.commit_hash = c.commit_hash`,
228224
`SELECT * FROM ref_commits r INNER JOIN commits c ON r.commit_hash = c.commit_hash`,
229-
`SELECT * FROM refs r INNER JOIN tree_entries te ON commit_has_tree(r.commit_hash, te.tree_hash)`,
225+
`SELECT * FROM refs r INNER JOIN commit_trees t ON r.commit_hash = t.commit_hash`,
230226
`SELECT * FROM refs r INNER JOIN blobs b ON commit_has_blob(r.commit_hash, b.blob_hash)`,
231-
`SELECT * FROM commits c INNER JOIN tree_entries te ON commit_has_tree(c.commit_hash, te.tree_hash)`,
227+
`SELECT * FROM commits c INNER JOIN commit_trees t ON c.commit_hash = t.tree_hash`,
232228
`SELECT * FROM commits c INNER JOIN tree_entries te ON c.tree_hash = te.tree_hash`,
233229
`SELECT * FROM commits c INNER JOIN blobs b ON commit_has_blob(c.commit_hash, b.blob_hash)`,
234230
`SELECT * FROM tree_entries te INNER JOIN blobs b ON te.blob_hash = b.blob_hash`,
@@ -241,8 +237,10 @@ func TestSquashCorrectness(t *testing.T) {
241237
WHERE re.ref_name = 'HEAD'`,
242238

243239
`SELECT * FROM commits c
240+
INNER JOIN commit_trees t
241+
ON c.commit_hash = t.commit_hash
244242
INNER JOIN tree_entries te
245-
ON c.tree_hash = te.tree_hash
243+
ON t.tree_hash = te.tree_hash
246244
INNER JOIN blobs b
247245
ON te.blob_hash = b.blob_hash
248246
WHERE te.tree_entry_name = 'LICENSE'`,
@@ -323,9 +321,9 @@ func BenchmarkQueries(b *testing.B) {
323321
{
324322
"query with commit_has_blob",
325323
`SELECT COUNT(c.commit_hash), c.commit_hash
326-
FROM refs r
324+
FROM ref_commits r
327325
INNER JOIN commits c
328-
ON r.ref_name = 'HEAD' AND history_idx(r.commit_hash, c.commit_hash) >= 0
326+
ON r.ref_name = 'HEAD' AND r.commit_hash = c.commit_hash
329327
INNER JOIN blobs b
330328
ON commit_has_blob(c.commit_hash, b.blob_hash)
331329
GROUP BY c.commit_hash`,
@@ -335,11 +333,9 @@ func BenchmarkQueries(b *testing.B) {
335333
`SELECT COUNT(first_commit_year), first_commit_year
336334
FROM (
337335
SELECT YEAR(c.commit_author_when) AS first_commit_year
338-
FROM repositories r
339-
INNER JOIN refs
340-
ON r.repository_id = refs.repository_id
336+
FROM ref_commits r
341337
INNER JOIN commits c
342-
ON history_idx(refs.commit_hash, c.commit_hash) >= 0
338+
ON r.commit_hash = c.commit_hash
343339
ORDER BY c.commit_author_when
344340
LIMIT 1
345341
) repo_years
@@ -349,9 +345,9 @@ func BenchmarkQueries(b *testing.B) {
349345
"query with history_idx",
350346
`SELECT * FROM (
351347
SELECT COUNT(c.commit_hash) AS num, c.commit_hash
352-
FROM refs r
348+
FROM ref_commits r
353349
INNER JOIN commits c
354-
ON history_idx(r.commit_hash, c.commit_hash) >= 0
350+
ON r.commit_hash = c.commit_hash
355351
GROUP BY c.commit_hash
356352
) t WHERE num > 1`,
357353
},

internal/function/commit_has_tree.go

Lines changed: 0 additions & 233 deletions
This file was deleted.

0 commit comments

Comments
 (0)