Skip to content

Commit 27cb5c4

Browse files
committed
refactor to use RepositoryFromContextOrOpen
1 parent dd9a956 commit 27cb5c4

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

routers/web/repo/pull.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,17 +395,12 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
395395
var headBranchSha string
396396
// HeadRepo may be missing
397397
if pull.HeadRepo != nil {
398-
var headGitRepo *git.Repository
399-
if ctx.Repo != nil && ctx.Repo.Repository != nil && pull.HeadRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil {
400-
headGitRepo = ctx.Repo.GitRepo
401-
} else {
402-
headGitRepo, err = gitrepo.OpenRepository(ctx, pull.HeadRepo)
403-
if err != nil {
404-
ctx.ServerError("OpenRepository", err)
405-
return nil
406-
}
407-
defer headGitRepo.Close()
398+
headGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pull.HeadRepo)
399+
if err != nil {
400+
ctx.ServerError("RepositoryFromContextOrOpen", err)
401+
return nil
408402
}
403+
defer closer.Close()
409404

410405
if pull.Flow == issues_model.PullRequestFlowGithub {
411406
headBranchExist = headGitRepo.IsBranchExist(pull.HeadBranch)

0 commit comments

Comments
 (0)