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:
authorWill Chandler <wchandler@gitlab.com>2022-07-20 18:12:00 +0300
committerWill Chandler <wchandler@gitlab.com>2022-07-20 18:12:00 +0300
commita3fe784ea748c52c280c5c9a5a47990c7a6ad95a (patch)
tree02961001233edc9d3923012c797f590c881ed049
parent1c907781819bf8810e15578f3d4d2b25e3ca1053 (diff)
parent4fca4bcdbfba0fc1a332bd922e60404cf3ff225c (diff)
Merge branch 'pks-git-objectids-sha256' into 'master'
git: Encapsulate object hash specific information See merge request gitlab-org/gitaly!4720
-rw-r--r--cmd/gitaly-git2go-v15/conflicts_test.go6
-rw-r--r--internal/blackbox/blackbox.go4
-rw-r--r--internal/git/catfile/object_info_reader.go2
-rw-r--r--internal/git/catfile/object_info_reader_test.go2
-rw-r--r--internal/git/catfile/object_reader_test.go2
-rw-r--r--internal/git/checksum.go2
-rw-r--r--internal/git/checksum_test.go2
-rw-r--r--internal/git/gitpipe/diff_tree.go2
-rw-r--r--internal/git/gittest/commit.go4
-rw-r--r--internal/git/gittest/delta_islands.go2
-rw-r--r--internal/git/gittest/objects.go2
-rw-r--r--internal/git/gittest/ref.go2
-rw-r--r--internal/git/gittest/repo.go5
-rw-r--r--internal/git/gittest/repository_suite.go2
-rw-r--r--internal/git/gittest/sha1.go17
-rw-r--r--internal/git/gittest/sha256.go18
-rw-r--r--internal/git/gittest/tag.go2
-rw-r--r--internal/git/gittest/tree.go4
-rw-r--r--internal/git/hooks_options_test.go2
-rw-r--r--internal/git/id.go73
-rw-r--r--internal/git/id_test.go165
-rw-r--r--internal/git/localrepo/objects.go4
-rw-r--r--internal/git/localrepo/objects_test.go22
-rw-r--r--internal/git/localrepo/refs.go2
-rw-r--r--internal/git/localrepo/refs_test.go6
-rw-r--r--internal/git/localrepo/remote_extra_test.go2
-rw-r--r--internal/git/lstree/parser.go2
-rw-r--r--internal/git/object_id.go116
-rw-r--r--internal/git/object_id_test.go312
-rw-r--r--internal/git/remoterepo/repository.go2
-rw-r--r--internal/git/sha256/id.go36
-rw-r--r--internal/git/sha256/id_test.go106
-rw-r--r--internal/git/stats/http_push_test.go8
-rw-r--r--internal/git/updateref/update_with_hooks.go4
-rw-r--r--internal/git/updateref/update_with_hooks_test.go12
-rw-r--r--internal/git/updateref/updateref.go4
-rw-r--r--internal/git/updateref/updateref_test.go2
-rw-r--r--internal/git2go/apply.go2
-rw-r--r--internal/git2go/commit.go2
-rw-r--r--internal/git2go/executor.go2
-rw-r--r--internal/gitaly/diff/diff.go4
-rw-r--r--internal/gitaly/diff/diff_test.go20
-rw-r--r--internal/gitaly/hook/postreceive_test.go2
-rw-r--r--internal/gitaly/hook/prereceive_test.go2
-rw-r--r--internal/gitaly/hook/referencetransaction.go2
-rw-r--r--internal/gitaly/hook/transactions_test.go6
-rw-r--r--internal/gitaly/hook/update.go4
-rw-r--r--internal/gitaly/hook/update_test.go2
-rw-r--r--internal/gitaly/linguist/linguist.go2
-rw-r--r--internal/gitaly/service/cleanup/apply_bfg_object_map_stream_test.go16
-rw-r--r--internal/gitaly/service/commit/commit_signatures.go2
-rw-r--r--internal/gitaly/service/commit/commit_signatures_test.go2
-rw-r--r--internal/gitaly/service/commit/stats.go2
-rw-r--r--internal/gitaly/service/conflicts/resolve_conflicts.go6
-rw-r--r--internal/gitaly/service/diff/commit_test.go42
-rw-r--r--internal/gitaly/service/operations/apply_patch.go4
-rw-r--r--internal/gitaly/service/operations/apply_patch_test.go4
-rw-r--r--internal/gitaly/service/operations/branches.go10
-rw-r--r--internal/gitaly/service/operations/branches_test.go8
-rw-r--r--internal/gitaly/service/operations/cherry_pick.go2
-rw-r--r--internal/gitaly/service/operations/cherry_pick_test.go2
-rw-r--r--internal/gitaly/service/operations/commit_files.go8
-rw-r--r--internal/gitaly/service/operations/commit_files_test.go2
-rw-r--r--internal/gitaly/service/operations/merge.go10
-rw-r--r--internal/gitaly/service/operations/merge_test.go4
-rw-r--r--internal/gitaly/service/operations/rebase.go2
-rw-r--r--internal/gitaly/service/operations/revert.go2
-rw-r--r--internal/gitaly/service/operations/revert_test.go2
-rw-r--r--internal/gitaly/service/operations/submodules.go2
-rw-r--r--internal/gitaly/service/operations/submodules_test.go6
-rw-r--r--internal/gitaly/service/operations/tags.go4
-rw-r--r--internal/gitaly/service/operations/update_branches_test.go18
-rw-r--r--internal/gitaly/service/ref/find_all_tags_test.go12
-rw-r--r--internal/gitaly/service/ref/pack_refs_test.go2
-rw-r--r--internal/gitaly/service/ref/refnames_containing.go4
-rw-r--r--internal/gitaly/service/repository/apply_gitattributes.go4
-rw-r--r--internal/gitaly/service/repository/calculate_checksum.go2
-rw-r--r--internal/gitaly/service/repository/calculate_checksum_test.go4
-rw-r--r--internal/gitaly/service/repository/create_repository_from_bundle_test.go8
-rw-r--r--internal/gitaly/service/repository/gc_test.go2
-rw-r--r--internal/gitaly/service/repository/raw_changes.go10
-rw-r--r--internal/gitaly/service/repository/raw_changes_test.go2
-rw-r--r--internal/gitaly/service/smarthttp/receive_pack_test.go4
-rw-r--r--internal/gitaly/service/smarthttp/upload_pack_test.go4
-rw-r--r--internal/gitaly/service/ssh/receive_pack_test.go18
85 files changed, 642 insertions, 604 deletions
diff --git a/cmd/gitaly-git2go-v15/conflicts_test.go b/cmd/gitaly-git2go-v15/conflicts_test.go
index 39829c7ae..4ab3e4de3 100644
--- a/cmd/gitaly-git2go-v15/conflicts_test.go
+++ b/cmd/gitaly-git2go-v15/conflicts_test.go
@@ -239,20 +239,20 @@ func TestConflicts_checkError(t *testing.T) {
},
{
desc: "ours OID doesn't exist",
- ours: glgit.ZeroOID,
+ ours: glgit.ObjectHashSHA1.ZeroOID,
theirs: validOID,
expErr: status.Error(codes.InvalidArgument, "odb: cannot read object: null OID cannot exist"),
},
{
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"),
},
{
desc: "theirs OID doesn't exist",
ours: validOID,
- theirs: glgit.ZeroOID,
+ theirs: glgit.ObjectHashSHA1.ZeroOID,
expErr: status.Error(codes.InvalidArgument, "odb: cannot read object: null OID cannot exist"),
},
}
diff --git a/internal/blackbox/blackbox.go b/internal/blackbox/blackbox.go
index b7dca5547..f793fdb0a 100644
--- a/internal/blackbox/blackbox.go
+++ b/internal/blackbox/blackbox.go
@@ -198,12 +198,12 @@ func (b Blackbox) push(probe Probe) error {
commands := make([]stats.PushCommand, len(probe.Push.Commands))
for i, command := range probe.Push.Commands {
- oldOID, err := git.NewObjectIDFromHex(command.OldOID)
+ oldOID, err := git.ObjectHashSHA1.FromHex(command.OldOID)
if err != nil {
return fmt.Errorf("invalid old object ID for probe %q: %w", probe.Name, err)
}
- newOID, err := git.NewObjectIDFromHex(command.NewOID)
+ newOID, err := git.ObjectHashSHA1.FromHex(command.NewOID)
if err != nil {
return fmt.Errorf("invalid new object ID for probe %q: %w", probe.Name, err)
}
diff --git a/internal/git/catfile/object_info_reader.go b/internal/git/catfile/object_info_reader.go
index 84857ce70..fda2c4ee4 100644
--- a/internal/git/catfile/object_info_reader.go
+++ b/internal/git/catfile/object_info_reader.go
@@ -75,7 +75,7 @@ restart:
return nil, fmt.Errorf("invalid info line: %q", infoLine)
}
- oid, err := git.NewObjectIDFromHex(info[0])
+ oid, err := git.ObjectHashSHA1.FromHex(info[0])
if err != nil {
return nil, fmt.Errorf("parse object ID: %w", err)
}
diff --git a/internal/git/catfile/object_info_reader_test.go b/internal/git/catfile/object_info_reader_test.go
index ab7d98a67..debe5562b 100644
--- a/internal/git/catfile/object_info_reader_test.go
+++ b/internal/git/catfile/object_info_reader_test.go
@@ -92,7 +92,7 @@ func TestObjectInfoReader(t *testing.T) {
"refs/tags/v1.1.1",
} {
revParseOutput := gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", revision)
- objectID, err := git.NewObjectIDFromHex(text.ChompBytes(revParseOutput))
+ objectID, err := git.ObjectHashSHA1.FromHex(text.ChompBytes(revParseOutput))
require.NoError(t, err)
objectType := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "cat-file", "-t", revision))
diff --git a/internal/git/catfile/object_reader_test.go b/internal/git/catfile/object_reader_test.go
index e4be10818..28da876f6 100644
--- a/internal/git/catfile/object_reader_test.go
+++ b/internal/git/catfile/object_reader_test.go
@@ -24,7 +24,7 @@ func TestObjectReader_reader(t *testing.T) {
cfg, repoProto, repoPath := testcfg.BuildWithRepo(t)
- commitID, err := git.NewObjectIDFromHex(text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "refs/heads/master")))
+ commitID, err := git.ObjectHashSHA1.FromHex(text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "refs/heads/master")))
require.NoError(t, err)
commitContents := gittest.Exec(t, cfg, "-C", repoPath, "cat-file", "-p", "refs/heads/master")
diff --git a/internal/git/checksum.go b/internal/git/checksum.go
index adc46fabc..ce4fb25d0 100644
--- a/internal/git/checksum.go
+++ b/internal/git/checksum.go
@@ -65,7 +65,7 @@ func (c *Checksum) Bytes() []byte {
// String returns the checksum as a hex encoded string.
func (c *Checksum) String() string {
if c.IsZero() {
- return ZeroOID.String()
+ return ObjectHashSHA1.ZeroOID.String()
}
return hex.EncodeToString(c.Bytes())
}
diff --git a/internal/git/checksum_test.go b/internal/git/checksum_test.go
index 167a7ec16..b70650d3d 100644
--- a/internal/git/checksum_test.go
+++ b/internal/git/checksum_test.go
@@ -53,7 +53,7 @@ func TestChecksum(t *testing.T) {
{
desc: "zero",
expectedZero: true,
- expected: ZeroOID.String(),
+ expected: ObjectHashSHA1.ZeroOID.String(),
},
{
desc: "single ref",
diff --git a/internal/git/gitpipe/diff_tree.go b/internal/git/gitpipe/diff_tree.go
index c41e77a6a..5caecf55f 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.ZeroOID. Cancelling the context will cause the
+// files this would be git.ObjectHashSHA1.ZeroOID. 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/gittest/commit.go b/internal/git/gittest/commit.go
index 7b4b14440..f8902ffe4 100644
--- a/internal/git/gittest/commit.go
+++ b/internal/git/gittest/commit.go
@@ -150,7 +150,7 @@ func WriteCommit(t testing.TB, cfg config.Cfg, repoPath string, opts ...WriteCom
tree = writeCommitConfig.treeID.String()
} else if len(parents) == 0 {
// If there are no parents, then we set the root tree to the empty tree.
- tree = EmptyTreeOID.String()
+ tree = DefaultObjectHash.EmptyTreeOID.String()
} else {
tree = parents[0].String() + "^{tree}"
}
@@ -210,7 +210,7 @@ func WriteCommit(t testing.TB, cfg config.Cfg, repoPath string, opts ...WriteCom
Stdin: stdin,
Env: env,
}, commitArgs...)
- oid, err := NewObjectIDFromHex(text.ChompBytes(stdout))
+ oid, err := DefaultObjectHash.FromHex(text.ChompBytes(stdout))
require.NoError(t, err)
if writeCommitConfig.branch != "" {
diff --git a/internal/git/gittest/delta_islands.go b/internal/git/gittest/delta_islands.go
index b54b72c73..7909c3049 100644
--- a/internal/git/gittest/delta_islands.go
+++ b/internal/git/gittest/delta_islands.go
@@ -50,7 +50,7 @@ func TestDeltaIslands(t *testing.T, cfg config.Cfg, repoPath string, isPoolRepo
// chains, and thus neither of the two blobs should use the bad blob as delta base.
require.NoError(t, repack(), "repack after delta island setup")
require.Equal(t, blob2ID, deltaBase(t, cfg, repoPath, blob1ID), "blob 1 delta base should be blob 2 after repack")
- require.Equal(t, git.ZeroOID.String(), deltaBase(t, cfg, repoPath, blob2ID), "blob 2 should not be delta compressed after repack")
+ require.Equal(t, git.ObjectHashSHA1.ZeroOID.String(), deltaBase(t, cfg, repoPath, blob2ID), "blob 2 should not be delta compressed after repack")
}
func commitBlob(t *testing.T, cfg config.Cfg, repoPath, ref string, content string) string {
diff --git a/internal/git/gittest/objects.go b/internal/git/gittest/objects.go
index f246e384b..aafca61b2 100644
--- a/internal/git/gittest/objects.go
+++ b/internal/git/gittest/objects.go
@@ -77,7 +77,7 @@ func WriteBlob(t testing.TB, cfg config.Cfg, testRepoPath string, contents []byt
hex := text.ChompBytes(ExecOpts(t, cfg, ExecConfig{Stdin: bytes.NewReader(contents)},
"-C", testRepoPath, "hash-object", "-w", "--stdin",
))
- oid, err := git.NewObjectIDFromHex(hex)
+ oid, err := DefaultObjectHash.FromHex(hex)
require.NoError(t, err)
return oid
}
diff --git a/internal/git/gittest/ref.go b/internal/git/gittest/ref.go
index bb1e5a104..9d9687089 100644
--- a/internal/git/gittest/ref.go
+++ b/internal/git/gittest/ref.go
@@ -18,7 +18,7 @@ func WriteRef(t testing.TB, cfg config.Cfg, repoPath string, ref git.ReferenceNa
func ResolveRevision(t testing.TB, cfg config.Cfg, repoPath string, revision string) git.ObjectID {
t.Helper()
output := Exec(t, cfg, "-C", repoPath, "rev-parse", "--verify", revision)
- objectID, err := git.NewObjectIDFromHex(text.ChompBytes(output))
+ objectID, err := DefaultObjectHash.FromHex(text.ChompBytes(output))
require.NoError(t, err)
return objectID
}
diff --git a/internal/git/gittest/repo.go b/internal/git/gittest/repo.go
index a9ff1e75e..1b4b08bb3 100644
--- a/internal/git/gittest/repo.go
+++ b/internal/git/gittest/repo.go
@@ -239,6 +239,8 @@ func RewrittenRepository(ctx context.Context, t testing.TB, cfg config.Cfg, repo
type InitRepoOpts struct {
// WithRelativePath determines the relative path of this repository.
WithRelativePath string
+ // ObjectFormat overrides the object format used by the repository.
+ ObjectFormat string
}
// InitRepo creates a new empty repository in the given storage. You can either pass no or exactly
@@ -260,6 +262,9 @@ func InitRepo(t testing.TB, cfg config.Cfg, storage config.Storage, opts ...Init
args := []string{"init", "--bare"}
args = append(args, initRepoExtraArgs...)
args = append(args, repoPath)
+ if opt.ObjectFormat != "" {
+ args = append(args, "--object-format", opt.ObjectFormat)
+ }
Exec(t, cfg, args...)
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 631560e63..4a5d8de33 100644
--- a/internal/git/gittest/sha1.go
+++ b/internal/git/gittest/sha1.go
@@ -4,16 +4,9 @@ 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
-)
-
-var initRepoExtraArgs = []string{}
+var (
+ // DefaultObjectHash is the default hash used for running tests.
+ DefaultObjectHash = git.ObjectHashSHA1
-// NewObjectIDFromHex constructs a new ObjectID from the given hex
-// representation of the object ID. Returns ErrInvalidObjectID if the given
-// OID is not valid.
-func NewObjectIDFromHex(hex string) (git.ObjectID, error) {
- return git.NewObjectIDFromHex(hex)
-}
+ initRepoExtraArgs = []string{}
+)
diff --git a/internal/git/gittest/sha256.go b/internal/git/gittest/sha256.go
index ad69cd981..d571657a9 100644
--- a/internal/git/gittest/sha256.go
+++ b/internal/git/gittest/sha256.go
@@ -4,19 +4,11 @@ package gittest
import (
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
- "gitlab.com/gitlab-org/gitaly/v15/internal/git/sha256"
)
-const (
- // EmptyTreeOID is the Git tree object hash that corresponds to an empty tree (directory)
- EmptyTreeOID = sha256.EmptyTreeOID
-)
-
-var initRepoExtraArgs = []string{"--object-format=sha256"}
+var (
+ // DefaultObjectHash is the default hash used for running tests.
+ DefaultObjectHash = git.ObjectHashSHA256
-// NewObjectIDFromHex constructs a new ObjectID from the given hex
-// representation of the object ID. Returns ErrInvalidObjectID if the given
-// OID is not valid.
-func NewObjectIDFromHex(hex string) (git.ObjectID, error) {
- return sha256.NewObjectIDFromHex(hex)
-}
+ initRepoExtraArgs = []string{"--object-format=sha256"}
+)
diff --git a/internal/git/gittest/tag.go b/internal/git/gittest/tag.go
index ad720ac81..09cfa2f5d 100644
--- a/internal/git/gittest/tag.go
+++ b/internal/git/gittest/tag.go
@@ -64,7 +64,7 @@ func WriteTag(
tagID := Exec(t, cfg, "-C", repoPath, "show-ref", "-s", tagName)
- objectID, err := git.NewObjectIDFromHex(text.ChompBytes(tagID))
+ objectID, err := DefaultObjectHash.FromHex(text.ChompBytes(tagID))
require.NoError(t, err)
return objectID
diff --git a/internal/git/gittest/tree.go b/internal/git/gittest/tree.go
index 04fb99dc8..7b93c996f 100644
--- a/internal/git/gittest/tree.go
+++ b/internal/git/gittest/tree.go
@@ -55,7 +55,7 @@ func RequireTree(t testing.TB, cfg config.Cfg, repoPath, treeish string, expecte
path := string(tabSplit[1])
- objectID, err := git.NewObjectIDFromHex(string(spaceSplit[2]))
+ objectID, err := DefaultObjectHash.FromHex(string(spaceSplit[2]))
require.NoError(t, err)
actualEntries = append(actualEntries, TreeEntry{
@@ -107,7 +107,7 @@ func WriteTree(t testing.TB, cfg config.Cfg, repoPath string, entries []TreeEntr
stdout := ExecOpts(t, cfg, ExecConfig{Stdin: &tree},
"-C", repoPath, "mktree", "-z", "--missing",
)
- treeOID, err := git.NewObjectIDFromHex(text.ChompBytes(stdout))
+ treeOID, err := DefaultObjectHash.FromHex(text.ChompBytes(stdout))
require.NoError(t, err)
return treeOID
diff --git a/internal/git/hooks_options_test.go b/internal/git/hooks_options_test.go
index 25595dff9..24ebed76b 100644
--- a/internal/git/hooks_options_test.go
+++ b/internal/git/hooks_options_test.go
@@ -21,7 +21,7 @@ func TestWithRefHook(t *testing.T) {
ctx := testhelper.Context(t)
opt := git.WithRefTxHook(repo)
- subCmd := git.SubCmd{Name: "update-ref", Args: []string{"refs/heads/master", git.ZeroOID.String()}}
+ subCmd := git.SubCmd{Name: "update-ref", Args: []string{"refs/heads/master", git.ObjectHashSHA1.ZeroOID.String()}}
for _, tt := range []struct {
name string
diff --git a/internal/git/id.go b/internal/git/id.go
deleted file mode 100644
index d4cb725dd..000000000
--- a/internal/git/id.go
+++ /dev/null
@@ -1,73 +0,0 @@
-package git
-
-import (
- "encoding/hex"
- "errors"
- "fmt"
- "regexp"
-)
-
-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")
-)
-
-var (
- // ErrInvalidObjectID is returned in case an object ID's string
- // representation is not a valid one.
- ErrInvalidObjectID = errors.New("invalid object ID")
-
- objectIDRegex = regexp.MustCompile(`\A[0-9a-f]{40}\z`)
-)
-
-// ObjectID represents an object ID.
-type ObjectID string
-
-// NewObjectIDFromHex constructs a new ObjectID from the given hex
-// representation of the object ID. Returns ErrInvalidObjectID if the given
-// OID is not valid.
-func NewObjectIDFromHex(hex string) (ObjectID, error) {
- if err := ValidateObjectID(hex); err != nil {
- return "", err
- }
- return ObjectID(hex), nil
-}
-
-// String returns the hex representation of the ObjectID.
-func (oid ObjectID) String() string {
- return string(oid)
-}
-
-// Bytes returns the byte representation of the ObjectID.
-func (oid ObjectID) Bytes() ([]byte, error) {
- decoded, err := hex.DecodeString(string(oid))
- if err != nil {
- return nil, err
- }
- return decoded, nil
-}
-
-// Revision returns a revision of the ObjectID. This directly returns the hex
-// representation as every object ID is a valid revision.
-func (oid ObjectID) Revision() Revision {
- return Revision(oid.String())
-}
-
-// ValidateObjectID checks if id is a syntactically correct object ID. Abbreviated
-// object IDs are not deemed to be valid. Returns an ErrInvalidObjectID if the
-// id is not valid.
-func ValidateObjectID(id string) error {
- if objectIDRegex.MatchString(id) {
- return nil
- }
-
- return fmt.Errorf("%w: %q", ErrInvalidObjectID, id)
-}
-
-// IsZeroOID is a shortcut for `something == git.ZeroOID.String()`
-func (oid ObjectID) IsZeroOID() bool {
- return string(oid) == string(ZeroOID)
-}
diff --git a/internal/git/id_test.go b/internal/git/id_test.go
deleted file mode 100644
index 3d4374134..000000000
--- a/internal/git/id_test.go
+++ /dev/null
@@ -1,165 +0,0 @@
-//go:build !gitaly_test_sha256
-
-package git
-
-import (
- "bytes"
- "encoding/hex"
- "fmt"
- "strings"
- "testing"
-
- "github.com/stretchr/testify/require"
-)
-
-func TestValidateObjectID(t *testing.T) {
- for _, tc := range []struct {
- desc string
- oid string
- valid bool
- }{
- {
- desc: "valid object ID",
- oid: "356e7793f9654d51dfb27312a1464062bceb9fa3",
- valid: true,
- },
- {
- desc: "object ID with non-hex characters fails",
- oid: "x56e7793f9654d51dfb27312a1464062bceb9fa3",
- valid: false,
- },
- {
- desc: "object ID with upper-case letters fails",
- oid: "356E7793F9654D51DFB27312A1464062BCEB9FA3",
- valid: false,
- },
- {
- desc: "too short object ID fails",
- oid: "356e7793f9654d51dfb27312a1464062bceb9fa",
- valid: false,
- },
- {
- desc: "too long object ID fails",
- oid: "356e7793f9654d51dfb27312a1464062bceb9fa33",
- valid: false,
- },
- {
- desc: "empty string fails",
- oid: "",
- valid: false,
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- err := ValidateObjectID(tc.oid)
- if tc.valid {
- require.NoError(t, err)
- } else {
- require.Error(t, err)
- require.EqualError(t, err, fmt.Sprintf("invalid object ID: %q", tc.oid))
- }
- })
- }
-}
-
-func TestNewObjectIDFromHex(t *testing.T) {
- for _, tc := range []struct {
- desc string
- oid string
- valid bool
- }{
- {
- desc: "valid object ID",
- oid: "356e7793f9654d51dfb27312a1464062bceb9fa3",
- valid: true,
- },
- {
- desc: "object ID with non-hex characters fails",
- oid: "x56e7793f9654d51dfb27312a1464062bceb9fa3",
- valid: false,
- },
- {
- desc: "object ID with upper-case letters fails",
- oid: "356E7793F9654D51DFB27312A1464062BCEB9FA3",
- valid: false,
- },
- {
- desc: "too short object ID fails",
- oid: "356e7793f9654d51dfb27312a1464062bceb9fa",
- valid: false,
- },
- {
- desc: "too long object ID fails",
- oid: "356e7793f9654d51dfb27312a1464062bceb9fa33",
- valid: false,
- },
- {
- desc: "empty string fails",
- oid: "",
- valid: false,
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- oid, err := NewObjectIDFromHex(tc.oid)
- if tc.valid {
- require.NoError(t, err)
- require.Equal(t, tc.oid, oid.String())
- } else {
- require.Error(t, err)
- }
- })
- }
-}
-
-func TestObjectID_Bytes(t *testing.T) {
- for _, tc := range []struct {
- desc string
- oid ObjectID
- expectedBytes []byte
- expectedErr error
- }{
- {
- desc: "zero OID",
- oid: ZeroOID,
- expectedBytes: bytes.Repeat([]byte{0}, 20),
- },
- {
- desc: "valid object ID",
- oid: ObjectID(strings.Repeat("8", 40)),
- expectedBytes: bytes.Repeat([]byte{0x88}, 20),
- },
- {
- desc: "invalid object ID",
- oid: ObjectID(strings.Repeat("8", 39) + "x"),
- expectedErr: hex.InvalidByteError('x'),
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- actualBytes, err := tc.oid.Bytes()
- require.Equal(t, tc.expectedErr, err)
- require.Equal(t, tc.expectedBytes, actualBytes)
- })
- }
-}
-
-func TestIsZeroOID(t *testing.T) {
- for _, tc := range []struct {
- desc string
- oid ObjectID
- isZero bool
- }{
- {
- desc: "zero object ID",
- oid: ZeroOID,
- isZero: true,
- },
- {
- desc: "zero object ID",
- oid: EmptyTreeOID,
- isZero: false,
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- require.Equal(t, tc.isZero, tc.oid.IsZeroOID())
- })
- }
-}
diff --git a/internal/git/localrepo/objects.go b/internal/git/localrepo/objects.go
index 62a5fa9eb..56555f3a4 100644
--- a/internal/git/localrepo/objects.go
+++ b/internal/git/localrepo/objects.go
@@ -47,7 +47,7 @@ func (repo *Repo) WriteBlob(ctx context.Context, path string, content io.Reader)
return "", errorWithStderr(err, stderr.Bytes())
}
- oid, err := git.NewObjectIDFromHex(text.ChompBytes(stdout.Bytes()))
+ oid, err := git.ObjectHashSHA1.FromHex(text.ChompBytes(stdout.Bytes()))
if err != nil {
return "", err
}
@@ -159,7 +159,7 @@ func (repo *Repo) WriteTag(
return "", MktagError{tagName: tagName, stderr: stderr.String()}
}
- tagID, err := git.NewObjectIDFromHex(text.ChompBytes(stdout.Bytes()))
+ tagID, err := git.ObjectHashSHA1.FromHex(text.ChompBytes(stdout.Bytes()))
if err != nil {
return "", fmt.Errorf("could not parse tag ID: %w", err)
}
diff --git a/internal/git/localrepo/objects_test.go b/internal/git/localrepo/objects_test.go
index ff7d5982b..c5c5b1245 100644
--- a/internal/git/localrepo/objects_test.go
+++ b/internal/git/localrepo/objects_test.go
@@ -103,7 +103,7 @@ func TestFormatTag(t *testing.T) {
// internal/gitaly/service/operations/tags_test.go
{
desc: "basic signature",
- objectID: git.ZeroOID,
+ objectID: git.ObjectHashSHA1.ZeroOID,
objectType: "commit",
tagName: []byte("my-tag"),
author: &gitalypb.User{
@@ -114,7 +114,7 @@ func TestFormatTag(t *testing.T) {
},
{
desc: "basic signature",
- objectID: git.ZeroOID,
+ objectID: git.ObjectHashSHA1.ZeroOID,
objectType: "commit",
tagName: []byte("my-tag\ninjection"),
tagBody: []byte(""),
@@ -126,7 +126,7 @@ func TestFormatTag(t *testing.T) {
},
{
desc: "signature with fixed time",
- objectID: git.ZeroOID,
+ objectID: git.ObjectHashSHA1.ZeroOID,
objectType: "commit",
tagName: []byte("my-tag"),
tagBody: []byte(""),
@@ -243,8 +243,8 @@ func TestRepo_ReadObject(t *testing.T) {
}{
{
desc: "invalid object",
- oid: git.ZeroOID,
- error: InvalidObjectError(git.ZeroOID.String()),
+ oid: git.ObjectHashSHA1.ZeroOID,
+ error: InvalidObjectError(git.ObjectHashSHA1.ZeroOID.String()),
},
{
desc: "valid object",
@@ -275,12 +275,12 @@ func TestRepo_ReadCommit(t *testing.T) {
}{
{
desc: "invalid commit",
- revision: git.ZeroOID.Revision(),
+ revision: git.ObjectHashSHA1.ZeroOID.Revision(),
expectedErr: ErrObjectNotFound,
},
{
desc: "invalid commit with trailers",
- revision: git.ZeroOID.Revision(),
+ revision: git.ObjectHashSHA1.ZeroOID.Revision(),
expectedErr: ErrObjectNotFound,
opts: []ReadCommitOpt{WithTrailers()},
},
@@ -424,18 +424,18 @@ func TestRepo_IsAncestor(t *testing.T) {
},
{
desc: "parent is not valid commit",
- parent: git.ZeroOID.Revision(),
+ parent: git.ObjectHashSHA1.ZeroOID.Revision(),
child: "HEAD",
errorMatcher: func(t testing.TB, err error) {
- require.Equal(t, InvalidCommitError(git.ZeroOID), err)
+ require.Equal(t, InvalidCommitError(git.ObjectHashSHA1.ZeroOID), err)
},
},
{
desc: "child is not valid commit",
parent: "HEAD",
- child: git.ZeroOID.Revision(),
+ child: git.ObjectHashSHA1.ZeroOID.Revision(),
errorMatcher: func(t testing.TB, err error) {
- require.Equal(t, InvalidCommitError(git.ZeroOID), err)
+ require.Equal(t, InvalidCommitError(git.ObjectHashSHA1.ZeroOID), err)
},
},
{
diff --git a/internal/git/localrepo/refs.go b/internal/git/localrepo/refs.go
index 60a807d23..492609d7a 100644
--- a/internal/git/localrepo/refs.go
+++ b/internal/git/localrepo/refs.go
@@ -57,7 +57,7 @@ func (repo *Repo) ResolveRevision(ctx context.Context, revision git.Revision) (g
}
hex := strings.TrimSpace(stdout.String())
- oid, err := git.NewObjectIDFromHex(hex)
+ oid, err := git.ObjectHashSHA1.FromHex(hex)
if err != nil {
return "", fmt.Errorf("unsupported object hash %q: %w", hex, err)
}
diff --git a/internal/git/localrepo/refs_test.go b/internal/git/localrepo/refs_test.go
index bbb782b9c..1b7ed148f 100644
--- a/internal/git/localrepo/refs_test.go
+++ b/internal/git/localrepo/refs_test.go
@@ -138,7 +138,7 @@ func TestRepo_GetReferenceWithAmbiguousRefs(t *testing.T) {
"refs/master",
"refs/tags/master",
} {
- require.NoError(t, repo.UpdateRef(ctx, ref, prevOID, git.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, ref, prevOID, git.ObjectHashSHA1.ZeroOID))
}
ref, err := repo.GetReference(ctx, "refs/heads/master")
@@ -423,7 +423,7 @@ func TestRepo_UpdateRef(t *testing.T) {
{
desc: "deleting master succeeds",
ref: "refs/heads/master",
- newValue: git.ZeroOID,
+ newValue: git.ObjectHashSHA1.ZeroOID,
oldValue: masterOID,
verify: func(t *testing.T, repo *Repo, err error) {
require.NoError(t, err)
@@ -435,7 +435,7 @@ func TestRepo_UpdateRef(t *testing.T) {
desc: "creating new branch succeeds",
ref: "refs/heads/new",
newValue: masterOID,
- oldValue: git.ZeroOID,
+ oldValue: git.ObjectHashSHA1.ZeroOID,
verify: func(t *testing.T, repo *Repo, err error) {
require.NoError(t, err)
ref, err := repo.GetReference(ctx, "refs/heads/new")
diff --git a/internal/git/localrepo/remote_extra_test.go b/internal/git/localrepo/remote_extra_test.go
index d0676b0eb..634229054 100644
--- a/internal/git/localrepo/remote_extra_test.go
+++ b/internal/git/localrepo/remote_extra_test.go
@@ -212,7 +212,7 @@ func TestRepo_FetchInternal(t *testing.T) {
// Create a local reference. Given that it doesn't exist on the remote side, it
// would get pruned if we pass `--prune`.
- require.NoError(t, repo.UpdateRef(ctx, "refs/heads/prune-me", remoteOID, git.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, "refs/heads/prune-me", remoteOID, git.ObjectHashSHA1.ZeroOID))
// By default, refs are not pruned.
require.NoError(t, repo.FetchInternal(
diff --git a/internal/git/lstree/parser.go b/internal/git/lstree/parser.go
index d60a9e126..2a35df472 100644
--- a/internal/git/lstree/parser.go
+++ b/internal/git/lstree/parser.go
@@ -61,7 +61,7 @@ func (p *Parser) NextEntry() (*Entry, error) {
return nil, err
}
- objectID, err := git.NewObjectIDFromHex(string(treeEntryID))
+ objectID, err := git.ObjectHashSHA1.FromHex(string(treeEntryID))
if err != nil {
return nil, err
}
diff --git a/internal/git/object_id.go b/internal/git/object_id.go
new file mode 100644
index 000000000..4d6083a12
--- /dev/null
+++ b/internal/git/object_id.go
@@ -0,0 +1,116 @@
+package git
+
+import (
+ "bytes"
+ "context"
+ "encoding/hex"
+ "errors"
+ "fmt"
+ "regexp"
+
+ "gitlab.com/gitlab-org/gitaly/v15/internal/command"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
+)
+
+var (
+ // ObjectHashSHA1 is the implementation of an object ID via SHA1.
+ ObjectHashSHA1 = ObjectHash{
+ regexp: regexp.MustCompile(`\A[0-9a-f]{40}\z`),
+ EmptyTreeOID: ObjectID("4b825dc642cb6eb9a060e54bf8d69288fbee4904"),
+ ZeroOID: ObjectID("0000000000000000000000000000000000000000"),
+ }
+
+ // ObjectHashSHA256 is the implementation of an object ID via SHA256.
+ ObjectHashSHA256 = ObjectHash{
+ regexp: regexp.MustCompile(`\A[0-9a-f]{64}\z`),
+ EmptyTreeOID: ObjectID("6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321"),
+ ZeroOID: ObjectID("0000000000000000000000000000000000000000000000000000000000000000"),
+ }
+
+ // ErrInvalidObjectID is returned in case an object ID's string
+ // representation is not a valid one.
+ ErrInvalidObjectID = errors.New("invalid object ID")
+)
+
+// 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
+ // ZeroOID is the special value that Git uses to signal a ref or object does not exist
+ ZeroOID ObjectID
+}
+
+// DetectObjectHash detects the object-hash used by the given repository.
+func DetectObjectHash(ctx context.Context, repoExecutor RepositoryExecutor) (ObjectHash, error) {
+ var stdout bytes.Buffer
+
+ if err := repoExecutor.ExecAndWait(ctx, SubCmd{
+ Name: "config",
+ Args: []string{"extensions.objectFormat"},
+ }, WithStdout(&stdout)); err != nil {
+ if status, ok := command.ExitStatus(err); ok && status == 1 {
+ return ObjectHashSHA1, nil
+ }
+
+ return ObjectHash{}, fmt.Errorf("reading object format: %w", err)
+ }
+
+ objectFormat := text.ChompBytes(stdout.Bytes())
+ switch objectFormat {
+ case "sha1":
+ return ObjectHashSHA1, nil
+ case "sha256":
+ return ObjectHashSHA256, nil
+ default:
+ return ObjectHash{}, fmt.Errorf("unknown object format: %q", objectFormat)
+ }
+}
+
+// FromHex constructs a new ObjectID from the given hex representation of the object ID. Returns
+// ErrInvalidObjectID if the given object ID is not valid.
+func (h ObjectHash) FromHex(hex string) (ObjectID, error) {
+ if err := h.ValidateHex(hex); err != nil {
+ return "", err
+ }
+
+ return ObjectID(hex), nil
+}
+
+// ValidateHex checks if `hex` is a syntactically correct object ID for the given hash. Abbreviated
+// object IDs are not deemed to be valid. Returns an `ErrInvalidObjectID` if the `hex` is not valid.
+func (h ObjectHash) ValidateHex(hex string) error {
+ if h.regexp.MatchString(hex) {
+ return nil
+ }
+
+ return fmt.Errorf("%w: %q", ErrInvalidObjectID, hex)
+}
+
+// IsZeroOID checks whether the given object ID is the all-zeroes object ID for the given hash.
+func (h ObjectHash) IsZeroOID(oid ObjectID) bool {
+ return string(oid) == string(h.ZeroOID)
+}
+
+// ObjectID represents an object ID.
+type ObjectID string
+
+// String returns the hex representation of the ObjectID.
+func (oid ObjectID) String() string {
+ return string(oid)
+}
+
+// Bytes returns the byte representation of the ObjectID.
+func (oid ObjectID) Bytes() ([]byte, error) {
+ decoded, err := hex.DecodeString(string(oid))
+ if err != nil {
+ return nil, err
+ }
+ return decoded, nil
+}
+
+// Revision returns a revision of the ObjectID. This directly returns the hex
+// representation as every object ID is a valid revision.
+func (oid ObjectID) Revision() Revision {
+ return Revision(oid.String())
+}
diff --git a/internal/git/object_id_test.go b/internal/git/object_id_test.go
new file mode 100644
index 000000000..a6b62ffdc
--- /dev/null
+++ b/internal/git/object_id_test.go
@@ -0,0 +1,312 @@
+//go:build !gitaly_test_sha256
+
+package git_test
+
+import (
+ "bytes"
+ "encoding/hex"
+ "fmt"
+ "path/filepath"
+ "strings"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg"
+ "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
+)
+
+func TestDetectObjectHash(t *testing.T) {
+ cfg := testcfg.Build(t)
+ ctx := testhelper.Context(t)
+
+ for _, tc := range []struct {
+ desc string
+ setup func(t *testing.T) *gitalypb.Repository
+ expectedErr error
+ expectedHash git.ObjectHash
+ }{
+ {
+ desc: "defaults to SHA1",
+ setup: func(t *testing.T) *gitalypb.Repository {
+ repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{
+ ObjectFormat: "sha1",
+ })
+
+ // Verify that the repo doesn't explicitly mention it's using SHA1
+ // as object hash.
+ content := testhelper.MustReadFile(t, filepath.Join(repoPath, "config"))
+ require.NotContains(t, text.ChompBytes(content), "sha1")
+
+ return repo
+ },
+ expectedHash: git.ObjectHashSHA1,
+ },
+ {
+ desc: "explicitly set to SHA1",
+ setup: func(t *testing.T) *gitalypb.Repository {
+ repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{
+ ObjectFormat: "sha1",
+ })
+
+ // Explicitly set the object format to SHA1.
+ gittest.Exec(t, cfg, "-C", repoPath, "config", "extensions.objectFormat", "sha1")
+
+ return repo
+ },
+ expectedHash: git.ObjectHashSHA1,
+ },
+ {
+ desc: "explicitly set to SHA256",
+ setup: func(t *testing.T) *gitalypb.Repository {
+ repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{
+ ObjectFormat: "sha256",
+ })
+
+ require.Equal(t,
+ "sha256",
+ text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "config", "extensions.objectFormat")),
+ )
+
+ return repo
+ },
+ expectedHash: git.ObjectHashSHA256,
+ },
+ {
+ desc: "unknown hash",
+ setup: func(t *testing.T) *gitalypb.Repository {
+ repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+
+ // Explicitly set the object format to something unknown.
+ gittest.Exec(t, cfg, "-C", repoPath, "config", "extensions.objectFormat", "blake2")
+
+ return repo
+ },
+ expectedErr: fmt.Errorf("reading object format: exit status 128"),
+ },
+ } {
+ t.Run(tc.desc, func(t *testing.T) {
+ repoProto := tc.setup(t)
+ repo := localrepo.NewTestRepo(t, cfg, repoProto)
+
+ hash, err := git.DetectObjectHash(ctx, repo)
+ if tc.expectedErr != nil {
+ require.EqualError(t, err, tc.expectedErr.Error())
+ } else {
+ require.NoError(t, err)
+ }
+ require.Equal(t, tc.expectedHash, hash)
+ })
+ }
+}
+
+func TestObjectHash_ValidateHex(t *testing.T) {
+ for _, hash := range []struct {
+ desc string
+ hash git.ObjectHash
+ validHex string
+ }{
+ {
+ desc: "SHA1",
+ hash: git.ObjectHashSHA1,
+ validHex: "356e7793f9654d51dfb27312a1464062bceb9fa3",
+ },
+ {
+ desc: "SHA256",
+ hash: git.ObjectHashSHA256,
+ validHex: "aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f",
+ },
+ } {
+ t.Run(hash.desc, func(t *testing.T) {
+ for _, tc := range []struct {
+ desc string
+ hex string
+ valid bool
+ }{
+ {
+ desc: "valid object ID",
+ hex: hash.validHex,
+ valid: true,
+ },
+ {
+ desc: "object ID with non-hex characters fails",
+ hex: "x" + hash.validHex[1:],
+ valid: false,
+ },
+ {
+ desc: "object ID with upper-case letters fails",
+ hex: strings.ToUpper(hash.validHex),
+ valid: false,
+ },
+ {
+ desc: "too short object ID fails",
+ hex: hash.validHex[:len(hash.validHex)-1],
+ valid: false,
+ },
+ {
+ desc: "too long object ID fails",
+ hex: hash.validHex + "3",
+ valid: false,
+ },
+ {
+ desc: "empty string fails",
+ hex: "",
+ valid: false,
+ },
+ } {
+ t.Run(tc.desc, func(t *testing.T) {
+ err := hash.hash.ValidateHex(tc.hex)
+ if tc.valid {
+ require.NoError(t, err)
+ } else {
+ require.Error(t, err)
+ require.EqualError(t, err, fmt.Sprintf("invalid object ID: %q", tc.hex))
+ }
+ })
+ }
+ })
+ }
+}
+
+func TestObjectHash_FromHex(t *testing.T) {
+ for _, hash := range []struct {
+ desc string
+ hash git.ObjectHash
+ validHex string
+ }{
+ {
+ desc: "SHA1",
+ hash: git.ObjectHashSHA1,
+ validHex: "356e7793f9654d51dfb27312a1464062bceb9fa3",
+ },
+ {
+ desc: "SHA256",
+ hash: git.ObjectHashSHA256,
+ validHex: "aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f",
+ },
+ } {
+ t.Run(hash.desc, func(t *testing.T) {
+ for _, tc := range []struct {
+ desc string
+ hex string
+ valid bool
+ }{
+ {
+ desc: "valid object ID",
+ hex: hash.validHex,
+ valid: true,
+ },
+ {
+ desc: "object ID with non-hex characters fails",
+ hex: "x" + hash.validHex[1:],
+ valid: false,
+ },
+ {
+ desc: "object ID with upper-case letters fails",
+ hex: strings.ToUpper(hash.validHex),
+ valid: false,
+ },
+ {
+ desc: "too short object ID fails",
+ hex: hash.validHex[:len(hash.validHex)-1],
+ valid: false,
+ },
+ {
+ desc: "too long object ID fails",
+ hex: hash.validHex + "3",
+ valid: false,
+ },
+ {
+ desc: "empty string fails",
+ hex: "",
+ valid: false,
+ },
+ } {
+ t.Run(tc.desc, func(t *testing.T) {
+ oid, err := hash.hash.FromHex(tc.hex)
+ if tc.valid {
+ require.NoError(t, err)
+ require.Equal(t, tc.hex, oid.String())
+ } else {
+ require.Error(t, err)
+ }
+ })
+ }
+ })
+ }
+}
+
+func TestObjectID_Bytes(t *testing.T) {
+ for _, tc := range []struct {
+ desc string
+ oid git.ObjectID
+ expectedBytes []byte
+ expectedErr error
+ }{
+ {
+ desc: "zero OID",
+ oid: git.ObjectHashSHA1.ZeroOID,
+ expectedBytes: bytes.Repeat([]byte{0}, 20),
+ },
+ {
+ desc: "valid object ID",
+ oid: git.ObjectID(strings.Repeat("8", 40)),
+ expectedBytes: bytes.Repeat([]byte{0x88}, 20),
+ },
+ {
+ desc: "invalid object ID",
+ oid: git.ObjectID(strings.Repeat("8", 39) + "x"),
+ expectedErr: hex.InvalidByteError('x'),
+ },
+ } {
+ t.Run(tc.desc, func(t *testing.T) {
+ actualBytes, err := tc.oid.Bytes()
+ require.Equal(t, tc.expectedErr, err)
+ require.Equal(t, tc.expectedBytes, actualBytes)
+ })
+ }
+}
+
+func TestObjectHash_IsZeroOID(t *testing.T) {
+ for _, hash := range []struct {
+ desc string
+ hash git.ObjectHash
+ validHex string
+ }{
+ {
+ desc: "SHA1",
+ hash: git.ObjectHashSHA1,
+ },
+ {
+ desc: "SHA256",
+ hash: git.ObjectHashSHA256,
+ },
+ } {
+ t.Run(hash.desc, func(t *testing.T) {
+ for _, tc := range []struct {
+ desc string
+ oid git.ObjectID
+ isZero bool
+ }{
+ {
+ desc: "zero object ID",
+ oid: hash.hash.ZeroOID,
+ isZero: true,
+ },
+ {
+ desc: "zero object ID",
+ oid: hash.hash.EmptyTreeOID,
+ isZero: false,
+ },
+ } {
+ t.Run(tc.desc, func(t *testing.T) {
+ require.Equal(t, tc.isZero, hash.hash.IsZeroOID(tc.oid))
+ })
+ }
+ })
+ }
+}
diff --git a/internal/git/remoterepo/repository.go b/internal/git/remoterepo/repository.go
index caaec9aa6..fb3fe0273 100644
--- a/internal/git/remoterepo/repository.go
+++ b/internal/git/remoterepo/repository.go
@@ -52,7 +52,7 @@ func (rr *Repo) ResolveRevision(ctx context.Context, revision git.Revision) (git
return "", git.ErrReferenceNotFound
}
- oid, err := git.NewObjectIDFromHex(oidHex)
+ oid, err := git.ObjectHashSHA1.FromHex(oidHex)
if err != nil {
return "", err
}
diff --git a/internal/git/sha256/id.go b/internal/git/sha256/id.go
deleted file mode 100644
index 42a4a7c5f..000000000
--- a/internal/git/sha256/id.go
+++ /dev/null
@@ -1,36 +0,0 @@
-package sha256
-
-import (
- "fmt"
- "regexp"
-
- "gitlab.com/gitlab-org/gitaly/v15/internal/git"
-)
-
-const (
- // EmptyTreeOID is the Git tree object sha256 hash that corresponds to an empty tree (directory)
- EmptyTreeOID = git.ObjectID("6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321")
-)
-
-var objectIDRegex = regexp.MustCompile(`\A[0-9a-f]{64}\z`)
-
-// NewObjectIDFromHex constructs a new ObjectID from the given hex
-// representation of the object ID. Returns ErrInvalidObjectID if the given
-// OID is not valid.
-func NewObjectIDFromHex(hex string) (git.ObjectID, error) {
- if err := ValidateObjectID(hex); err != nil {
- return "", err
- }
- return git.ObjectID(hex), nil
-}
-
-// ValidateObjectID checks if id is a syntactically correct object ID. Abbreviated
-// object IDs are not deemed to be valid. Returns an ErrInvalidObjectID if the
-// id is not valid.
-func ValidateObjectID(id string) error {
- if objectIDRegex.MatchString(id) {
- return nil
- }
-
- return fmt.Errorf("%w: %q", git.ErrInvalidObjectID, id)
-}
diff --git a/internal/git/sha256/id_test.go b/internal/git/sha256/id_test.go
deleted file mode 100644
index 1be75e98f..000000000
--- a/internal/git/sha256/id_test.go
+++ /dev/null
@@ -1,106 +0,0 @@
-package sha256
-
-import (
- "fmt"
- "testing"
-
- "github.com/stretchr/testify/require"
-)
-
-func TestValidateObjectID(t *testing.T) {
- for _, tc := range []struct {
- desc string
- oid string
- valid bool
- }{
- {
- desc: "valid object ID",
- oid: "cff96308c1b0c36602ca031013b563074edddb203efa61c4f01be1bd2482d92e",
- valid: true,
- },
- {
- desc: "object ID with non-hex characters fails",
- oid: "xff96308c1b0c36602ca031013b563074edddb203efa61c4f01be1bd2482d92e",
- valid: false,
- },
- {
- desc: "object ID with upper-case letters fails",
- oid: "CFF96308C1B0C36602CA031013B563074EDDDB203EFA61C4F01BE1BD2482D92E",
- valid: false,
- },
- {
- desc: "too short object ID fails",
- oid: "cff96308c1b0c36602ca031013b563074edddb203efa61c4f01be1bd2482d92",
- valid: false,
- },
- {
- desc: "too long object ID fails",
- oid: "cff96308c1b0c36602ca031013b563074edddb203efa61c4f01be1bd2482d92eb",
- valid: false,
- },
- {
- desc: "empty string fails",
- oid: "",
- valid: false,
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- err := ValidateObjectID(tc.oid)
- if tc.valid {
- require.NoError(t, err)
- } else {
- require.Error(t, err)
- require.EqualError(t, err, fmt.Sprintf("invalid object ID: %q", tc.oid))
- }
- })
- }
-}
-
-func TestNewObjectIDFromHex(t *testing.T) {
- for _, tc := range []struct {
- desc string
- oid string
- valid bool
- }{
- {
- desc: "valid object ID",
- oid: "cff96308c1b0c36602ca031013b563074edddb203efa61c4f01be1bd2482d92e",
- valid: true,
- },
- {
- desc: "object ID with non-hex characters fails",
- oid: "xff96308c1b0c36602ca031013b563074edddb203efa61c4f01be1bd2482d92e",
- valid: false,
- },
- {
- desc: "object ID with upper-case letters fails",
- oid: "CFF96308C1B0C36602CA031013B563074EDDDB203EFA61C4F01BE1BD2482D92E",
- valid: false,
- },
- {
- desc: "too short object ID fails",
- oid: "cff96308c1b0c36602ca031013b563074edddb203efa61c4f01be1bd2482d92",
- valid: false,
- },
- {
- desc: "too long object ID fails",
- oid: "cff96308c1b0c36602ca031013b563074edddb203efa61c4f01be1bd2482d92eb",
- valid: false,
- },
- {
- desc: "empty string fails",
- oid: "",
- valid: false,
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- oid, err := NewObjectIDFromHex(tc.oid)
- if tc.valid {
- require.NoError(t, err)
- require.Equal(t, tc.oid, oid.String())
- } else {
- require.Error(t, err)
- }
- })
- }
-}
diff --git a/internal/git/stats/http_push_test.go b/internal/git/stats/http_push_test.go
index aa4999ad6..f589aa30f 100644
--- a/internal/git/stats/http_push_test.go
+++ b/internal/git/stats/http_push_test.go
@@ -51,7 +51,7 @@ func TestPerformHTTPPush(t *testing.T) {
)
return []PushCommand{
- {OldOID: git.ZeroOID, NewOID: commit, Reference: "refs/heads/foobar"},
+ {OldOID: git.ObjectHashSHA1.ZeroOID, NewOID: commit, Reference: "refs/heads/foobar"},
}, bytes.NewReader(pack)
},
expectedTimings: []string{
@@ -84,7 +84,7 @@ func TestPerformHTTPPush(t *testing.T) {
commit := gittest.WriteCommit(t, cfg, repoPath)
commits[i] = commit.String()
commands[i] = PushCommand{
- OldOID: git.ZeroOID,
+ OldOID: git.ObjectHashSHA1.ZeroOID,
NewOID: commit,
Reference: git.ReferenceName(fmt.Sprintf("refs/heads/branch-%d", i)),
}
@@ -123,7 +123,7 @@ func TestPerformHTTPPush(t *testing.T) {
oldOID := git.ObjectID(text.ChompBytes(commit))
return []PushCommand{
- {OldOID: oldOID, NewOID: git.ZeroOID, Reference: "refs/heads/feature"},
+ {OldOID: oldOID, NewOID: git.ObjectHashSHA1.ZeroOID, Reference: "refs/heads/feature"},
}, nil
},
expectedTimings: []string{
@@ -151,7 +151,7 @@ func TestPerformHTTPPush(t *testing.T) {
oldOID := git.ObjectID(strings.Repeat("1", 40))
return []PushCommand{
- {OldOID: oldOID, NewOID: git.ZeroOID, Reference: "refs/heads/master"},
+ {OldOID: oldOID, NewOID: git.ObjectHashSHA1.ZeroOID, Reference: "refs/heads/master"},
}, nil
},
expectedErr: fmt.Errorf("parsing packfile response: %w",
diff --git a/internal/git/updateref/update_with_hooks.go b/internal/git/updateref/update_with_hooks.go
index fe5cf75df..787711cc8 100644
--- a/internal/git/updateref/update_with_hooks.go
+++ b/internal/git/updateref/update_with_hooks.go
@@ -163,10 +163,10 @@ func (u *UpdaterWithHooks) UpdateReference(
if reference == "" {
return fmt.Errorf("reference cannot be empty")
}
- if err := git.ValidateObjectID(oldrev.String()); err != nil {
+ if err := git.ObjectHashSHA1.ValidateHex(oldrev.String()); err != nil {
return fmt.Errorf("validating old value: %w", err)
}
- if err := git.ValidateObjectID(newrev.String()); err != nil {
+ if err := git.ObjectHashSHA1.ValidateHex(newrev.String()); err != nil {
return fmt.Errorf("validating new value: %w", err)
}
diff --git a/internal/git/updateref/update_with_hooks_test.go b/internal/git/updateref/update_with_hooks_test.go
index 2b759f689..7bd5a2e2b 100644
--- a/internal/git/updateref/update_with_hooks_test.go
+++ b/internal/git/updateref/update_with_hooks_test.go
@@ -147,7 +147,7 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) {
preReceive: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error {
changes, err := io.ReadAll(stdin)
require.NoError(t, err)
- require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ZeroOID.String()), string(changes))
+ require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ObjectHashSHA1.ZeroOID.String()), string(changes))
require.Empty(t, pushOptions)
requirePayload(t, env)
return nil
@@ -155,14 +155,14 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) {
update: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error {
require.Equal(t, "refs/heads/master", ref)
require.Equal(t, oldRev, oldValue)
- require.Equal(t, newValue, git.ZeroOID.String())
+ require.Equal(t, newValue, git.ObjectHashSHA1.ZeroOID.String())
requirePayload(t, env)
return nil
},
postReceive: func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error {
changes, err := io.ReadAll(stdin)
require.NoError(t, err)
- require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ZeroOID.String()), string(changes))
+ require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ObjectHashSHA1.ZeroOID.String()), string(changes))
requirePayload(t, env)
require.Empty(t, pushOptions)
return nil
@@ -170,7 +170,7 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) {
referenceTransaction: func(t *testing.T, ctx context.Context, state hook.ReferenceTransactionState, env []string, stdin io.Reader) error {
changes, err := io.ReadAll(stdin)
require.NoError(t, err)
- require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ZeroOID.String()), string(changes))
+ require.Equal(t, fmt.Sprintf("%s %s refs/heads/master\n", oldRev, git.ObjectHashSHA1.ZeroOID.String()), string(changes))
require.Less(t, referenceTransactionCalls, 2)
if referenceTransactionCalls == 0 {
@@ -257,7 +257,7 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) {
gitCmdFactory := gittest.NewCommandFactory(t, cfg)
updater := updateref.NewUpdaterWithHooks(cfg, config.NewLocator(cfg), hookManager, gitCmdFactory, nil)
- err := updater.UpdateReference(ctx, repo, user, nil, git.ReferenceName("refs/heads/master"), git.ZeroOID, git.ObjectID(oldRev))
+ err := updater.UpdateReference(ctx, repo, user, nil, git.ReferenceName("refs/heads/master"), git.ObjectHashSHA1.ZeroOID, git.ObjectID(oldRev))
if tc.expectedErr == "" {
require.NoError(t, err)
} else {
@@ -367,7 +367,7 @@ func TestUpdaterWithHooks_quarantine(t *testing.T) {
},
quarantine,
git.ReferenceName("refs/heads/master"),
- git.ZeroOID,
+ git.ObjectHashSHA1.ZeroOID,
git.ObjectID("1e292f8fedd741b75372e19097c76d327140c312"),
))
diff --git a/internal/git/updateref/updateref.go b/internal/git/updateref/updateref.go
index cc97513cc..c8f446720 100644
--- a/internal/git/updateref/updateref.go
+++ b/internal/git/updateref/updateref.go
@@ -105,13 +105,13 @@ func (u *Updater) Update(reference git.ReferenceName, newvalue, oldvalue string)
// Create commands the reference to be created with the given object ID. The ref must not exist.
func (u *Updater) Create(reference git.ReferenceName, value string) error {
- return u.Update(reference, value, git.ZeroOID.String())
+ return u.Update(reference, value, git.ObjectHashSHA1.ZeroOID.String())
}
// Delete commands the reference to be removed from the repository. This command will ignore any old
// state of the reference and just force-remove it.
func (u *Updater) Delete(reference git.ReferenceName) error {
- return u.Update(reference, git.ZeroOID.String(), "")
+ return u.Update(reference, git.ObjectHashSHA1.ZeroOID.String(), "")
}
// Prepare prepares the reference transaction by locking all references and determining their
diff --git a/internal/git/updateref/updateref_test.go b/internal/git/updateref/updateref_test.go
index d48a75432..0de5f698c 100644
--- a/internal/git/updateref/updateref_test.go
+++ b/internal/git/updateref/updateref_test.go
@@ -262,7 +262,7 @@ func TestUpdater_capturesStderr(t *testing.T) {
ref := "refs/heads/a"
newValue := strings.Repeat("1", 40)
- oldValue := git.ZeroOID.String()
+ oldValue := git.ObjectHashSHA1.ZeroOID.String()
require.NoError(t, updater.Update(git.ReferenceName(ref), newValue, oldValue))
diff --git a/internal/git2go/apply.go b/internal/git2go/apply.go
index 600890ca0..2bee12857 100644
--- a/internal/git2go/apply.go
+++ b/internal/git2go/apply.go
@@ -118,7 +118,7 @@ func (b *Executor) Apply(ctx context.Context, repo repository.GitRepo, params Ap
return "", result.Err
}
- commitID, err := git.NewObjectIDFromHex(result.CommitID)
+ commitID, err := git.ObjectHashSHA1.FromHex(result.CommitID)
if err != nil {
return "", fmt.Errorf("could not parse commit ID: %w", err)
}
diff --git a/internal/git2go/commit.go b/internal/git2go/commit.go
index 068125d5b..13edb4faa 100644
--- a/internal/git2go/commit.go
+++ b/internal/git2go/commit.go
@@ -80,7 +80,7 @@ func (b *Executor) Commit(ctx context.Context, repo repository.GitRepo, params C
return "", result.Err
}
- commitID, err := git.NewObjectIDFromHex(result.CommitID)
+ commitID, err := git.ObjectHashSHA1.FromHex(result.CommitID)
if err != nil {
return "", fmt.Errorf("could not parse commit ID: %w", err)
}
diff --git a/internal/git2go/executor.go b/internal/git2go/executor.go
index f1e594779..9524f03b1 100644
--- a/internal/git2go/executor.go
+++ b/internal/git2go/executor.go
@@ -123,7 +123,7 @@ func (b *Executor) runWithGob(ctx context.Context, repo repository.GitRepo, cmd
return "", fmt.Errorf("%s: %w", cmd, result.Err)
}
- commitID, err := git.NewObjectIDFromHex(result.CommitID)
+ commitID, err := git.ObjectHashSHA1.FromHex(result.CommitID)
if err != nil {
return "", fmt.Errorf("could not parse commit ID: %w", err)
}
diff --git a/internal/gitaly/diff/diff.go b/internal/gitaly/diff/diff.go
index 57429a1e5..f33c630e1 100644
--- a/internal/gitaly/diff/diff.go
+++ b/internal/gitaly/diff/diff.go
@@ -328,13 +328,13 @@ func (parser *Parser) handleTypeChangeDiff() {
":%o %o %s %s A\t%s\n",
0,
parser.currentDiff.NewMode,
- git.ZeroOID,
+ git.ObjectHashSHA1.ZeroOID,
parser.currentDiff.ToID,
parser.currentDiff.FromPath,
)
parser.currentDiff.NewMode = 0
- parser.currentDiff.ToID = git.ZeroOID.String()
+ parser.currentDiff.ToID = git.ObjectHashSHA1.ZeroOID.String()
parser.rawLines = append([][]byte{[]byte(newRawLine)}, parser.rawLines...)
}
diff --git a/internal/gitaly/diff/diff_test.go b/internal/gitaly/diff/diff_test.go
index 172c0f6df..04d3bc3f6 100644
--- a/internal/gitaly/diff/diff_test.go
+++ b/internal/gitaly/diff/diff_test.go
@@ -49,7 +49,7 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5
{
OldMode: 0,
NewMode: 0o100644,
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "4cc7061661b8f52891bc1b39feb4d856b21a1067",
FromPath: []byte("big.txt"),
ToPath: []byte("big.txt"),
@@ -60,7 +60,7 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5
{
OldMode: 0,
NewMode: 0o100644,
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "3be11c69355948412925fa5e073d76d58ff3afd2",
FromPath: []byte("file-00.txt"),
ToPath: []byte("file-00.txt"),
@@ -268,7 +268,7 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5
{
OldMode: 0,
NewMode: 0o100644,
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "4cc7061661b8f52891bc1b39feb4d856b21a1067",
FromPath: []byte("big.txt"),
ToPath: []byte("big.txt"),
@@ -280,7 +280,7 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5
{
OldMode: 0,
NewMode: 0o100644,
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "3be11c69355948412925fa5e073d76d58ff3afd2",
FromPath: []byte("file-00.txt"),
ToPath: []byte("file-00.txt"),
@@ -331,7 +331,7 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5
{
OldMode: 0,
NewMode: 0o100644,
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "4cc7061661b8f52891bc1b39feb4d856b21a1067",
FromPath: []byte("big.txt"),
ToPath: []byte("big.txt"),
@@ -344,7 +344,7 @@ index 0000000000000000000000000000000000000000..3be11c69355948412925fa5e073d76d5
{
OldMode: 0,
NewMode: 0o100644,
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "3be11c69355948412925fa5e073d76d58ff3afd2",
FromPath: []byte("file-00.txt"),
ToPath: []byte("file-00.txt"),
@@ -394,7 +394,7 @@ index 0000000000000000000000000000000000000000..b6507e5b5ce18077e3ec8aaa2291404e
{
OldMode: 0,
NewMode: 0o100644,
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "b6507e5b5ce18077e3ec8aaa2291404e5051d45d",
FromPath: []byte("expand-collapse/file-0.txt"),
ToPath: []byte("expand-collapse/file-0.txt"),
@@ -406,7 +406,7 @@ index 0000000000000000000000000000000000000000..b6507e5b5ce18077e3ec8aaa2291404e
{
OldMode: 0,
NewMode: 0o100644,
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "b6507e5b5ce18077e3ec8aaa2291404e5051d45d",
FromPath: []byte("expand-collapse/file-1.txt"),
ToPath: []byte("expand-collapse/file-1.txt"),
@@ -418,7 +418,7 @@ index 0000000000000000000000000000000000000000..b6507e5b5ce18077e3ec8aaa2291404e
{
OldMode: 0,
NewMode: 0o100644,
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "b6507e5b5ce18077e3ec8aaa2291404e5051d45d",
FromPath: []byte("expand-collapse/file-2.txt"),
ToPath: []byte("expand-collapse/file-2.txt"),
@@ -452,7 +452,7 @@ index 0000000000000000000000000000000000000000..c3ae147b03a2d1fd89b25198b3fc5302
{
OldMode: 0,
NewMode: 0o100644,
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "c3ae147b03a2d1fd89b25198b3fc53028c5b0d53",
FromPath: []byte("file-0"),
ToPath: []byte("file-0"),
diff --git a/internal/gitaly/hook/postreceive_test.go b/internal/gitaly/hook/postreceive_test.go
index 7dcc9c32b..5fb125ad0 100644
--- a/internal/gitaly/hook/postreceive_test.go
+++ b/internal/gitaly/hook/postreceive_test.go
@@ -394,7 +394,7 @@ func TestPostReceive_quarantine(t *testing.T) {
require.NoError(t, err)
stdin := strings.NewReader(fmt.Sprintf("%s %s refs/heads/master",
- git.ZeroOID, git.ZeroOID))
+ git.ObjectHashSHA1.ZeroOID, git.ObjectHashSHA1.ZeroOID))
var stdout, stderr bytes.Buffer
require.NoError(t, hookManager.PostReceiveHook(ctx, repo, nil,
diff --git a/internal/gitaly/hook/prereceive_test.go b/internal/gitaly/hook/prereceive_test.go
index e1f48171e..f7bd01325 100644
--- a/internal/gitaly/hook/prereceive_test.go
+++ b/internal/gitaly/hook/prereceive_test.go
@@ -213,7 +213,7 @@ func TestPrereceive_quarantine(t *testing.T) {
require.NoError(t, err)
stdin := strings.NewReader(fmt.Sprintf("%s %s refs/heads/master",
- git.ZeroOID, git.ZeroOID))
+ git.ObjectHashSHA1.ZeroOID, git.ObjectHashSHA1.ZeroOID))
var stdout, stderr bytes.Buffer
require.NoError(t, hookManager.PreReceiveHook(ctx, repo, nil,
diff --git a/internal/gitaly/hook/referencetransaction.go b/internal/gitaly/hook/referencetransaction.go
index 25bb44ea1..2468f5eb6 100644
--- a/internal/gitaly/hook/referencetransaction.go
+++ b/internal/gitaly/hook/referencetransaction.go
@@ -14,7 +14,7 @@ import (
// forceDeletionPrefix is the prefix of a queued reference transaction which deletes a
// reference without checking its current value.
-var forceDeletionPrefix = fmt.Sprintf("%[1]s %[1]s ", git.ZeroOID.String())
+var forceDeletionPrefix = fmt.Sprintf("%[1]s %[1]s ", git.ObjectHashSHA1.ZeroOID.String())
//nolint: revive,stylecheck // This is unintentionally missing documentation.
func (m *GitLabHookManager) ReferenceTransactionHook(ctx context.Context, state ReferenceTransactionState, env []string, stdin io.Reader) error {
diff --git a/internal/gitaly/hook/transactions_test.go b/internal/gitaly/hook/transactions_test.go
index 4172243b8..1000b8420 100644
--- a/internal/gitaly/hook/transactions_test.go
+++ b/internal/gitaly/hook/transactions_test.go
@@ -60,7 +60,7 @@ func TestHookManager_stopCalled(t *testing.T) {
return hookManager.PreReceiveHook(ctx, repo, nil, []string{hooksPayload}, strings.NewReader("changes"), io.Discard, io.Discard)
}
updateFunc := func(t *testing.T) error {
- return hookManager.UpdateHook(ctx, repo, "ref", git.ZeroOID.String(), git.ZeroOID.String(), []string{hooksPayload}, io.Discard, io.Discard)
+ return hookManager.UpdateHook(ctx, repo, "ref", git.ObjectHashSHA1.ZeroOID.String(), git.ObjectHashSHA1.ZeroOID.String(), []string{hooksPayload}, io.Discard, io.Discard)
}
postReceiveFunc := func(t *testing.T) error {
return hookManager.PostReceiveHook(ctx, repo, nil, []string{hooksPayload}, strings.NewReader("changes"), io.Discard, io.Discard)
@@ -148,7 +148,7 @@ func TestHookManager_contextCancellationCancelsVote(t *testing.T) {
require.NoError(t, err)
ctx, cancel := context.WithCancel(testhelper.Context(t))
- changes := fmt.Sprintf("%s %s refs/heads/master", strings.Repeat("1", 40), git.ZeroOID)
+ changes := fmt.Sprintf("%s %s refs/heads/master", strings.Repeat("1", 40), git.ObjectHashSHA1.ZeroOID)
cancel()
@@ -158,7 +158,7 @@ func TestHookManager_contextCancellationCancelsVote(t *testing.T) {
func TestIsForceDeletionsOnly(t *testing.T) {
anyOID := strings.Repeat("1", 40)
- zeroOID := git.ZeroOID.String()
+ zeroOID := git.ObjectHashSHA1.ZeroOID.String()
forceDeletion := fmt.Sprintf("%s %s refs/heads/force-delete", zeroOID, zeroOID)
forceUpdate := fmt.Sprintf("%s %s refs/heads/force-update", zeroOID, anyOID)
diff --git a/internal/gitaly/hook/update.go b/internal/gitaly/hook/update.go
index 564e1550a..81251f6ca 100644
--- a/internal/gitaly/hook/update.go
+++ b/internal/gitaly/hook/update.go
@@ -39,10 +39,10 @@ func (m *GitLabHookManager) updateHook(ctx context.Context, payload git.HooksPay
if ref == "" {
return helper.ErrInternalf("hook got no reference")
}
- if err := git.ValidateObjectID(oldValue); err != nil {
+ if err := git.ObjectHashSHA1.ValidateHex(oldValue); err != nil {
return helper.ErrInternalf("hook got invalid old value: %w", err)
}
- if err := git.ValidateObjectID(newValue); err != nil {
+ if err := git.ObjectHashSHA1.ValidateHex(newValue); err != nil {
return helper.ErrInternalf("hook got invalid new value: %w", err)
}
if payload.UserDetails == nil {
diff --git a/internal/gitaly/hook/update_test.go b/internal/gitaly/hook/update_test.go
index 4a1652ad8..c5b47c76f 100644
--- a/internal/gitaly/hook/update_test.go
+++ b/internal/gitaly/hook/update_test.go
@@ -245,7 +245,7 @@ func TestUpdate_quarantine(t *testing.T) {
var stdout, stderr bytes.Buffer
require.NoError(t, hookManager.UpdateHook(ctx, repo, "refs/heads/master",
- git.ZeroOID.String(), git.ZeroOID.String(), []string{env}, &stdout, &stderr))
+ git.ObjectHashSHA1.ZeroOID.String(), git.ObjectHashSHA1.ZeroOID.String(), []string{env}, &stdout, &stderr))
if isQuarantined {
require.Equal(t, "allyourbasearebelongtous", stdout.String())
diff --git a/internal/gitaly/linguist/linguist.go b/internal/gitaly/linguist/linguist.go
index 145e4f8b9..696f70a4f 100644
--- a/internal/gitaly/linguist/linguist.go
+++ b/internal/gitaly/linguist/linguist.go
@@ -192,7 +192,7 @@ func (inst *Instance) enryStats(ctx context.Context, repo *localrepo.Repo, commi
skipDeleted := func(result *gitpipe.RevisionResult) bool {
// Skip files that are deleted.
- if result.OID.IsZeroOID() {
+ if git.ObjectHashSHA1.IsZeroOID(result.OID) {
// It's a little bit of a hack to use this skip
// function, but for every file that's deleted,
// remove the stats.
diff --git a/internal/gitaly/service/cleanup/apply_bfg_object_map_stream_test.go b/internal/gitaly/service/cleanup/apply_bfg_object_map_stream_test.go
index 5f498e99f..9bdacdfad 100644
--- a/internal/gitaly/service/cleanup/apply_bfg_object_map_stream_test.go
+++ b/internal/gitaly/service/cleanup/apply_bfg_object_map_stream_test.go
@@ -57,10 +57,10 @@ func TestApplyBfgObjectMapStreamSuccess(t *testing.T) {
const filterRepoCommitMapHeader = "old new\n"
objectMapData := fmt.Sprintf(
filterRepoCommitMapHeader+strings.Repeat("%s %s\n", 5),
- headCommit.Id, git.ZeroOID.String(),
- git.ZeroOID.String(), blobID,
- git.ZeroOID.String(), tagID,
- blobID, git.ZeroOID.String(),
+ headCommit.Id, git.ObjectHashSHA1.ZeroOID.String(),
+ git.ObjectHashSHA1.ZeroOID.String(), blobID,
+ git.ObjectHashSHA1.ZeroOID.String(), tagID,
+ blobID, git.ObjectHashSHA1.ZeroOID.String(),
tagID, tagID,
)
@@ -90,10 +90,10 @@ func TestApplyBfgObjectMapStreamSuccess(t *testing.T) {
// Ensure that the returned entry is correct
require.Len(t, entries, 4, "wrong number of entries returned")
- requireEntry(t, entries[0], headCommit.Id, git.ZeroOID.String(), gitalypb.ObjectType_COMMIT)
- requireEntry(t, entries[1], git.ZeroOID.String(), blobID, gitalypb.ObjectType_BLOB)
- requireEntry(t, entries[2], git.ZeroOID.String(), tagID, gitalypb.ObjectType_TAG)
- requireEntry(t, entries[3], blobID, git.ZeroOID.String(), gitalypb.ObjectType_UNKNOWN)
+ requireEntry(t, entries[0], headCommit.Id, git.ObjectHashSHA1.ZeroOID.String(), gitalypb.ObjectType_COMMIT)
+ requireEntry(t, entries[1], git.ObjectHashSHA1.ZeroOID.String(), blobID, gitalypb.ObjectType_BLOB)
+ requireEntry(t, entries[2], git.ObjectHashSHA1.ZeroOID.String(), tagID, gitalypb.ObjectType_TAG)
+ requireEntry(t, entries[3], blobID, git.ObjectHashSHA1.ZeroOID.String(), gitalypb.ObjectType_UNKNOWN)
}
func requireEntry(t *testing.T, entry *gitalypb.ApplyBfgObjectMapStreamResponse_Entry, oldOid, newOid string, objectType gitalypb.ObjectType) {
diff --git a/internal/gitaly/service/commit/commit_signatures.go b/internal/gitaly/service/commit/commit_signatures.go
index 17adf5c8a..9045e428c 100644
--- a/internal/gitaly/service/commit/commit_signatures.go
+++ b/internal/gitaly/service/commit/commit_signatures.go
@@ -138,7 +138,7 @@ func validateGetCommitSignaturesRequest(request *gitalypb.GetCommitSignaturesReq
// Do not support shorthand or invalid commit SHAs
for _, commitID := range request.CommitIds {
- if err := git.ValidateObjectID(commitID); err != nil {
+ if err := git.ObjectHashSHA1.ValidateHex(commitID); err != nil {
return err
}
}
diff --git a/internal/gitaly/service/commit/commit_signatures_test.go b/internal/gitaly/service/commit/commit_signatures_test.go
index d88573dfd..70882228b 100644
--- a/internal/gitaly/service/commit/commit_signatures_test.go
+++ b/internal/gitaly/service/commit/commit_signatures_test.go
@@ -33,7 +33,7 @@ func TestSuccessfulGetCommitSignaturesRequest(t *testing.T) {
CommitIds: []string{
"5937ac0a7beb003549fc5fd26fc247adbce4a52e", // has signature
"e63f41fe459e62e1228fcef60d7189127aeba95a", // has no signature
- git.ZeroOID.String(), // does not exist
+ git.ObjectHashSHA1.ZeroOID.String(), // does not exist
"a17a9f66543673edf0a3d1c6b93bdda3fe600f32", // has signature
"8cf8e80a5a0546e391823c250f2b26b9cf15ce88", // has signature and commit message > 4MB
"dc00eb001f41dfac08192ead79c2377c588b82ee", // has signature and commit message without newline at the end
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/conflicts/resolve_conflicts.go b/internal/gitaly/service/conflicts/resolve_conflicts.go
index f764d3593..11de0412f 100644
--- a/internal/gitaly/service/conflicts/resolve_conflicts.go
+++ b/internal/gitaly/service/conflicts/resolve_conflicts.go
@@ -168,8 +168,8 @@ func (s *server) resolveConflicts(header *gitalypb.ResolveConflictsRequestHeader
authorDate = header.Timestamp.AsTime()
}
- if git.ValidateObjectID(header.GetOurCommitOid()) != nil ||
- git.ValidateObjectID(header.GetTheirCommitOid()) != nil {
+ if git.ObjectHashSHA1.ValidateHex(header.GetOurCommitOid()) != nil ||
+ git.ObjectHashSHA1.ValidateHex(header.GetTheirCommitOid()) != nil {
return errors.New("Rugged::InvalidError: unable to parse OID - contains invalid characters")
}
@@ -192,7 +192,7 @@ func (s *server) resolveConflicts(header *gitalypb.ResolveConflictsRequestHeader
return err
}
- commitOID, err := git.NewObjectIDFromHex(result.CommitID)
+ commitOID, err := git.ObjectHashSHA1.FromHex(result.CommitID)
if err != nil {
return err
}
diff --git a/internal/gitaly/service/diff/commit_test.go b/internal/gitaly/service/diff/commit_test.go
index 4d9a50ceb..62f2ed282 100644
--- a/internal/gitaly/service/diff/commit_test.go
+++ b/internal/gitaly/service/diff/commit_test.go
@@ -36,7 +36,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
},
{
FromID: "bdea48ee65c869eb0b86b1283069d76cce0a7254",
- ToID: git.ZeroOID.String(),
+ ToID: git.ObjectHashSHA1.ZeroOID.String(),
OldMode: 0o100644,
NewMode: 0,
FromPath: []byte("gitaly/deleted-file"),
@@ -55,7 +55,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
Patch: testhelper.MustReadFile(t, "testdata/file-with-multiple-chunks-chunks.txt"),
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "389c7a36a6e133268b0d36b00e7ffc0f3a5b6651",
OldMode: 0,
NewMode: 0o100644,
@@ -65,7 +65,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
Patch: testhelper.MustReadFile(t, "testdata/file-with-pluses-chunks.txt"),
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "bc2ef601a538d69ef99d5bdafa605e63f902e8e4",
OldMode: 0,
NewMode: 0o100644,
@@ -95,7 +95,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
},
{
FromID: "43d24af4e22580f36b1ca52647c1aff75a766a33",
- ToID: git.ZeroOID.String(),
+ ToID: git.ObjectHashSHA1.ZeroOID.String(),
OldMode: 0o100644,
NewMode: 0,
FromPath: []byte("gitaly/named-file-with-mods"),
@@ -104,7 +104,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
Patch: testhelper.MustReadFile(t, "testdata/named-file-with-mods-chunks.txt"),
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "b464dff7a75ccc92fbd920fd9ae66a84b9d2bf94",
OldMode: 0,
NewMode: 0o100644,
@@ -123,7 +123,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
Binary: false,
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "3856c00e9450a51a62096327167fc43d3be62eef",
OldMode: 0,
NewMode: 0o100644,
@@ -133,7 +133,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
Patch: testhelper.MustReadFile(t, "testdata/renamed-file-with-mods-chunks.txt"),
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "a135e3e0d4af177a902ca57dcc4c7fc6f30858b1",
OldMode: 0,
NewMode: 0o100644,
@@ -143,7 +143,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
Patch: testhelper.MustReadFile(t, "testdata/tab-newline-file-chunks.txt"),
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
OldMode: 0,
NewMode: 0o100755,
@@ -152,7 +152,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
Binary: false,
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "b1e67221afe8461efd244b487afca22d46b95eb8",
OldMode: 0,
NewMode: 0o100644,
@@ -237,7 +237,7 @@ func TestSuccessfulCommitDiffRequestWithPaths(t *testing.T) {
},
{
FromID: "43d24af4e22580f36b1ca52647c1aff75a766a33",
- ToID: git.ZeroOID.String(),
+ ToID: git.ObjectHashSHA1.ZeroOID.String(),
OldMode: 0o100644,
NewMode: 0,
FromPath: []byte("gitaly/named-file-with-mods"),
@@ -267,7 +267,7 @@ func TestSuccessfulCommitDiffRequestWithTypeChangeDiff(t *testing.T) {
expectedDiffs := []diff.Diff{
{
FromID: "349cd0f6b1aba8538861d95783cbce6d49d747f8",
- ToID: git.ZeroOID.String(),
+ ToID: git.ObjectHashSHA1.ZeroOID.String(),
OldMode: 0o120000,
NewMode: 0,
FromPath: []byte("gitaly/symlink-to-be-regular"),
@@ -276,7 +276,7 @@ func TestSuccessfulCommitDiffRequestWithTypeChangeDiff(t *testing.T) {
Patch: testhelper.MustReadFile(t, "testdata/symlink-to-be-regular-deleted-chunks.txt"),
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "f9e5cc857610185e6feeb494a26bf27551a4f02b",
OldMode: 0,
NewMode: 0o100644,
@@ -349,7 +349,7 @@ func TestSuccessfulCommitDiffRequestWithIgnoreWhitespaceChange(t *testing.T) {
},
{
FromID: "43d24af4e22580f36b1ca52647c1aff75a766a33",
- ToID: git.ZeroOID.String(),
+ ToID: git.ObjectHashSHA1.ZeroOID.String(),
OldMode: 0o100644,
NewMode: 0,
FromPath: []byte("gitaly/named-file-with-mods"),
@@ -849,7 +849,7 @@ func TestSuccessfulCommitDeltaRequest(t *testing.T) {
},
{
FromID: "bdea48ee65c869eb0b86b1283069d76cce0a7254",
- ToID: git.ZeroOID.String(),
+ ToID: git.ObjectHashSHA1.ZeroOID.String(),
OldMode: 0o100644,
NewMode: 0,
FromPath: []byte("gitaly/deleted-file"),
@@ -864,7 +864,7 @@ func TestSuccessfulCommitDeltaRequest(t *testing.T) {
ToPath: []byte("gitaly/file-with-multiple-chunks"),
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "bc2ef601a538d69ef99d5bdafa605e63f902e8e4",
OldMode: 0,
NewMode: 0o100644,
@@ -889,14 +889,14 @@ func TestSuccessfulCommitDeltaRequest(t *testing.T) {
},
{
FromID: "43d24af4e22580f36b1ca52647c1aff75a766a33",
- ToID: git.ZeroOID.String(),
+ ToID: git.ObjectHashSHA1.ZeroOID.String(),
OldMode: 0o100644,
NewMode: 0,
FromPath: []byte("gitaly/named-file-with-mods"),
ToPath: []byte("gitaly/named-file-with-mods"),
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "b464dff7a75ccc92fbd920fd9ae66a84b9d2bf94",
OldMode: 0,
NewMode: 0o100644,
@@ -912,7 +912,7 @@ func TestSuccessfulCommitDeltaRequest(t *testing.T) {
ToPath: []byte("gitaly/renamed-file"),
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "3856c00e9450a51a62096327167fc43d3be62eef",
OldMode: 0,
NewMode: 0o100644,
@@ -920,7 +920,7 @@ func TestSuccessfulCommitDeltaRequest(t *testing.T) {
ToPath: []byte("gitaly/renamed-file-with-mods"),
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "a135e3e0d4af177a902ca57dcc4c7fc6f30858b1",
OldMode: 0,
NewMode: 0o100644,
@@ -928,7 +928,7 @@ func TestSuccessfulCommitDeltaRequest(t *testing.T) {
ToPath: []byte("gitaly/tab\tnewline\n file"),
},
{
- FromID: git.ZeroOID.String(),
+ FromID: git.ObjectHashSHA1.ZeroOID.String(),
ToID: "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
OldMode: 0,
NewMode: 0o100755,
@@ -987,7 +987,7 @@ func TestSuccessfulCommitDeltaRequestWithPaths(t *testing.T) {
},
{
FromID: "43d24af4e22580f36b1ca52647c1aff75a766a33",
- ToID: git.ZeroOID.String(),
+ ToID: git.ObjectHashSHA1.ZeroOID.String(),
OldMode: 0o100644,
NewMode: 0,
FromPath: []byte("gitaly/named-file-with-mods"),
diff --git a/internal/gitaly/service/operations/apply_patch.go b/internal/gitaly/service/operations/apply_patch.go
index b39704893..0a02b7430 100644
--- a/internal/gitaly/service/operations/apply_patch.go
+++ b/internal/gitaly/service/operations/apply_patch.go
@@ -169,14 +169,14 @@ func (s *Server) userApplyPatch(ctx context.Context, header *gitalypb.UserApplyP
return fmt.Errorf("get patched commit: %w", gitError{ErrMsg: revParseStderr.String(), Err: err})
}
- patchedCommit, err := git.NewObjectIDFromHex(text.ChompBytes(revParseStdout.Bytes()))
+ patchedCommit, err := git.ObjectHashSHA1.FromHex(text.ChompBytes(revParseStdout.Bytes()))
if err != nil {
return fmt.Errorf("parse patched commit oid: %w", err)
}
currentCommit := parentCommitID
if branchCreated {
- currentCommit = git.ZeroOID
+ currentCommit = git.ObjectHashSHA1.ZeroOID
}
if err := s.updateReferenceWithHooks(ctx, header.Repository, header.User, nil, targetBranch, patchedCommit, currentCommit); err != nil {
diff --git a/internal/gitaly/service/operations/apply_patch_test.go b/internal/gitaly/service/operations/apply_patch_test.go
index e3c959218..f4d34318e 100644
--- a/internal/gitaly/service/operations/apply_patch_test.go
+++ b/internal/gitaly/service/operations/apply_patch_test.go
@@ -305,7 +305,7 @@ To restore the original branch and stop patching, run "git am --abort".
}
if baseCommit != "" {
- require.NoError(t, repo.UpdateRef(ctx, tc.baseReference, baseCommit, git.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, tc.baseReference, baseCommit, git.ObjectHashSHA1.ZeroOID))
}
if tc.extraBranches != nil {
@@ -319,7 +319,7 @@ To restore the original branch and stop patching, run "git am --abort".
for _, extraBranch := range tc.extraBranches {
require.NoError(t, repo.UpdateRef(ctx,
- git.NewReferenceNameFromBranchName(extraBranch), emptyCommit, git.ZeroOID),
+ git.NewReferenceNameFromBranchName(extraBranch), emptyCommit, git.ObjectHashSHA1.ZeroOID),
)
}
}
diff --git a/internal/gitaly/service/operations/branches.go b/internal/gitaly/service/operations/branches.go
index 02a25649c..ebad7a04d 100644
--- a/internal/gitaly/service/operations/branches.go
+++ b/internal/gitaly/service/operations/branches.go
@@ -44,7 +44,7 @@ func (s *Server) UserCreateBranch(ctx context.Context, req *gitalypb.UserCreateB
return nil, status.Errorf(codes.FailedPrecondition, "revspec '%s' not found", req.StartPoint)
}
- startPointOID, err := git.NewObjectIDFromHex(startPointCommit.Id)
+ startPointOID, err := git.ObjectHashSHA1.FromHex(startPointCommit.Id)
if err != nil {
return nil, status.Errorf(codes.Internal, "could not parse start point commit ID: %v", err)
}
@@ -57,7 +57,7 @@ func (s *Server) UserCreateBranch(ctx context.Context, req *gitalypb.UserCreateB
return nil, status.Error(codes.Internal, err.Error())
}
- if err := s.updateReferenceWithHooks(ctx, req.GetRepository(), req.User, quarantineDir, referenceName, startPointOID, git.ZeroOID); err != nil {
+ if err := s.updateReferenceWithHooks(ctx, req.GetRepository(), req.User, quarantineDir, referenceName, startPointOID, git.ObjectHashSHA1.ZeroOID); err != nil {
var customHookErr updateref.CustomHookError
if errors.As(err, &customHookErr) {
return &gitalypb.UserCreateBranchResponse{
@@ -108,12 +108,12 @@ func (s *Server) UserUpdateBranch(ctx context.Context, req *gitalypb.UserUpdateB
return nil, err
}
- newOID, err := git.NewObjectIDFromHex(string(req.Newrev))
+ newOID, err := git.ObjectHashSHA1.FromHex(string(req.Newrev))
if err != nil {
return nil, status.Errorf(codes.Internal, "could not parse newrev: %v", err)
}
- oldOID, err := git.NewObjectIDFromHex(string(req.Oldrev))
+ oldOID, err := git.ObjectHashSHA1.FromHex(string(req.Oldrev))
if err != nil {
return nil, status.Errorf(codes.Internal, "could not parse oldrev: %v", err)
}
@@ -163,7 +163,7 @@ func (s *Server) UserDeleteBranch(ctx context.Context, req *gitalypb.UserDeleteB
return nil, helper.ErrFailedPreconditionf("branch not found: %q", req.BranchName)
}
- if err := s.updateReferenceWithHooks(ctx, req.Repository, req.User, nil, referenceName, git.ZeroOID, referenceValue); err != nil {
+ if err := s.updateReferenceWithHooks(ctx, req.Repository, req.User, nil, referenceName, git.ObjectHashSHA1.ZeroOID, referenceValue); err != nil {
var notAllowedError hook.NotAllowedError
var customHookErr updateref.CustomHookError
var updateRefError updateref.Error
diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go
index 3909632a0..b3948c5f1 100644
--- a/internal/gitaly/service/operations/branches_test.go
+++ b/internal/gitaly/service/operations/branches_test.go
@@ -261,7 +261,7 @@ func TestUserCreateBranch_startPoint(t *testing.T) {
t.Run(testCase.desc, func(t *testing.T) {
gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/heads/"+testCase.startPoint,
testCase.startPointCommit,
- git.ZeroOID.String(),
+ git.ObjectHashSHA1.ZeroOID.String(),
)
request := &gitalypb.UserCreateBranchRequest{
Repository: repoProto,
@@ -466,7 +466,7 @@ func TestUserDeleteBranch_allowed(t *testing.T) {
UserId: "user-123",
ErrorMessage: "something something",
Changes: []byte(fmt.Sprintf(
- "%s %s refs/heads/branch\n", "549090fbeacc6607bc70648d3ba554c355e670c5", git.ZeroOID,
+ "%s %s refs/heads/branch\n", "549090fbeacc6607bc70648d3ba554c355e670c5", git.ObjectHashSHA1.ZeroOID,
)),
},
},
@@ -487,7 +487,7 @@ func TestUserDeleteBranch_allowed(t *testing.T) {
UserId: "user-123",
ErrorMessage: "something else",
Changes: []byte(fmt.Sprintf(
- "%s %s refs/heads/branch\n", "549090fbeacc6607bc70648d3ba554c355e670c5", git.ZeroOID,
+ "%s %s refs/heads/branch\n", "549090fbeacc6607bc70648d3ba554c355e670c5", git.ObjectHashSHA1.ZeroOID,
)),
},
},
@@ -545,7 +545,7 @@ func TestUserDeleteBranch_concurrentUpdate(t *testing.T) {
Error: &gitalypb.UserDeleteBranchError_ReferenceUpdate{
ReferenceUpdate: &gitalypb.ReferenceUpdateError{
OldOid: commitID.String(),
- NewOid: git.ZeroOID.String(),
+ NewOid: git.ObjectHashSHA1.ZeroOID.String(),
ReferenceName: []byte("refs/heads/concurrent-update"),
},
},
diff --git a/internal/gitaly/service/operations/cherry_pick.go b/internal/gitaly/service/operations/cherry_pick.go
index 7b8994479..23b0566fd 100644
--- a/internal/gitaly/service/operations/cherry_pick.go
+++ b/internal/gitaly/service/operations/cherry_pick.go
@@ -133,7 +133,7 @@ func (s *Server) UserCherryPick(ctx context.Context, req *gitalypb.UserCherryPic
oldrev, err := quarantineRepo.ResolveRevision(ctx, referenceName.Revision()+"^{commit}")
if errors.Is(err, git.ErrReferenceNotFound) {
branchCreated = true
- oldrev = git.ZeroOID
+ oldrev = git.ObjectHashSHA1.ZeroOID
} else if err != nil {
return nil, helper.ErrInvalidArgumentf("resolve ref: %w", err)
}
diff --git a/internal/gitaly/service/operations/cherry_pick_test.go b/internal/gitaly/service/operations/cherry_pick_test.go
index 923fdd23a..ccc8bc6e9 100644
--- a/internal/gitaly/service/operations/cherry_pick_test.go
+++ b/internal/gitaly/service/operations/cherry_pick_test.go
@@ -646,7 +646,7 @@ func testServerUserCherryPickQuarantine(t *testing.T, ctx context.Context) {
}
hookOutput := testhelper.MustReadFile(t, outputPath)
- oid, err := git.NewObjectIDFromHex(text.ChompBytes(hookOutput))
+ oid, err := git.ObjectHashSHA1.FromHex(text.ChompBytes(hookOutput))
require.NoError(t, err)
exists, err := repo.HasRevision(ctx, oid.Revision()+"^{commit}")
require.NoError(t, err)
diff --git a/internal/gitaly/service/operations/commit_files.go b/internal/gitaly/service/operations/commit_files.go
index ba4514fc1..16df353e4 100644
--- a/internal/gitaly/service/operations/commit_files.go
+++ b/internal/gitaly/service/operations/commit_files.go
@@ -161,7 +161,7 @@ func (s *Server) userCommitFiles(ctx context.Context, header *gitalypb.UserCommi
return fmt.Errorf("resolve parent commit: %w", err)
}
} else {
- parentCommitOID, err = git.NewObjectIDFromHex(header.StartSha)
+ parentCommitOID, err = git.ObjectHashSHA1.FromHex(header.StartSha)
if err != nil {
return helper.ErrInvalidArgumentf("cannot resolve parent commit: %w", err)
}
@@ -310,7 +310,7 @@ func (s *Server) userCommitFiles(ctx context.Context, header *gitalypb.UserCommi
oldRevision := parentCommitOID
if targetBranchCommit == "" {
- oldRevision = git.ZeroOID
+ oldRevision = git.ObjectHashSHA1.ZeroOID
} else if header.Force {
oldRevision = targetBranchCommit
}
@@ -326,7 +326,7 @@ func (s *Server) userCommitFiles(ctx context.Context, header *gitalypb.UserCommi
return stream.SendAndClose(&gitalypb.UserCommitFilesResponse{BranchUpdate: &gitalypb.OperationBranchUpdate{
CommitId: commitID.String(),
RepoCreated: !hasBranches,
- BranchCreated: oldRevision.IsZeroOID(),
+ BranchCreated: git.ObjectHashSHA1.IsZeroOID(oldRevision),
}})
}
@@ -434,7 +434,7 @@ func validateUserCommitFilesHeader(header *gitalypb.UserCommitFilesRequestHeader
startSha := header.GetStartSha()
if len(startSha) > 0 {
- err := git.ValidateObjectID(startSha)
+ err := git.ObjectHashSHA1.ValidateHex(startSha)
if err != nil {
return err
}
diff --git a/internal/gitaly/service/operations/commit_files_test.go b/internal/gitaly/service/operations/commit_files_test.go
index b1643333e..24bed724c 100644
--- a/internal/gitaly/service/operations/commit_files_test.go
+++ b/internal/gitaly/service/operations/commit_files_test.go
@@ -1016,7 +1016,7 @@ func TestUserCommitFilesQuarantine(t *testing.T) {
require.NoError(t, err)
hookOutput := testhelper.MustReadFile(t, outputPath)
- oid, err := git.NewObjectIDFromHex(text.ChompBytes(hookOutput))
+ oid, err := git.ObjectHashSHA1.FromHex(text.ChompBytes(hookOutput))
require.NoError(t, err)
exists, err := repo.HasRevision(ctx, oid.Revision()+"^{commit}")
require.NoError(t, err)
diff --git a/internal/gitaly/service/operations/merge.go b/internal/gitaly/service/operations/merge.go
index cfcf137b8..8237ec034 100644
--- a/internal/gitaly/service/operations/merge.go
+++ b/internal/gitaly/service/operations/merge.go
@@ -116,7 +116,7 @@ func (s *Server) UserMergeBranch(stream gitalypb.OperationService_UserMergeBranc
return helper.ErrInternal(err)
}
- mergeOID, err := git.NewObjectIDFromHex(merge.CommitID)
+ mergeOID, err := git.ObjectHashSHA1.FromHex(merge.CommitID)
if err != nil {
return helper.ErrInternalf("could not parse merge ID: %w", err)
}
@@ -256,7 +256,7 @@ func (s *Server) UserFFBranch(ctx context.Context, in *gitalypb.UserFFBranchRequ
return nil, helper.ErrInvalidArgument(err)
}
- commitID, err := git.NewObjectIDFromHex(in.CommitId)
+ commitID, err := git.ObjectHashSHA1.FromHex(in.CommitId)
if err != nil {
return nil, helper.ErrInvalidArgumentf("cannot parse commit ID: %w", err)
}
@@ -365,14 +365,14 @@ func (s *Server) UserMergeToRef(ctx context.Context, request *gitalypb.UserMerge
return nil, helper.ErrFailedPreconditionf("target reference is symbolic: %q", request.TargetRef)
}
- oid, err := git.NewObjectIDFromHex(targetRef.Target)
+ oid, err := git.ObjectHashSHA1.FromHex(targetRef.Target)
if err != nil {
return nil, helper.ErrInternalf("invalid target revision: %v", err)
}
oldTargetOID = oid
} else if errors.Is(err, git.ErrReferenceNotFound) {
- oldTargetOID = git.ZeroOID
+ oldTargetOID = git.ObjectHashSHA1.ZeroOID
} else {
return nil, helper.ErrInternalf("could not read target reference: %v", err)
}
@@ -404,7 +404,7 @@ func (s *Server) UserMergeToRef(ctx context.Context, request *gitalypb.UserMerge
sourceOID, oid, string(request.TargetRef))
}
- mergeOID, err := git.NewObjectIDFromHex(merge.CommitID)
+ mergeOID, err := git.ObjectHashSHA1.FromHex(merge.CommitID)
if err != nil {
return nil, err
}
diff --git a/internal/gitaly/service/operations/merge_test.go b/internal/gitaly/service/operations/merge_test.go
index 33265a342..41c5038c8 100644
--- a/internal/gitaly/service/operations/merge_test.go
+++ b/internal/gitaly/service/operations/merge_test.go
@@ -170,7 +170,7 @@ func TestUserMergeBranch_quarantine(t *testing.T) {
), err)
require.Nil(t, secondResponse)
- oid, err := git.NewObjectIDFromHex(strings.TrimSpace(firstResponse.CommitId))
+ oid, err := git.ObjectHashSHA1.FromHex(strings.TrimSpace(firstResponse.CommitId))
require.NoError(t, err)
exists, err := repo.HasRevision(ctx, oid.Revision()+"^{commit}")
require.NoError(t, err)
@@ -393,7 +393,7 @@ func TestUserMergeBranch_ambiguousReference(t *testing.T) {
"refs/tags/heads/" + mergeBranchName,
"refs/tags/refs/heads/" + mergeBranchName,
} {
- require.NoError(t, repo.UpdateRef(ctx, git.ReferenceName(reference), masterOID, git.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, git.ReferenceName(reference), masterOID, git.ObjectHashSHA1.ZeroOID))
}
mergeCommitMessage := "Merged by Gitaly"
diff --git a/internal/gitaly/service/operations/rebase.go b/internal/gitaly/service/operations/rebase.go
index 1ab3458e8..4edfe2863 100644
--- a/internal/gitaly/service/operations/rebase.go
+++ b/internal/gitaly/service/operations/rebase.go
@@ -44,7 +44,7 @@ func (s *Server) UserRebaseConfirmable(stream gitalypb.OperationService_UserReba
}
branch := git.NewReferenceNameFromBranchName(string(header.Branch))
- oldrev, err := git.NewObjectIDFromHex(header.BranchSha)
+ oldrev, err := git.ObjectHashSHA1.FromHex(header.BranchSha)
if err != nil {
return helper.ErrNotFound(err)
}
diff --git a/internal/gitaly/service/operations/revert.go b/internal/gitaly/service/operations/revert.go
index f4c693de6..2d7775a33 100644
--- a/internal/gitaly/service/operations/revert.go
+++ b/internal/gitaly/service/operations/revert.go
@@ -84,7 +84,7 @@ func (s *Server) UserRevert(ctx context.Context, req *gitalypb.UserRevertRequest
oldrev, err := quarantineRepo.ResolveRevision(ctx, referenceName.Revision()+"^{commit}")
if errors.Is(err, git.ErrReferenceNotFound) {
branchCreated = true
- oldrev = git.ZeroOID
+ oldrev = git.ObjectHashSHA1.ZeroOID
} else if err != nil {
return nil, helper.ErrInvalidArgumentf("resolve ref: %w", err)
}
diff --git a/internal/gitaly/service/operations/revert_test.go b/internal/gitaly/service/operations/revert_test.go
index bb1242bc6..d829d9db9 100644
--- a/internal/gitaly/service/operations/revert_test.go
+++ b/internal/gitaly/service/operations/revert_test.go
@@ -210,7 +210,7 @@ func TestServer_UserRevert_quarantine(t *testing.T) {
require.NotEmpty(t, response.PreReceiveError)
hookOutput := testhelper.MustReadFile(t, outputPath)
- oid, err := git.NewObjectIDFromHex(text.ChompBytes(hookOutput))
+ oid, err := git.ObjectHashSHA1.FromHex(text.ChompBytes(hookOutput))
require.NoError(t, err)
exists, err := repo.HasRevision(ctx, oid.Revision()+"^{commit}")
require.NoError(t, err)
diff --git a/internal/gitaly/service/operations/submodules.go b/internal/gitaly/service/operations/submodules.go
index 462e09fad..aae4b9be5 100644
--- a/internal/gitaly/service/operations/submodules.go
+++ b/internal/gitaly/service/operations/submodules.go
@@ -138,7 +138,7 @@ func (s *Server) userUpdateSubmodule(ctx context.Context, req *gitalypb.UserUpda
return nil, fmt.Errorf("%s: submodule subcommand: %w", userUpdateSubmoduleName, err)
}
- commitID, err := git.NewObjectIDFromHex(result.CommitID)
+ commitID, err := git.ObjectHashSHA1.FromHex(result.CommitID)
if err != nil {
return nil, helper.ErrInvalidArgumentf("cannot parse commit ID: %w", err)
}
diff --git a/internal/gitaly/service/operations/submodules_test.go b/internal/gitaly/service/operations/submodules_test.go
index 009186512..442cc2964 100644
--- a/internal/gitaly/service/operations/submodules_test.go
+++ b/internal/gitaly/service/operations/submodules_test.go
@@ -32,14 +32,14 @@ func TestSuccessfulUserUpdateSubmoduleRequest(t *testing.T) {
// a branch which has a name starting with "refs/heads/".
currentOID, err := repo.ResolveRevision(ctx, "refs/heads/master")
require.NoError(t, err)
- require.NoError(t, repo.UpdateRef(ctx, "refs/heads/refs/heads/master", currentOID, git.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, "refs/heads/refs/heads/master", currentOID, git.ObjectHashSHA1.ZeroOID))
// If something uses the branch name as an unqualified reference, then
// git would return the tag instead of the branch. We thus create a tag
// with a different OID than the current master branch.
prevOID, err := repo.ResolveRevision(ctx, "refs/heads/master~")
require.NoError(t, err)
- require.NoError(t, repo.UpdateRef(ctx, "refs/tags/master", prevOID, git.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, "refs/tags/master", prevOID, git.ObjectHashSHA1.ZeroOID))
commitMessage := []byte("Update Submodule message")
@@ -179,7 +179,7 @@ func TestUserUpdateSubmoduleQuarantine(t *testing.T) {
require.NotEmpty(t, response.GetPreReceiveError())
hookOutput := testhelper.MustReadFile(t, outputPath)
- oid, err := git.NewObjectIDFromHex(text.ChompBytes(hookOutput))
+ oid, err := git.ObjectHashSHA1.FromHex(text.ChompBytes(hookOutput))
require.NoError(t, err)
exists, err := repo.HasRevision(ctx, oid.Revision()+"^{commit}")
require.NoError(t, err)
diff --git a/internal/gitaly/service/operations/tags.go b/internal/gitaly/service/operations/tags.go
index 7df74bdd8..b1f2a635c 100644
--- a/internal/gitaly/service/operations/tags.go
+++ b/internal/gitaly/service/operations/tags.go
@@ -34,7 +34,7 @@ func (s *Server) UserDeleteTag(ctx context.Context, req *gitalypb.UserDeleteTagR
return nil, status.Errorf(codes.FailedPrecondition, "tag not found: %s", req.TagName)
}
- if err := s.updateReferenceWithHooks(ctx, req.Repository, req.User, nil, referenceName, git.ZeroOID, revision); err != nil {
+ if err := s.updateReferenceWithHooks(ctx, req.Repository, req.User, nil, referenceName, git.ObjectHashSHA1.ZeroOID, revision); err != nil {
var customHookErr updateref.CustomHookError
if errors.As(err, &customHookErr) {
return &gitalypb.UserDeleteTagResponse{
@@ -110,7 +110,7 @@ func (s *Server) UserCreateTag(ctx context.Context, req *gitalypb.UserCreateTagR
}
referenceName := git.ReferenceName(fmt.Sprintf("refs/tags/%s", req.TagName))
- if err := s.updateReferenceWithHooks(ctx, req.Repository, req.User, quarantineDir, referenceName, tagID, git.ZeroOID); err != nil {
+ if err := s.updateReferenceWithHooks(ctx, req.Repository, req.User, quarantineDir, referenceName, tagID, git.ObjectHashSHA1.ZeroOID); err != nil {
var customHookErrr updateref.CustomHookError
if errors.As(err, &customHookErrr) {
return &gitalypb.UserCreateTagResponse{
diff --git a/internal/gitaly/service/operations/update_branches_test.go b/internal/gitaly/service/operations/update_branches_test.go
index 7a717ccf1..3cffdd11a 100644
--- a/internal/gitaly/service/operations/update_branches_test.go
+++ b/internal/gitaly/service/operations/update_branches_test.go
@@ -52,7 +52,7 @@ func TestSuccessfulUserUpdateBranchRequest(t *testing.T) {
{
desc: "short name branch creation",
updateBranchName: "a-new-branch",
- oldRev: []byte(git.ZeroOID.String()),
+ oldRev: []byte(git.ObjectHashSHA1.ZeroOID.String()),
newRev: []byte("845009f4d7bdc9e0d8f26b1c6fb6e108aaff9314"),
},
// We create refs/heads/heads/BRANCH and
@@ -62,13 +62,13 @@ func TestSuccessfulUserUpdateBranchRequest(t *testing.T) {
{
desc: "heads/* branch creation",
updateBranchName: "heads/a-new-branch",
- oldRev: []byte(git.ZeroOID.String()),
+ oldRev: []byte(git.ObjectHashSHA1.ZeroOID.String()),
newRev: []byte("845009f4d7bdc9e0d8f26b1c6fb6e108aaff9314"),
},
{
desc: "refs/heads/* branch creation",
updateBranchName: "refs/heads/a-new-branch",
- oldRev: []byte(git.ZeroOID.String()),
+ oldRev: []byte(git.ObjectHashSHA1.ZeroOID.String()),
newRev: []byte("845009f4d7bdc9e0d8f26b1c6fb6e108aaff9314"),
},
}
@@ -118,7 +118,7 @@ func TestSuccessfulUserUpdateBranchRequestToDelete(t *testing.T) {
desc: "short name branch deletion",
updateBranchName: "csv",
oldRev: []byte("3dd08961455abf80ef9115f4afdc1c6f968b503c"),
- newRev: []byte(git.ZeroOID.String()),
+ newRev: []byte(git.ObjectHashSHA1.ZeroOID.String()),
err: status.Error(codes.InvalidArgument, "object not found"),
},
// We test for the failed heads/* and refs/heads/* cases below in TestFailedUserUpdateBranchRequest
@@ -127,7 +127,7 @@ func TestSuccessfulUserUpdateBranchRequestToDelete(t *testing.T) {
updateBranchName: "heads/my-test-branch",
createBranch: true,
oldRev: []byte("689600b91aabec706e657e38ea706ece1ee8268f"),
- newRev: []byte(git.ZeroOID.String()),
+ newRev: []byte(git.ObjectHashSHA1.ZeroOID.String()),
err: status.Error(codes.InvalidArgument, "object not found"),
},
{
@@ -135,7 +135,7 @@ func TestSuccessfulUserUpdateBranchRequestToDelete(t *testing.T) {
updateBranchName: "refs/heads/my-other-test-branch",
createBranch: true,
oldRev: []byte("db46a1c5a5e474aa169b6cdb7a522d891bc4c5f9"),
- newRev: []byte(git.ZeroOID.String()),
+ newRev: []byte(git.ObjectHashSHA1.ZeroOID.String()),
err: status.Error(codes.InvalidArgument, "object not found"),
},
}
@@ -298,7 +298,7 @@ func TestFailedUserUpdateBranchRequest(t *testing.T) {
{
desc: "existing branch failed deletion attempt",
branchName: "csv",
- newrev: []byte(git.ZeroOID.String()),
+ newrev: []byte(git.ObjectHashSHA1.ZeroOID.String()),
oldrev: oldrev,
gotrev: []byte("3dd08961455abf80ef9115f4afdc1c6f968b503c"),
user: gittest.TestUser,
@@ -332,7 +332,7 @@ func TestFailedUserUpdateBranchRequest(t *testing.T) {
{
desc: "delete existing branch, but unsupported refs/heads/* name",
branchName: "refs/heads/crlf-diff",
- newrev: []byte(git.ZeroOID.String()),
+ newrev: []byte(git.ObjectHashSHA1.ZeroOID.String()),
oldrev: []byte("593890758a6f845c600f38ffa05be2749211caee"),
user: gittest.TestUser,
err: status.Errorf(codes.FailedPrecondition, "Could not update %v. Please refresh and try again.", "refs/heads/crlf-diff"),
@@ -341,7 +341,7 @@ func TestFailedUserUpdateBranchRequest(t *testing.T) {
desc: "short name branch deletion",
branchName: "csv",
oldrev: []byte("3dd08961455abf80ef9115f4afdc1c6f968b503c"),
- newrev: []byte(git.ZeroOID.String()),
+ newrev: []byte(git.ObjectHashSHA1.ZeroOID.String()),
expectNotFoundError: true,
user: gittest.TestUser,
err: nil,
diff --git a/internal/gitaly/service/ref/find_all_tags_test.go b/internal/gitaly/service/ref/find_all_tags_test.go
index 4396c8a99..0398cc6f1 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"),
@@ -288,10 +288,10 @@ func TestFindAllTags_duplicateAnnotatedTags(t *testing.T) {
gittest.TestUser, date)
require.NoError(t, err)
- require.NoError(t, repo.UpdateRef(ctx, "refs/tags/annotated", tagID, git.ZeroOID))
- require.NoError(t, repo.UpdateRef(ctx, "refs/tags/annotated-dup", tagID, git.ZeroOID))
- require.NoError(t, repo.UpdateRef(ctx, "refs/tags/lightweight-1", commitID, git.ZeroOID))
- require.NoError(t, repo.UpdateRef(ctx, "refs/tags/lightweight-2", commitID, git.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, "refs/tags/annotated", tagID, git.ObjectHashSHA1.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, "refs/tags/annotated-dup", tagID, git.ObjectHashSHA1.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, "refs/tags/lightweight-1", commitID, git.ObjectHashSHA1.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, "refs/tags/lightweight-2", commitID, git.ObjectHashSHA1.ZeroOID))
c, err := client.FindAllTags(ctx, &gitalypb.FindAllTagsRequest{Repository: repoProto})
require.NoError(t, err)
@@ -642,7 +642,7 @@ func TestFindAllTags_sorted(t *testing.T) {
require.NoError(t, err)
annotatedTagID, err := repo.WriteTag(ctx, git.ObjectID(headCommit.Id), "commit", []byte("annotated"), []byte("message"), gittest.TestUser, time.Now())
require.NoError(t, err)
- require.NoError(t, repo.UpdateRef(ctx, "refs/tags/annotated", annotatedTagID, git.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, "refs/tags/annotated", annotatedTagID, git.ObjectHashSHA1.ZeroOID))
require.NoError(t, repo.ExecAndWait(ctx, git.SubCmd{
Name: "tag",
diff --git a/internal/gitaly/service/ref/pack_refs_test.go b/internal/gitaly/service/ref/pack_refs_test.go
index bb8d276bd..cdaa080c0 100644
--- a/internal/gitaly/service/ref/pack_refs_test.go
+++ b/internal/gitaly/service/ref/pack_refs_test.go
@@ -34,7 +34,7 @@ func TestPackRefsSuccessfulRequest(t *testing.T) {
// creates some new heads
newBranches := 10
for i := 0; i < newBranches; i++ {
- require.NoError(t, repo.UpdateRef(ctx, git.ReferenceName(fmt.Sprintf("refs/heads/new-ref-%d", i)), "refs/heads/master", git.ZeroOID))
+ require.NoError(t, repo.UpdateRef(ctx, git.ReferenceName(fmt.Sprintf("refs/heads/new-ref-%d", i)), "refs/heads/master", git.ObjectHashSHA1.ZeroOID))
}
// pack all refs
diff --git a/internal/gitaly/service/ref/refnames_containing.go b/internal/gitaly/service/ref/refnames_containing.go
index 278316afc..420dbda83 100644
--- a/internal/gitaly/service/ref/refnames_containing.go
+++ b/internal/gitaly/service/ref/refnames_containing.go
@@ -15,7 +15,7 @@ import (
// ListBranchNamesContainingCommit returns a maximum of in.GetLimit() Branch names
// which contain the SHA1 passed as argument
func (s *server) ListBranchNamesContainingCommit(in *gitalypb.ListBranchNamesContainingCommitRequest, stream gitalypb.RefService_ListBranchNamesContainingCommitServer) error {
- if err := git.ValidateObjectID(in.GetCommitId()); err != nil {
+ if err := git.ObjectHashSHA1.ValidateHex(in.GetCommitId()); err != nil {
return helper.ErrInvalidArgument(err)
}
@@ -58,7 +58,7 @@ func (bs *branchNamesContainingCommitSender) Send() error {
// ListTagNamesContainingCommit returns a maximum of in.GetLimit() Tag names
// which contain the SHA1 passed as argument
func (s *server) ListTagNamesContainingCommit(in *gitalypb.ListTagNamesContainingCommitRequest, stream gitalypb.RefService_ListTagNamesContainingCommitServer) error {
- if err := git.ValidateObjectID(in.GetCommitId()); err != nil {
+ if err := git.ObjectHashSHA1.ValidateHex(in.GetCommitId()); err != nil {
return helper.ErrInvalidArgument(err)
}
diff --git a/internal/gitaly/service/repository/apply_gitattributes.go b/internal/gitaly/service/repository/apply_gitattributes.go
index b1690a336..460a86ba5 100644
--- a/internal/gitaly/service/repository/apply_gitattributes.go
+++ b/internal/gitaly/service/repository/apply_gitattributes.go
@@ -64,7 +64,7 @@ func (s *server) applyGitattributes(ctx context.Context, repo *localrepo.Repo, o
// We use the zero OID as placeholder to vote on removal of the
// gitattributes file.
- if err := s.vote(ctx, git.ZeroOID, voting.Prepared); err != nil {
+ if err := s.vote(ctx, git.ObjectHashSHA1.ZeroOID, voting.Prepared); err != nil {
return fmt.Errorf("preimage vote: %w", err)
}
@@ -72,7 +72,7 @@ func (s *server) applyGitattributes(ctx context.Context, repo *localrepo.Repo, o
return err
}
- if err := s.vote(ctx, git.ZeroOID, voting.Committed); err != nil {
+ if err := s.vote(ctx, git.ObjectHashSHA1.ZeroOID, voting.Committed); err != nil {
return fmt.Errorf("postimage vote: %w", err)
}
diff --git a/internal/gitaly/service/repository/calculate_checksum.go b/internal/gitaly/service/repository/calculate_checksum.go
index db6333fec..3407936ec 100644
--- a/internal/gitaly/service/repository/calculate_checksum.go
+++ b/internal/gitaly/service/repository/calculate_checksum.go
@@ -43,7 +43,7 @@ func (s *server) CalculateChecksum(ctx context.Context, in *gitalypb.CalculateCh
if err := cmd.Wait(); checksum.IsZero() || err != nil {
if s.isValidRepo(ctx, repo) {
- return &gitalypb.CalculateChecksumResponse{Checksum: git.ZeroOID.String()}, nil
+ return &gitalypb.CalculateChecksumResponse{Checksum: git.ObjectHashSHA1.ZeroOID.String()}, nil
}
return nil, status.Errorf(codes.DataLoss, "CalculateChecksum: not a git repository '%s'", repoPath)
diff --git a/internal/gitaly/service/repository/calculate_checksum_test.go b/internal/gitaly/service/repository/calculate_checksum_test.go
index fd0ee09e4..38feb5bbc 100644
--- a/internal/gitaly/service/repository/calculate_checksum_test.go
+++ b/internal/gitaly/service/repository/calculate_checksum_test.go
@@ -49,7 +49,7 @@ func TestEmptyRepositoryCalculateChecksum(t *testing.T) {
response, err := client.CalculateChecksum(testCtx, request)
require.NoError(t, err)
- require.Equal(t, git.ZeroOID.String(), response.Checksum)
+ require.Equal(t, git.ObjectHashSHA1.ZeroOID.String(), response.Checksum)
}
func TestBrokenRepositoryCalculateChecksum(t *testing.T) {
@@ -116,5 +116,5 @@ func TestInvalidRefsCalculateChecksum(t *testing.T) {
response, err := client.CalculateChecksum(ctx, request)
require.NoError(t, err)
- require.Equal(t, git.ZeroOID.String(), response.Checksum)
+ require.Equal(t, git.ObjectHashSHA1.ZeroOID.String(), response.Checksum)
}
diff --git a/internal/gitaly/service/repository/create_repository_from_bundle_test.go b/internal/gitaly/service/repository/create_repository_from_bundle_test.go
index 4a3e4a602..bde2bf12b 100644
--- a/internal/gitaly/service/repository/create_repository_from_bundle_test.go
+++ b/internal/gitaly/service/repository/create_repository_from_bundle_test.go
@@ -164,10 +164,10 @@ func TestCreateRepositoryFromBundle_transactional(t *testing.T) {
require.NoError(t, err)
refsVote := voting.VoteFromData([]byte(strings.Join([]string{
- fmt.Sprintf("%s %s refs/keep-around/2", git.ZeroOID, masterOID),
- fmt.Sprintf("%s %s refs/keep-around/1", git.ZeroOID, masterOID),
- fmt.Sprintf("%s %s refs/heads/feature", git.ZeroOID, featureOID),
- fmt.Sprintf("%s %s refs/heads/master", git.ZeroOID, masterOID),
+ fmt.Sprintf("%s %s refs/keep-around/2", git.ObjectHashSHA1.ZeroOID, masterOID),
+ fmt.Sprintf("%s %s refs/keep-around/1", git.ObjectHashSHA1.ZeroOID, masterOID),
+ fmt.Sprintf("%s %s refs/heads/feature", git.ObjectHashSHA1.ZeroOID, featureOID),
+ fmt.Sprintf("%s %s refs/heads/master", git.ObjectHashSHA1.ZeroOID, masterOID),
}, "\n") + "\n"))
// Compute the second vote hash to assert that we really hash exactly the files that we
diff --git a/internal/gitaly/service/repository/gc_test.go b/internal/gitaly/service/repository/gc_test.go
index c12754412..05184b5e5 100644
--- a/internal/gitaly/service/repository/gc_test.go
+++ b/internal/gitaly/service/repository/gc_test.go
@@ -465,7 +465,7 @@ func TestCleanupInvalidKeepAroundRefs(t *testing.T) {
{
desc: "Filled with the blank ref",
refName: "0b4bc9a49b562e85de7cc9e834518ea6828729b9",
- refContent: git.ZeroOID.String(),
+ refContent: git.ObjectHashSHA1.ZeroOID.String(),
shouldExist: true,
},
{
diff --git a/internal/gitaly/service/repository/raw_changes.go b/internal/gitaly/service/repository/raw_changes.go
index ab7956440..9a81e1637 100644
--- a/internal/gitaly/service/repository/raw_changes.go
+++ b/internal/gitaly/service/repository/raw_changes.go
@@ -38,13 +38,13 @@ func (s *server) GetRawChanges(req *gitalypb.GetRawChangesRequest, stream gitaly
}
func validateRawChangesRequest(ctx context.Context, req *gitalypb.GetRawChangesRequest, objectInfoReader catfile.ObjectInfoReader) error {
- if from := req.FromRevision; !git.ObjectID(from).IsZeroOID() {
+ if from := req.FromRevision; !git.ObjectHashSHA1.IsZeroOID(git.ObjectID(from)) {
if _, err := objectInfoReader.Info(ctx, git.Revision(from)); err != nil {
return fmt.Errorf("invalid 'from' revision: %q", from)
}
}
- if to := req.ToRevision; !git.ObjectID(to).IsZeroOID() {
+ if to := req.ToRevision; !git.ObjectHashSHA1.IsZeroOID(git.ObjectID(to)) {
if _, err := objectInfoReader.Info(ctx, git.Revision(to)); err != nil {
return fmt.Errorf("invalid 'to' revision: %q", to)
}
@@ -54,12 +54,12 @@ func validateRawChangesRequest(ctx context.Context, req *gitalypb.GetRawChangesR
}
func (s *server) getRawChanges(stream gitalypb.RepositoryService_GetRawChangesServer, repo git.RepositoryExecutor, objectInfoReader catfile.ObjectInfoReader, from, to string) error {
- if git.ObjectID(to).IsZeroOID() {
+ if git.ObjectHashSHA1.IsZeroOID(git.ObjectID(to)) {
return nil
}
- if git.ObjectID(from).IsZeroOID() {
- from = git.EmptyTreeOID.String()
+ if git.ObjectHashSHA1.IsZeroOID(git.ObjectID(from)) {
+ from = git.ObjectHashSHA1.EmptyTreeOID.String()
}
ctx := stream.Context()
diff --git a/internal/gitaly/service/repository/raw_changes_test.go b/internal/gitaly/service/repository/raw_changes_test.go
index aeb4a96c2..eaf281bbf 100644
--- a/internal/gitaly/service/repository/raw_changes_test.go
+++ b/internal/gitaly/service/repository/raw_changes_test.go
@@ -50,7 +50,7 @@ func TestGetRawChanges(t *testing.T) {
},
},
{
- oldRev: git.ZeroOID.String(),
+ oldRev: git.ObjectHashSHA1.ZeroOID.String(),
newRev: "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863",
changes: []*gitalypb.GetRawChangesResponse_RawChange{
{
diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go
index 89c0acc2d..399ef04d7 100644
--- a/internal/gitaly/service/smarthttp/receive_pack_test.go
+++ b/internal/gitaly/service/smarthttp/receive_pack_test.go
@@ -824,7 +824,7 @@ func TestPostReceivePack_referenceTransactionHook(t *testing.T) {
branchOID := text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "refs/heads/delete-me"))
uploadPackData := &bytes.Buffer{}
- gittest.WritePktlineString(t, uploadPackData, fmt.Sprintf("%s %s refs/heads/delete-me\x00 %s", branchOID, git.ZeroOID.String(), uploadPackCapabilities))
+ gittest.WritePktlineString(t, uploadPackData, fmt.Sprintf("%s %s refs/heads/delete-me\x00 %s", branchOID, git.ObjectHashSHA1.ZeroOID.String(), uploadPackCapabilities))
gittest.WritePktlineFlush(t, uploadPackData)
response := performPush(t, stream, &gitalypb.PostReceivePackRequest{
@@ -907,7 +907,7 @@ func createPushRequest(t *testing.T, cfg config.Cfg) (git.ObjectID, git.ObjectID
// We form the packet line the same way git executable does: https://github.com/git/git/blob/d1a13d3fcb252631361a961cb5e2bf10ed467cba/send-pack.c#L524-L527
var request bytes.Buffer
gittest.WritePktlinef(t, &request, "%s %s refs/heads/master\x00 %s", oldCommitID, newCommitID, uploadPackCapabilities)
- gittest.WritePktlinef(t, &request, "%s %s refs/heads/branch", git.ZeroOID, newCommitID)
+ gittest.WritePktlinef(t, &request, "%s %s refs/heads/branch", git.ObjectHashSHA1.ZeroOID, newCommitID)
gittest.WritePktlineFlush(t, &request)
// We need to get a pack file containing the objects we want to push, so we use git pack-objects
diff --git a/internal/gitaly/service/smarthttp/upload_pack_test.go b/internal/gitaly/service/smarthttp/upload_pack_test.go
index cf6590bd2..35843932f 100644
--- a/internal/gitaly/service/smarthttp/upload_pack_test.go
+++ b/internal/gitaly/service/smarthttp/upload_pack_test.go
@@ -83,7 +83,7 @@ func testServerPostUpload(t *testing.T, ctx context.Context, makeRequest request
testcfg.BuildGitalyHooks(t, cfg)
- oldCommit, err := git.NewObjectIDFromHex("1e292f8fedd741b75372e19097c76d327140c312") // refs/heads/master
+ oldCommit, err := git.ObjectHashSHA1.FromHex("1e292f8fedd741b75372e19097c76d327140c312") // refs/heads/master
require.NoError(t, err)
newCommit := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master"), gittest.WithParents(oldCommit))
@@ -454,7 +454,7 @@ func testServerPostUploadPackPartialClone(t *testing.T, ctx context.Context, mak
testcfg.BuildGitalyHooks(t, cfg)
- oldCommit, err := git.NewObjectIDFromHex("1e292f8fedd741b75372e19097c76d327140c312") // refs/heads/master
+ oldCommit, err := git.ObjectHashSHA1.FromHex("1e292f8fedd741b75372e19097c76d327140c312") // refs/heads/master
require.NoError(t, err)
newCommit := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master"), gittest.WithParents(oldCommit))
diff --git a/internal/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go
index 92e7c6146..737ec2106 100644
--- a/internal/gitaly/service/ssh/receive_pack_test.go
+++ b/internal/gitaly/service/ssh/receive_pack_test.go
@@ -432,7 +432,7 @@ func TestReceivePackTransactional(t *testing.T) {
commands: []command{
{
ref: "refs/heads/other",
- oldOID: git.ZeroOID.String(),
+ oldOID: git.ObjectHashSHA1.ZeroOID.String(),
newOID: masterOID,
},
},
@@ -447,11 +447,11 @@ func TestReceivePackTransactional(t *testing.T) {
{
ref: "refs/heads/other",
oldOID: masterOID,
- newOID: git.ZeroOID.String(),
+ newOID: git.ObjectHashSHA1.ZeroOID.String(),
},
},
expectedRefs: map[string]string{
- "refs/heads/other": git.ZeroOID.String(),
+ "refs/heads/other": git.ObjectHashSHA1.ZeroOID.String(),
},
expectedVotes: 3,
},
@@ -461,12 +461,12 @@ func TestReceivePackTransactional(t *testing.T) {
commands: []command{
{
ref: "refs/heads/a",
- oldOID: git.ZeroOID.String(),
+ oldOID: git.ObjectHashSHA1.ZeroOID.String(),
newOID: masterOID,
},
{
ref: "refs/heads/b",
- oldOID: git.ZeroOID.String(),
+ oldOID: git.ObjectHashSHA1.ZeroOID.String(),
newOID: masterOID,
},
},
@@ -482,7 +482,7 @@ func TestReceivePackTransactional(t *testing.T) {
commands: []command{
{
ref: "refs/heads/a",
- oldOID: git.ZeroOID.String(),
+ oldOID: git.ObjectHashSHA1.ZeroOID.String(),
newOID: masterParentOID,
},
},
@@ -497,13 +497,13 @@ func TestReceivePackTransactional(t *testing.T) {
commands: []command{
{
ref: "refs/heads/a",
- oldOID: git.ZeroOID.String(),
+ oldOID: git.ObjectHashSHA1.ZeroOID.String(),
newOID: masterParentOID,
},
{
ref: "refs/heads/b",
oldOID: masterOID,
- newOID: git.ZeroOID.String(),
+ newOID: git.ObjectHashSHA1.ZeroOID.String(),
},
},
expectedRefs: map[string]string{
@@ -551,7 +551,7 @@ func TestReceivePackTransactional(t *testing.T) {
for expectedRef, expectedOID := range tc.expectedRefs {
actualOID, err := repo.ResolveRevision(ctx, git.Revision(expectedRef))
- if expectedOID == git.ZeroOID.String() {
+ if expectedOID == git.ObjectHashSHA1.ZeroOID.String() {
require.Equal(t, git.ErrReferenceNotFound, err)
} else {
require.NoError(t, err)