diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-18 13:33:46 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-18 13:54:19 +0300 |
commit | 1ba56c88d4f68fb7a20b5bff96890e041efc7ad1 (patch) | |
tree | 077b93e3e1e6452ae86991f1dd9b1fd588e52f46 | |
parent | 77bb97e29950a2f7f12e219655dd438ded40a20e (diff) |
git: Move `ZeroOID` into `ObjectHash` structure
Move the `ZeroOID` variable into the `ObjectHash` structure to make it
dependent on the hash function used.
49 files changed, 185 insertions, 169 deletions
diff --git a/cmd/gitaly-git2go-v15/conflicts_test.go b/cmd/gitaly-git2go-v15/conflicts_test.go index 5b09130a0..4ab3e4de3 100644 --- a/cmd/gitaly-git2go-v15/conflicts_test.go +++ b/cmd/gitaly-git2go-v15/conflicts_test.go @@ -239,7 +239,7 @@ 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"), }, @@ -252,7 +252,7 @@ func TestConflicts_checkError(t *testing.T) { { 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/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/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/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/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_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/object_id.go b/internal/git/object_id.go index 85afd4aa7..fcaf7225c 100644 --- a/internal/git/object_id.go +++ b/internal/git/object_id.go @@ -7,22 +7,19 @@ import ( "regexp" ) -const ( - // ZeroOID is the special value that Git uses to signal a ref or object does not exist - ZeroOID = ObjectID("0000000000000000000000000000000000000000") -) - 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 @@ -35,6 +32,8 @@ 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 } // FromHex constructs a new ObjectID from the given hex representation of the object ID. Returns @@ -57,6 +56,11 @@ func (h ObjectHash) ValidateHex(hex string) error { 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 @@ -79,8 +83,3 @@ func (oid ObjectID) Bytes() ([]byte, error) { func (oid ObjectID) Revision() Revision { return Revision(oid.String()) } - -// IsZeroOID is a shortcut for `something == git.ZeroOID.String()` -func (oid ObjectID) IsZeroOID() bool { - return string(oid) == string(ZeroOID) -} diff --git a/internal/git/object_id_test.go b/internal/git/object_id_test.go index 22f8d9a6c..c243352ca 100644 --- a/internal/git/object_id_test.go +++ b/internal/git/object_id_test.go @@ -157,7 +157,7 @@ func TestObjectID_Bytes(t *testing.T) { }{ { desc: "zero OID", - oid: ZeroOID, + oid: ObjectHashSHA1.ZeroOID, expectedBytes: bytes.Repeat([]byte{0}, 20), }, { @@ -179,25 +179,42 @@ func TestObjectID_Bytes(t *testing.T) { } } -func TestIsZeroOID(t *testing.T) { - for _, tc := range []struct { - desc string - oid ObjectID - isZero bool +func TestObjectHash_IsZeroOID(t *testing.T) { + for _, hash := range []struct { + desc string + hash ObjectHash + validHex string }{ { - desc: "zero object ID", - oid: ZeroOID, - isZero: true, + desc: "SHA1", + hash: ObjectHashSHA1, }, { - desc: "zero object ID", - oid: ObjectHashSHA1.EmptyTreeOID, - isZero: false, + desc: "SHA256", + hash: ObjectHashSHA256, }, } { - t.Run(tc.desc, func(t *testing.T) { - require.Equal(t, tc.isZero, tc.oid.IsZeroOID()) + t.Run(hash.desc, func(t *testing.T) { + for _, tc := range []struct { + desc string + oid 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/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_test.go b/internal/git/updateref/update_with_hooks_test.go index 592f1526b..d84f3221f 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 { @@ -258,7 +258,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 { @@ -368,7 +368,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 cdaf0e9e9..827a3b843 100644 --- a/internal/git/updateref/updateref_test.go +++ b/internal/git/updateref/updateref_test.go @@ -258,7 +258,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/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_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 2a1a92c60..ea7655f4a 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_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/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 3829dbeb8..0a02b7430 100644 --- a/internal/gitaly/service/operations/apply_patch.go +++ b/internal/gitaly/service/operations/apply_patch.go @@ -176,7 +176,7 @@ func (s *Server) userApplyPatch(ctx context.Context, header *gitalypb.UserApplyP 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 41f63e233..ebad7a04d 100644 --- a/internal/gitaly/service/operations/branches.go +++ b/internal/gitaly/service/operations/branches.go @@ -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{ @@ -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 98444630c..794168b22 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 b35a078b8..c78cda969 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/commit_files.go b/internal/gitaly/service/operations/commit_files.go index f5486abf2..16df353e4 100644 --- a/internal/gitaly/service/operations/commit_files.go +++ b/internal/gitaly/service/operations/commit_files.go @@ -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), }}) } diff --git a/internal/gitaly/service/operations/merge.go b/internal/gitaly/service/operations/merge.go index 7fe726abb..8237ec034 100644 --- a/internal/gitaly/service/operations/merge.go +++ b/internal/gitaly/service/operations/merge.go @@ -372,7 +372,7 @@ func (s *Server) UserMergeToRef(ctx context.Context, request *gitalypb.UserMerge 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) } diff --git a/internal/gitaly/service/operations/merge_test.go b/internal/gitaly/service/operations/merge_test.go index 034d7aee8..57b2d4664 100644 --- a/internal/gitaly/service/operations/merge_test.go +++ b/internal/gitaly/service/operations/merge_test.go @@ -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/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/submodules_test.go b/internal/gitaly/service/operations/submodules_test.go index 9944c7801..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") 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 53726710b..0398cc6f1 100644 --- a/internal/gitaly/service/ref/find_all_tags_test.go +++ b/internal/gitaly/service/ref/find_all_tags_test.go @@ -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/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 4fb96257f..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,11 +54,11 @@ 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() { + if git.ObjectHashSHA1.IsZeroOID(git.ObjectID(from)) { from = git.ObjectHashSHA1.EmptyTreeOID.String() } 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/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) |