diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-18 13:33:46 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-20 07:39:11 +0300 |
commit | 600197debaadea93b7b36f43e93493fc5fdc6946 (patch) | |
tree | fec702921ef4a03ef2bb5c51013f1d3804a98196 | |
parent | 879da72e1478b558246a8a81553a816b362bdad7 (diff) |
git: Move `EmptyTreeOID` into `ObjectHash` structure
Move the `EmptyTreeOID` variable into the `ObjectHash` structure to make
it dependent on the hash function used.
-rw-r--r-- | cmd/gitaly-git2go-v15/conflicts_test.go | 2 | ||||
-rw-r--r-- | internal/git/gittest/repository_suite.go | 2 | ||||
-rw-r--r-- | internal/git/gittest/sha1.go | 6 | ||||
-rw-r--r-- | internal/git/object_id.go | 11 | ||||
-rw-r--r-- | internal/git/object_id_test.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/commit/stats.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/ref/find_all_tags_test.go | 2 | ||||
-rw-r--r-- | internal/gitaly/service/repository/raw_changes.go | 2 |
8 files changed, 14 insertions, 15 deletions
diff --git a/cmd/gitaly-git2go-v15/conflicts_test.go b/cmd/gitaly-git2go-v15/conflicts_test.go index 39829c7ae..5b09130a0 100644 --- a/cmd/gitaly-git2go-v15/conflicts_test.go +++ b/cmd/gitaly-git2go-v15/conflicts_test.go @@ -245,7 +245,7 @@ func TestConflicts_checkError(t *testing.T) { }, { desc: "invalid object type", - ours: glgit.EmptyTreeOID, + ours: glgit.ObjectHashSHA1.EmptyTreeOID, theirs: validOID, expErr: status.Error(codes.InvalidArgument, "the requested type does not match the type in the ODB"), }, diff --git a/internal/git/gittest/repository_suite.go b/internal/git/gittest/repository_suite.go index d1b7a8043..83db63614 100644 --- a/internal/git/gittest/repository_suite.go +++ b/internal/git/gittest/repository_suite.go @@ -96,7 +96,7 @@ func testRepositoryHasBranches(t *testing.T, cfg config.Cfg, getRepository GetRe repo, repoPath := getRepository(ctx, t, false) - emptyCommit := text.ChompBytes(Exec(t, cfg, "-C", repoPath, "commit-tree", git.EmptyTreeOID.String())) + emptyCommit := text.ChompBytes(Exec(t, cfg, "-C", repoPath, "commit-tree", git.ObjectHashSHA1.EmptyTreeOID.String())) Exec(t, cfg, "-C", repoPath, "update-ref", "refs/headsbranch", emptyCommit) diff --git a/internal/git/gittest/sha1.go b/internal/git/gittest/sha1.go index 38fd11759..3cfb3dc26 100644 --- a/internal/git/gittest/sha1.go +++ b/internal/git/gittest/sha1.go @@ -4,10 +4,8 @@ package gittest import "gitlab.com/gitlab-org/gitaly/v15/internal/git" -const ( - // EmptyTreeOID is the Git tree object hash that corresponds to an empty tree (directory) - EmptyTreeOID = git.EmptyTreeOID -) +// EmptyTreeOID is the Git tree object hash that corresponds to an empty tree (directory) +var EmptyTreeOID = git.ObjectHashSHA1.EmptyTreeOID var initRepoExtraArgs = []string{} diff --git a/internal/git/object_id.go b/internal/git/object_id.go index 0be8857c8..85afd4aa7 100644 --- a/internal/git/object_id.go +++ b/internal/git/object_id.go @@ -8,9 +8,6 @@ import ( ) const ( - // EmptyTreeOID is the Git tree object hash that corresponds to an empty tree (directory) - EmptyTreeOID = ObjectID("4b825dc642cb6eb9a060e54bf8d69288fbee4904") - // ZeroOID is the special value that Git uses to signal a ref or object does not exist ZeroOID = ObjectID("0000000000000000000000000000000000000000") ) @@ -18,12 +15,14 @@ const ( var ( // ObjectHashSHA1 is the implementation of an object ID via SHA1. ObjectHashSHA1 = ObjectHash{ - regexp: regexp.MustCompile(`\A[0-9a-f]{40}\z`), + regexp: regexp.MustCompile(`\A[0-9a-f]{40}\z`), + EmptyTreeOID: ObjectID("4b825dc642cb6eb9a060e54bf8d69288fbee4904"), } // ObjectHashSHA256 is the implementation of an object ID via SHA256. ObjectHashSHA256 = ObjectHash{ - regexp: regexp.MustCompile(`\A[0-9a-f]{64}\z`), + regexp: regexp.MustCompile(`\A[0-9a-f]{64}\z`), + EmptyTreeOID: ObjectID("6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321"), } // ErrInvalidObjectID is returned in case an object ID's string @@ -34,6 +33,8 @@ var ( // ObjectHash is a hash-function specific implementation of an object ID. type ObjectHash struct { regexp *regexp.Regexp + // EmptyTreeOID is the object ID of the tree object that has no directory entries. + EmptyTreeOID ObjectID } // FromHex constructs a new ObjectID from the given hex representation of the object ID. Returns diff --git a/internal/git/object_id_test.go b/internal/git/object_id_test.go index 62306d285..22f8d9a6c 100644 --- a/internal/git/object_id_test.go +++ b/internal/git/object_id_test.go @@ -192,7 +192,7 @@ func TestIsZeroOID(t *testing.T) { }, { desc: "zero object ID", - oid: EmptyTreeOID, + oid: ObjectHashSHA1.EmptyTreeOID, isZero: false, }, } { diff --git a/internal/gitaly/service/commit/stats.go b/internal/gitaly/service/commit/stats.go index 644d5b344..1b9ba0286 100644 --- a/internal/gitaly/service/commit/stats.go +++ b/internal/gitaly/service/commit/stats.go @@ -39,7 +39,7 @@ func (s *server) commitStats(ctx context.Context, in *gitalypb.CommitStatsReques var args []string if len(commit.GetParentIds()) == 0 { - args = append(args, git.EmptyTreeOID.String(), commit.Id) + args = append(args, git.ObjectHashSHA1.EmptyTreeOID.String(), commit.Id) } else { args = append(args, commit.Id+"^", commit.Id) } diff --git a/internal/gitaly/service/ref/find_all_tags_test.go b/internal/gitaly/service/ref/find_all_tags_test.go index 4396c8a99..53726710b 100644 --- a/internal/gitaly/service/ref/find_all_tags_test.go +++ b/internal/gitaly/service/ref/find_all_tags_test.go @@ -249,7 +249,7 @@ func TestFindAllTags_simpleNestedTags(t *testing.T) { Body: []byte("message"), BodySize: 7, Subject: []byte("message"), - TreeId: git.EmptyTreeOID.String(), + TreeId: git.ObjectHashSHA1.EmptyTreeOID.String(), Author: &gitalypb.CommitAuthor{ Name: []byte("Scrooge McDuck"), Email: []byte("scrooge@mcduck.com"), diff --git a/internal/gitaly/service/repository/raw_changes.go b/internal/gitaly/service/repository/raw_changes.go index ab7956440..4fb96257f 100644 --- a/internal/gitaly/service/repository/raw_changes.go +++ b/internal/gitaly/service/repository/raw_changes.go @@ -59,7 +59,7 @@ func (s *server) getRawChanges(stream gitalypb.RepositoryService_GetRawChangesSe } if git.ObjectID(from).IsZeroOID() { - from = git.EmptyTreeOID.String() + from = git.ObjectHashSHA1.EmptyTreeOID.String() } ctx := stream.Context() |