summaryrefslogtreecommitdiffstats
path: root/services/repository/push.go
diff options
context:
space:
mode:
authorAdam Majer <amajer@suse.de>2023-12-13 21:02:00 +0000
committerGitHub <noreply@github.com>2023-12-13 21:02:00 +0000
commitcbf923e87bca0f50c2c01a60ccf544b63c365e98 (patch)
tree9e2e66c688bdc0f740e1ae333847dfb33677c730 /services/repository/push.go
parent064f05204c0539d1f92895776dee7f626a628e3b (diff)
downloadgitea-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 'services/repository/push.go')
-rw-r--r--services/repository/push.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/services/repository/push.go b/services/repository/push.go
index b5388834c0..3003933c34 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -65,7 +65,7 @@ func PushUpdates(opts []*repo_module.PushUpdateOptions) error {
for _, opt := range opts {
if opt.IsNewRef() && opt.IsDelRef() {
- return fmt.Errorf("Old and new revisions are both %s", git.EmptySHA)
+ return fmt.Errorf("Old and new revisions are both NULL")
}
}
@@ -94,6 +94,11 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
}
defer gitRepo.Close()
+ objectFormat, err := gitRepo.GetObjectFormat()
+ if err != nil {
+ return fmt.Errorf("unknown repository ObjectFormat [%s]: %w", repoPath, err)
+ }
+
if err = repo_module.UpdateRepoSize(ctx, repo); err != nil {
return fmt.Errorf("Failed to update size for repository: %v", err)
}
@@ -106,7 +111,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
log.Trace("pushUpdates: %-v %s %s %s", repo, opts.OldCommitID, opts.NewCommitID, opts.RefFullName)
if opts.IsNewRef() && opts.IsDelRef() {
- return fmt.Errorf("old and new revisions are both %s", git.EmptySHA)
+ return fmt.Errorf("old and new revisions are both %s", objectFormat.Empty())
}
if opts.RefFullName.IsTag() {
if pusher == nil || pusher.ID != opts.PusherID {
@@ -126,7 +131,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
&repo_module.PushUpdateOptions{
RefFullName: git.RefNameFromTag(tagName),
OldCommitID: opts.OldCommitID,
- NewCommitID: git.EmptySHA,
+ NewCommitID: objectFormat.Empty().String(),
}, repo_module.NewPushCommits())
delTags = append(delTags, tagName)
@@ -139,13 +144,13 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
commits := repo_module.NewPushCommits()
commits.HeadCommit = repo_module.CommitToPushCommit(newCommit)
- commits.CompareURL = repo.ComposeCompareURL(git.EmptySHA, opts.NewCommitID)
+ commits.CompareURL = repo.ComposeCompareURL(objectFormat.Empty().String(), opts.NewCommitID)
notify_service.PushCommits(
ctx, pusher, repo,
&repo_module.PushUpdateOptions{
RefFullName: opts.RefFullName,
- OldCommitID: git.EmptySHA,
+ OldCommitID: objectFormat.Empty().String(),
NewCommitID: opts.NewCommitID,
}, commits)
@@ -229,7 +234,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
}
oldCommitID := opts.OldCommitID
- if oldCommitID == git.EmptySHA && len(commits.Commits) > 0 {
+ if oldCommitID == objectFormat.Empty().String() && len(commits.Commits) > 0 {
oldCommit, err := gitRepo.GetCommit(commits.Commits[len(commits.Commits)-1].Sha1)
if err != nil && !git.IsErrNotExist(err) {
log.Error("unable to GetCommit %s from %-v: %v", oldCommitID, repo, err)
@@ -245,11 +250,11 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
}
}
- if oldCommitID == git.EmptySHA && repo.DefaultBranch != branch {
+ if oldCommitID == objectFormat.Empty().String() && repo.DefaultBranch != branch {
oldCommitID = repo.DefaultBranch
}
- if oldCommitID != git.EmptySHA {
+ if oldCommitID != objectFormat.Empty().String() {
commits.CompareURL = repo.ComposeCompareURL(oldCommitID, opts.NewCommitID)
} else {
commits.CompareURL = ""