Skip to content

Commit 3c6fc25

Browse files
authored
Use repo object format name instead of detecting from git repository (#29702)
It's unnecessary to detect the repository object format from git repository. Just use the repository's object format name.
1 parent 851bd18 commit 3c6fc25

File tree

6 files changed

+9
-29
lines changed

6 files changed

+9
-29
lines changed

modules/indexer/code/git.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,9 @@ func genesisChanges(ctx context.Context, repo *repo_model.Repository, revision s
9191
return nil, runErr
9292
}
9393

94+
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
95+
9496
var err error
95-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, repo.RepoPath())
96-
if err != nil {
97-
return nil, err
98-
}
9997
changes.Updates, err = parseGitLsTreeOutput(objectFormat, stdout)
10098
return &changes, err
10199
}
@@ -174,10 +172,8 @@ func nonGenesisChanges(ctx context.Context, repo *repo_model.Repository, revisio
174172
return nil, err
175173
}
176174

177-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, repo.RepoPath())
178-
if err != nil {
179-
return nil, err
180-
}
175+
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
176+
181177
changes.Updates, err = parseGitLsTreeOutput(objectFormat, lsTreeStdout)
182178
return &changes, err
183179
}

routers/web/repo/branch.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,7 @@ func RestoreBranchPost(ctx *context.Context) {
148148
return
149149
}
150150

151-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, ctx.Repo.Repository.RepoPath())
152-
if err != nil {
153-
log.Error("RestoreBranch: CreateBranch: %w", err)
154-
ctx.Flash.Error(ctx.Tr("repo.branch.restore_failed", deletedBranch.Name))
155-
return
156-
}
151+
objectFormat := git.ObjectFormatFromName(ctx.Repo.Repository.ObjectFormatName)
157152

158153
// Don't return error below this
159154
if err := repo_service.PushUpdate(

routers/web/repo/setting/webhook.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,7 @@ func TestWebhook(ctx *context.Context) {
656656
commit := ctx.Repo.Commit
657657
if commit == nil {
658658
ghost := user_model.NewGhostUser()
659-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, ctx.Repo.Repository.RepoPath())
660-
if err != nil {
661-
ctx.Flash.Error("GetObjectFormatOfRepo: " + err.Error())
662-
ctx.Status(http.StatusInternalServerError)
663-
return
664-
}
659+
objectFormat := git.ObjectFormatFromName(ctx.Repo.Repository.ObjectFormatName)
665660
commit = &git.Commit{
666661
ID: objectFormat.EmptyObjectID(),
667662
Author: ghost.NewGitSig(),

services/mirror/mirror_pull.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
479479
log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.refName, err)
480480
continue
481481
}
482-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, m.Repo.RepoPath())
483-
if err != nil {
484-
log.Error("SyncMirrors [repo: %-v]: unable to GetHashTypeOfRepo: %v", m.Repo, err)
485-
}
482+
objectFormat := git.ObjectFormatFromName(m.Repo.ObjectFormatName)
486483
notify_service.SyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{
487484
RefFullName: result.refName,
488485
OldCommitID: objectFormat.EmptyObjectID().String(),

services/pull/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
337337
}
338338
if err == nil {
339339
for _, pr := range prs {
340-
objectFormat, _ := git.GetObjectFormatOfRepo(ctx, pr.BaseRepo.RepoPath())
340+
objectFormat := git.ObjectFormatFromName(pr.BaseRepo.ObjectFormatName)
341341
if newCommitID != "" && newCommitID != objectFormat.EmptyObjectID().String() {
342342
changed, err := checkIfPRContentChanged(ctx, pr, oldCommitID, newCommitID)
343343
if err != nil {

services/release/release.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,7 @@ func DeleteReleaseByID(ctx context.Context, repo *repo_model.Repository, rel *re
326326
}
327327

328328
refName := git.RefNameFromTag(rel.TagName)
329-
objectFormat, err := git.GetObjectFormatOfRepo(ctx, repo.RepoPath())
330-
if err != nil {
331-
return err
332-
}
329+
objectFormat := git.ObjectFormatFromName(repo.ObjectFormatName)
333330
notify_service.PushCommits(
334331
ctx, doer, repo,
335332
&repository.PushUpdateOptions{

0 commit comments

Comments
 (0)