From 0a53eb838d547d3b63ff39be95ca7ca9c9ef2f93 Mon Sep 17 00:00:00 2001 From: oliverpool Date: Mon, 18 Mar 2024 12:26:38 +0100 Subject: [PATCH] use gitRepo.GetCommit directly and give it a commitID instead of a branchName (a bit more correct and faster) --- routers/private/hook_post_receive.go | 4 +--- services/repository/branch.go | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index c34c0013d..ebe542483 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -142,9 +142,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { commitIDs = append(commitIDs, update.NewCommitID) } - if err := repo_service.SyncBranchesToDB(ctx, repo.ID, opts.UserID, branchNames, commitIDs, func(commitID string) (*git.Commit, error) { - return gitRepo.GetCommit(commitID) - }); err != nil { + if err := repo_service.SyncBranchesToDB(ctx, repo.ID, opts.UserID, branchNames, commitIDs, gitRepo.GetCommit); err != nil { ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{ Err: fmt.Sprintf("Failed to sync branch to DB in repository: %s/%s Error: %v", ownerName, repoName, err), }) diff --git a/services/repository/branch.go b/services/repository/branch.go index 9a0ff443a..39506152f 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -283,7 +283,7 @@ func SyncBranchesToDB(ctx context.Context, repoID, pusherID int64, branchNames, continue } - commit, err := getCommit(branchName) + commit, err := getCommit(commitID) if err != nil { return fmt.Errorf("get commit of %s failed: %v", branchName, err) }