mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-02 13:19:42 +00:00
fix: avoid markup render panic (#38698)
fix #38697 The root problem is that "commitChecker.repo" can be nil when the render is called without a real repo.
This commit is contained in:
@@ -13,35 +13,38 @@ import (
|
||||
)
|
||||
|
||||
type commitChecker struct {
|
||||
ctx context.Context
|
||||
commitCache map[string]bool
|
||||
repo *repo_model.Repository
|
||||
ctx context.Context
|
||||
commitCache map[string]bool
|
||||
repoOptional *repo_model.Repository
|
||||
|
||||
gitRepo *git.Repository
|
||||
gitRepoCloser io.Closer
|
||||
}
|
||||
|
||||
func newCommitChecker(ctx context.Context, repo *repo_model.Repository) *commitChecker {
|
||||
return &commitChecker{ctx: ctx, commitCache: make(map[string]bool), repo: repo}
|
||||
return &commitChecker{ctx: ctx, commitCache: make(map[string]bool), repoOptional: repo}
|
||||
}
|
||||
|
||||
func (c *commitChecker) Close() error {
|
||||
if c != nil && c.gitRepoCloser != nil {
|
||||
if c.gitRepoCloser != nil {
|
||||
return c.gitRepoCloser.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *commitChecker) IsCommitIDExisting(commitID string) bool {
|
||||
if c.repoOptional == nil {
|
||||
return false
|
||||
}
|
||||
exist, inCache := c.commitCache[commitID]
|
||||
if inCache {
|
||||
return exist
|
||||
}
|
||||
|
||||
if c.gitRepo == nil {
|
||||
r, closer, err := git.RepositoryFromContextOrOpen(c.ctx, c.repo)
|
||||
r, closer, err := git.RepositoryFromContextOrOpen(c.ctx, c.repoOptional)
|
||||
if err != nil {
|
||||
log.Error("Unable to open repository: %s, error: %v", c.repo.FullName(), err)
|
||||
log.Error("Unable to open repository: %s, error: %v", c.repoOptional.FullName(), err)
|
||||
return false
|
||||
}
|
||||
c.gitRepo, c.gitRepoCloser = r, closer
|
||||
|
||||
Reference in New Issue
Block a user