diff options
author | Adam Majer <amajer@suse.de> | 2023-12-13 21:02:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-13 21:02:00 +0000 |
commit | cbf923e87bca0f50c2c01a60ccf544b63c365e98 (patch) | |
tree | 9e2e66c688bdc0f740e1ae333847dfb33677c730 /models/git | |
parent | 064f05204c0539d1f92895776dee7f626a628e3b (diff) | |
download | gitea-cbf923e87bca0f50c2c01a60ccf544b63c365e98.tar.gz gitea-cbf923e87bca0f50c2c01a60ccf544b63c365e98.zip |
Abstract hash function usage (#28138)
Refactor Hash interfaces and centralize hash function. This will allow
easier introduction of different hash function later on.
This forms the "no-op" part of the SHA256 enablement patch.
Diffstat (limited to 'models/git')
-rw-r--r-- | models/git/branch_test.go | 2 | ||||
-rw-r--r-- | models/git/commit_status.go | 13 |
2 files changed, 6 insertions, 9 deletions
diff --git a/models/git/branch_test.go b/models/git/branch_test.go index ce4cbd56a1..adcf9fd305 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -30,7 +30,7 @@ func TestAddDeletedBranch(t *testing.T) { assert.True(t, secondBranch.IsDeleted) commit := &git.Commit{ - ID: git.MustIDFromString(secondBranch.CommitID), + ID: repo.ObjectFormat.MustIDFromString(secondBranch.CommitID), CommitMessage: secondBranch.CommitMessage, Committer: &git.Signature{ When: secondBranch.CommitTime.AsLocalTime(), diff --git a/models/git/commit_status.go b/models/git/commit_status.go index 097ce01c14..a22fd23043 100644 --- a/models/git/commit_status.go +++ b/models/git/commit_status.go @@ -114,7 +114,8 @@ WHEN NOT MATCHED // GetNextCommitStatusIndex retried 3 times to generate a resource index func GetNextCommitStatusIndex(ctx context.Context, repoID int64, sha string) (int64, error) { - if !git.IsValidSHAPattern(sha) { + _, err := git.IDFromString(sha) + if err != nil { return 0, git.ErrInvalidSHA{SHA: sha} } @@ -425,7 +426,7 @@ func FindRepoRecentCommitStatusContexts(ctx context.Context, repoID int64, befor type NewCommitStatusOptions struct { Repo *repo_model.Repository Creator *user_model.User - SHA string + SHA git.ObjectID CommitStatus *CommitStatus } @@ -440,10 +441,6 @@ func NewCommitStatus(ctx context.Context, opts NewCommitStatusOptions) error { return fmt.Errorf("NewCommitStatus[%s, %s]: no user specified", repoPath, opts.SHA) } - if _, err := git.NewIDFromString(opts.SHA); err != nil { - return fmt.Errorf("NewCommitStatus[%s, %s]: invalid sha: %w", repoPath, opts.SHA, err) - } - ctx, committer, err := db.TxContext(ctx) if err != nil { return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", opts.Repo.ID, opts.Creator.ID, opts.SHA, err) @@ -451,7 +448,7 @@ func NewCommitStatus(ctx context.Context, opts NewCommitStatusOptions) error { defer committer.Close() // Get the next Status Index - idx, err := GetNextCommitStatusIndex(ctx, opts.Repo.ID, opts.SHA) + idx, err := GetNextCommitStatusIndex(ctx, opts.Repo.ID, opts.SHA.String()) if err != nil { return fmt.Errorf("generate commit status index failed: %w", err) } @@ -459,7 +456,7 @@ func NewCommitStatus(ctx context.Context, opts NewCommitStatusOptions) error { opts.CommitStatus.Description = strings.TrimSpace(opts.CommitStatus.Description) opts.CommitStatus.Context = strings.TrimSpace(opts.CommitStatus.Context) opts.CommitStatus.TargetURL = strings.TrimSpace(opts.CommitStatus.TargetURL) - opts.CommitStatus.SHA = opts.SHA + opts.CommitStatus.SHA = opts.SHA.String() opts.CommitStatus.CreatorID = opts.Creator.ID opts.CommitStatus.RepoID = opts.Repo.ID opts.CommitStatus.Index = idx |