aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/agit/agit.go3
-rw-r--r--services/migrations/gitea_uploader.go16
-rw-r--r--services/pull/check.go5
-rw-r--r--services/pull/merge.go2
-rw-r--r--services/release/release.go2
-rw-r--r--services/repository/branch.go7
-rw-r--r--services/repository/files/commit.go6
-rw-r--r--services/repository/files/tree.go2
-rw-r--r--services/repository/lfs.go2
-rw-r--r--services/repository/push.go6
10 files changed, 24 insertions, 27 deletions
diff --git a/services/agit/agit.go b/services/agit/agit.go
index 75b561581d..2233fe8547 100644
--- a/services/agit/agit.go
+++ b/services/agit/agit.go
@@ -36,7 +36,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
topicBranch = opts.GitPushOptions["topic"]
_, forcePush = opts.GitPushOptions["force-push"]
- objectFormat, _ := gitRepo.GetObjectFormat()
+ objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
pusher, err := user_model.GetUserByID(ctx, opts.UserID)
if err != nil {
@@ -149,7 +149,6 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
log.Trace("Pull request created: %d/%d", repo.ID, prIssue.ID)
- objectFormat, _ := gitRepo.GetObjectFormat()
results = append(results, private.HookProcReceiveRefResult{
Ref: pr.GetGitRefName(),
OriginalRef: opts.RefFullNames[i],
diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go
index 2891977c7c..468be6c9df 100644
--- a/services/migrations/gitea_uploader.go
+++ b/services/migrations/gitea_uploader.go
@@ -140,8 +140,18 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
if err != nil {
return err
}
- g.gitRepo, err = gitrepo.OpenRepository(g.ctx, r)
- return err
+ g.gitRepo, err = gitrepo.OpenRepository(g.ctx, g.repo)
+ if err != nil {
+ return err
+ }
+
+ // detect object format from git repository and update to database
+ objectFormat, err := g.gitRepo.GetObjectFormat()
+ if err != nil {
+ return err
+ }
+ g.repo.ObjectFormatName = objectFormat.Name()
+ return repo_model.UpdateRepositoryCols(g.ctx, g.repo, "object_format_name")
}
// Close closes this uploader
@@ -896,7 +906,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
comment.UpdatedAt = comment.CreatedAt
}
- objectFormat, _ := g.gitRepo.GetObjectFormat()
+ objectFormat := git.ObjectFormatFromName(g.repo.ObjectFormatName)
if !objectFormat.IsValid(comment.CommitID) {
log.Warn("Invalid comment CommitID[%s] on comment[%d] in PR #%d of %s/%s replaced with %s", comment.CommitID, pr.Index, g.repoOwner, g.repoName, headCommitID)
comment.CommitID = headCommitID
diff --git a/services/pull/check.go b/services/pull/check.go
index dd6c3ed230..f4dd332b14 100644
--- a/services/pull/check.go
+++ b/services/pull/check.go
@@ -222,10 +222,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
}
defer gitRepo.Close()
- objectFormat, err := gitRepo.GetObjectFormat()
- if err != nil {
- return nil, fmt.Errorf("%-v GetObjectFormat: %w", pr.BaseRepo, err)
- }
+ objectFormat := git.ObjectFormatFromName(pr.BaseRepo.ObjectFormatName)
// Get the commit from BaseBranch where the pull request got merged
mergeCommit, _, err := git.NewCommand(ctx, "rev-list", "--ancestry-path", "--merges", "--reverse").
diff --git a/services/pull/merge.go b/services/pull/merge.go
index d4c0c821d6..e37540a96f 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -497,7 +497,7 @@ func MergedManually(ctx context.Context, pr *issues_model.PullRequest, doer *use
return models.ErrInvalidMergeStyle{ID: pr.BaseRepo.ID, Style: repo_model.MergeStyleManuallyMerged}
}
- objectFormat, _ := baseGitRepo.GetObjectFormat()
+ objectFormat := git.ObjectFormatFromName(pr.BaseRepo.ObjectFormatName)
if len(commitID) != objectFormat.FullLength() {
return fmt.Errorf("Wrong commit ID")
}
diff --git a/services/release/release.go b/services/release/release.go
index 4c522c18be..a359e5078e 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -88,7 +88,7 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel
created = true
rel.LowerTagName = strings.ToLower(rel.TagName)
- objectFormat, _ := gitRepo.GetObjectFormat()
+ objectFormat := git.ObjectFormatFromName(rel.Repo.ObjectFormatName)
commits := repository.NewPushCommits()
commits.HeadCommit = repository.CommitToPushCommit(commit)
commits.CompareURL = rel.Repo.ComposeCompareURL(objectFormat.EmptyObjectID().String(), commit.ID.String())
diff --git a/services/repository/branch.go b/services/repository/branch.go
index 38781acb58..ec41173da8 100644
--- a/services/repository/branch.go
+++ b/services/repository/branch.go
@@ -380,11 +380,6 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
return fmt.Errorf("GetBranch: %vc", err)
}
- objectFormat, err := gitRepo.GetObjectFormat()
- if err != nil {
- return err
- }
-
if rawBranch.IsDeleted {
return nil
}
@@ -406,6 +401,8 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
return err
}
+ objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
+
// Don't return error below this
if err := PushUpdate(
&repo_module.PushUpdateOptions{
diff --git a/services/repository/files/commit.go b/services/repository/files/commit.go
index 16a15e06a7..512aec7c81 100644
--- a/services/repository/files/commit.go
+++ b/services/repository/files/commit.go
@@ -30,10 +30,8 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
}
defer closer.Close()
- objectFormat, err := gitRepo.GetObjectFormat()
- if err != nil {
- return fmt.Errorf("GetObjectFormat[%s]: %w", repoPath, err)
- }
+ objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
+
commit, err := gitRepo.GetCommit(sha)
if err != nil {
gitRepo.Close()
diff --git a/services/repository/files/tree.go b/services/repository/files/tree.go
index 9d3185c3fc..e3a7f3b8b0 100644
--- a/services/repository/files/tree.go
+++ b/services/repository/files/tree.go
@@ -37,7 +37,7 @@ func GetTreeBySHA(ctx context.Context, repo *repo_model.Repository, gitRepo *git
}
apiURL := repo.APIURL()
apiURLLen := len(apiURL)
- objectFormat, _ := gitRepo.GetObjectFormat()
+ objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
hashLen := objectFormat.FullLength()
const gitBlobsPath = "/git/blobs/"
diff --git a/services/repository/lfs.go b/services/repository/lfs.go
index 4504f796bd..4d48881b87 100644
--- a/services/repository/lfs.go
+++ b/services/repository/lfs.go
@@ -79,7 +79,7 @@ func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.R
store := lfs.NewContentStore()
errStop := errors.New("STOPERR")
- objectFormat, _ := gitRepo.GetObjectFormat()
+ objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
err = git_model.IterateLFSMetaObjectsForRepo(ctx, repo.ID, func(ctx context.Context, metaObject *git_model.LFSMetaObject, count int64) error {
if opts.NumberToCheckPerRepo > 0 && total > opts.NumberToCheckPerRepo {
diff --git a/services/repository/push.go b/services/repository/push.go
index c76025b6a7..9aaf0e1c9b 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -93,11 +93,6 @@ 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", repo.FullName(), err)
- }
-
if err = repo_module.UpdateRepoSize(ctx, repo); err != nil {
return fmt.Errorf("Failed to update size for repository: %v", err)
}
@@ -105,6 +100,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
addTags := make([]string, 0, len(optsList))
delTags := make([]string, 0, len(optsList))
var pusher *user_model.User
+ objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
for _, opts := range optsList {
log.Trace("pushUpdates: %-v %s %s %s", repo, opts.OldCommitID, opts.NewCommitID, opts.RefFullName)