Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-08-09 11:15:06 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-08-11 16:07:33 +0300
commitcffaa1610ff5f2ac8d2b78a5f74d2f4e4a90a5bb (patch)
tree45bed4351877a25824f4b2e77cdc5c023c7942f0 /internal
parentc680ac066efdc5484bd4ed7f0f5c66c6c149dd31 (diff)
gitpipe: Support SHA256 object hashpks-gitpipe-sha256
Adapt the gitpipe package to support repositories that use SHA256 as object hash by automatically detecting the repository format and enable testing this package with SHA256.
Diffstat (limited to 'internal')
-rw-r--r--internal/git/gitpipe/catfile_info.go10
-rw-r--r--internal/git/gitpipe/catfile_info_test.go8
-rw-r--r--internal/git/gitpipe/catfile_object_test.go6
-rw-r--r--internal/git/gitpipe/diff_tree.go2
-rw-r--r--internal/git/gitpipe/diff_tree_test.go2
-rw-r--r--internal/git/gitpipe/ls_tree.go10
-rw-r--r--internal/git/gitpipe/ls_tree_test.go2
-rw-r--r--internal/git/gitpipe/pipeline_test.go14
-rw-r--r--internal/git/gitpipe/revision_test.go2
-rw-r--r--internal/git/gitpipe/testhelper_test.go10
10 files changed, 38 insertions, 28 deletions
diff --git a/internal/git/gitpipe/catfile_info.go b/internal/git/gitpipe/catfile_info.go
index 8b4792378..3aec77cca 100644
--- a/internal/git/gitpipe/catfile_info.go
+++ b/internal/git/gitpipe/catfile_info.go
@@ -185,6 +185,14 @@ func CatfileInfoAllObjects(
go func() {
defer close(resultChan)
+ objectHash, err := repo.ObjectHash(ctx)
+ if err != nil {
+ sendCatfileInfoResult(ctx, resultChan, CatfileInfoResult{
+ err: fmt.Errorf("detecting object hash: %w", err),
+ })
+ return
+ }
+
var stderr bytes.Buffer
cmd, err := repo.Exec(ctx, git.SubCmd{
Name: "cat-file",
@@ -204,7 +212,7 @@ func CatfileInfoAllObjects(
reader := bufio.NewReader(cmd)
for {
- objectInfo, err := catfile.ParseObjectInfo(git.ObjectHashSHA1, reader)
+ objectInfo, err := catfile.ParseObjectInfo(objectHash, reader)
if err != nil {
if errors.Is(err, io.EOF) {
break
diff --git a/internal/git/gitpipe/catfile_info_test.go b/internal/git/gitpipe/catfile_info_test.go
index 8872b3e11..94cf6a78d 100644
--- a/internal/git/gitpipe/catfile_info_test.go
+++ b/internal/git/gitpipe/catfile_info_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package gitpipe
import (
@@ -77,7 +75,7 @@ func TestCatfileInfo(t *testing.T) {
{OID: blobID, ObjectName: []byte("branch-test.txt")},
},
expectedResults: []CatfileInfoResult{
- {ObjectInfo: &catfile.ObjectInfo{Oid: treeID, Type: "tree", Size: 43}},
+ {ObjectInfo: &catfile.ObjectInfo{Oid: treeID, Type: "tree", Size: hashDependentObjectSize(43, 55)}},
{ObjectInfo: &catfile.ObjectInfo{Oid: blobID, Type: "blob", Size: 8}, ObjectName: []byte("branch-test.txt")},
},
},
@@ -303,8 +301,8 @@ func TestCatfileInfoAllObjects(t *testing.T) {
actualObjects := []CatfileInfoResult{
{ObjectInfo: &catfile.ObjectInfo{Oid: blob1, Type: "blob", Size: 6}},
{ObjectInfo: &catfile.ObjectInfo{Oid: blob2, Type: "blob", Size: 6}},
- {ObjectInfo: &catfile.ObjectInfo{Oid: tree, Type: "tree", Size: 34}},
- {ObjectInfo: &catfile.ObjectInfo{Oid: commit, Type: "commit", Size: 177}},
+ {ObjectInfo: &catfile.ObjectInfo{Oid: tree, Type: "tree", Size: hashDependentObjectSize(34, 46)}},
+ {ObjectInfo: &catfile.ObjectInfo{Oid: commit, Type: "commit", Size: hashDependentObjectSize(177, 201)}},
}
t.Run("successful", func(t *testing.T) {
diff --git a/internal/git/gitpipe/catfile_object_test.go b/internal/git/gitpipe/catfile_object_test.go
index ebbeee874..fe4f5d319 100644
--- a/internal/git/gitpipe/catfile_object_test.go
+++ b/internal/git/gitpipe/catfile_object_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package gitpipe
import (
@@ -73,11 +71,11 @@ func TestCatfileObject(t *testing.T) {
{
desc: "revlist result with object names",
catfileInfoInputs: []CatfileInfoResult{
- {ObjectInfo: &catfile.ObjectInfo{Oid: treeID, Type: "tree", Size: 43}},
+ {ObjectInfo: &catfile.ObjectInfo{Oid: treeID, Type: "tree", Size: hashDependentObjectSize(43, 55)}},
{ObjectInfo: &catfile.ObjectInfo{Oid: blobID, Type: "blob", Size: 59}, ObjectName: []byte("branch-test.txt")},
},
expectedResults: []CatfileObjectResult{
- {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: treeID, Type: "tree", Size: 43}}},
+ {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: treeID, Type: "tree", Size: hashDependentObjectSize(43, 55)}}},
{Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: blobID, Type: "blob", Size: 8}}, ObjectName: []byte("branch-test.txt")},
},
},
diff --git a/internal/git/gitpipe/diff_tree.go b/internal/git/gitpipe/diff_tree.go
index 5caecf55f..cf81a1ba3 100644
--- a/internal/git/gitpipe/diff_tree.go
+++ b/internal/git/gitpipe/diff_tree.go
@@ -46,7 +46,7 @@ func DiffTreeWithSkip(skipResult func(*RevisionResult) bool) DiffTreeOption {
// DiffTree runs git-diff-tree(1) between the two given revisions. The returned
// channel will contain the new object IDs listed by this command. For deleted
-// files this would be git.ObjectHashSHA1.ZeroOID. Cancelling the context will cause the
+// files this would be the all-zeroes object ID. Cancelling the context will cause the
// pipeline to be cancelled, too. By default, it will not recurse into subtrees.
func DiffTree(
ctx context.Context,
diff --git a/internal/git/gitpipe/diff_tree_test.go b/internal/git/gitpipe/diff_tree_test.go
index 5ea74263c..ca29d509a 100644
--- a/internal/git/gitpipe/diff_tree_test.go
+++ b/internal/git/gitpipe/diff_tree_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package gitpipe
import (
diff --git a/internal/git/gitpipe/ls_tree.go b/internal/git/gitpipe/ls_tree.go
index 5d2ad775f..3c21c1eb0 100644
--- a/internal/git/gitpipe/ls_tree.go
+++ b/internal/git/gitpipe/ls_tree.go
@@ -56,6 +56,14 @@ func LsTree(
go func() {
defer close(resultChan)
+ objectHash, err := repo.ObjectHash(ctx)
+ if err != nil {
+ sendRevisionResult(ctx, resultChan, RevisionResult{
+ err: fmt.Errorf("detecting object hash: %w", err),
+ })
+ return
+ }
+
flags := []git.Option{
git.Flag{Name: "-z"},
}
@@ -80,7 +88,7 @@ func LsTree(
return
}
- parser := lstree.NewParser(cmd, git.ObjectHashSHA1)
+ parser := lstree.NewParser(cmd, objectHash)
for {
entry, err := parser.NextEntry()
if err != nil {
diff --git a/internal/git/gitpipe/ls_tree_test.go b/internal/git/gitpipe/ls_tree_test.go
index 87afb8390..e5a7bdccf 100644
--- a/internal/git/gitpipe/ls_tree_test.go
+++ b/internal/git/gitpipe/ls_tree_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package gitpipe
import (
diff --git a/internal/git/gitpipe/pipeline_test.go b/internal/git/gitpipe/pipeline_test.go
index 7271509c7..2af0f0496 100644
--- a/internal/git/gitpipe/pipeline_test.go
+++ b/internal/git/gitpipe/pipeline_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package gitpipe
import (
@@ -113,9 +111,9 @@ func TestPipeline_revlist(t *testing.T) {
WithObjects(),
},
expectedResults: []CatfileObjectResult{
- {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: tree, Type: "tree", Size: 66}}},
+ {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: tree, Type: "tree", Size: hashDependentObjectSize(66, 90)}}},
{Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: blobB, Type: "blob", Size: 1}}, ObjectName: []byte("blob")},
- {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: subtree, Type: "tree", Size: 35}}, ObjectName: []byte("subtree")},
+ {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: subtree, Type: "tree", Size: hashDependentObjectSize(35, 47)}}, ObjectName: []byte("subtree")},
{Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: blobA, Type: "blob", Size: 6}}, ObjectName: []byte("subtree/subblob")},
},
},
@@ -154,10 +152,10 @@ func TestPipeline_revlist(t *testing.T) {
WithObjects(),
},
expectedResults: []CatfileObjectResult{
- {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: commitB, Type: "commit", Size: 225}}},
- {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: tree, Type: "tree", Size: 66}}},
+ {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: commitB, Type: "commit", Size: hashDependentObjectSize(225, 273)}}},
+ {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: tree, Type: "tree", Size: hashDependentObjectSize(66, 90)}}},
{Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: blobB, Type: "blob", Size: 1}}, ObjectName: []byte("blob")},
- {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: subtree, Type: "tree", Size: 35}}, ObjectName: []byte("subtree")},
+ {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: subtree, Type: "tree", Size: hashDependentObjectSize(35, 47)}}, ObjectName: []byte("subtree")},
{Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: blobA, Type: "blob", Size: 6}}, ObjectName: []byte("subtree/subblob")},
},
},
@@ -168,7 +166,7 @@ func TestPipeline_revlist(t *testing.T) {
commitB.String(),
},
expectedResults: []CatfileObjectResult{
- {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: commitB, Type: "commit", Size: 225}}},
+ {Object: &catfile.Object{ObjectInfo: catfile.ObjectInfo{Oid: commitB, Type: "commit", Size: hashDependentObjectSize(225, 273)}}},
},
},
{
diff --git a/internal/git/gitpipe/revision_test.go b/internal/git/gitpipe/revision_test.go
index 5dfaffa15..723f1316b 100644
--- a/internal/git/gitpipe/revision_test.go
+++ b/internal/git/gitpipe/revision_test.go
@@ -1,5 +1,3 @@
-//go:build !gitaly_test_sha256
-
package gitpipe
import (
diff --git a/internal/git/gitpipe/testhelper_test.go b/internal/git/gitpipe/testhelper_test.go
index 397c270b3..4bc9f18f7 100644
--- a/internal/git/gitpipe/testhelper_test.go
+++ b/internal/git/gitpipe/testhelper_test.go
@@ -1,11 +1,10 @@
-//go:build !gitaly_test_sha256
-
package gitpipe
import (
"testing"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
)
@@ -51,3 +50,10 @@ func (ch *chanObjectIterator) ObjectID() git.ObjectID {
func (ch *chanObjectIterator) ObjectName() []byte {
return []byte("idontcare")
}
+
+func hashDependentObjectSize(sha1Size, sha256Size int64) int64 {
+ if gittest.ObjectHashIsSHA256() {
+ return sha256Size
+ }
+ return sha1Size
+}