diff --git a/modules/git/commit_info_gogit.go b/modules/git/commit_info_gogit.go index d541b361ff..caa6509564 100644 --- a/modules/git/commit_info_gogit.go +++ b/modules/git/commit_info_gogit.go @@ -34,28 +34,19 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath return nil, nil, err } - var revs map[string]*Commit - if commit.repo.LastCommitCache != nil { - var unHitPaths []string - revs, unHitPaths, err = getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths, commit.repo.LastCommitCache) + revs, unHitPaths, err := commit.repo.lastCommitCache.getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths) + if err != nil { + return nil, nil, err + } + if len(unHitPaths) > 0 { + revs2, err := GetLastCommitForPaths(ctx, commit.repo.lastCommitCache, c, treePath, unHitPaths) if err != nil { return nil, nil, err } - if len(unHitPaths) > 0 { - revs2, err := GetLastCommitForPaths(ctx, commit.repo.LastCommitCache, c, treePath, unHitPaths) - if err != nil { - return nil, nil, err - } - for k, v := range revs2 { - revs[k] = v - } + for k, v := range revs2 { + revs[k] = v } - } else { - revs, err = GetLastCommitForPaths(ctx, nil, c, treePath, entryPaths) - } - if err != nil { - return nil, nil, err } commit.repo.gogitStorage.Close() @@ -154,7 +145,7 @@ func getFileHashes(c cgobject.CommitNode, treePath string, paths []string) (map[ } // GetLastCommitForPaths returns last commit information -func GetLastCommitForPaths(ctx context.Context, cache *LastCommitCache, c cgobject.CommitNode, treePath string, paths []string) (map[string]*Commit, error) { +func GetLastCommitForPaths(ctx context.Context, cache *lastCommitCache, c cgobject.CommitNode, treePath string, paths []string) (map[string]*Commit, error) { refSha := c.ID().String() // We do a tree traversal with nodes sorted by commit time diff --git a/modules/git/last_commit_cache_gogit.go b/modules/git/last_commit_cache_gogit.go index abe034361a..bb5e9a201f 100644 --- a/modules/git/last_commit_cache_gogit.go +++ b/modules/git/last_commit_cache_gogit.go @@ -16,7 +16,7 @@ import ( func (c *lastCommitCache) CacheCommit(ctx context.Context, commit *Commit) error { commitNodeIndex, _ := c.repo.CommitNodeIndex() - index, err := commitNodeIndex.Get(plumbing.Hash(c.ID.RawValue())) + index, err := commitNodeIndex.Get(plumbing.Hash(commit.ID.RawValue())) if err != nil { return err } diff --git a/modules/git/repo_base_gogit.go b/modules/git/repo_base_gogit.go index 293aca159c..115d176308 100644 --- a/modules/git/repo_base_gogit.go +++ b/modules/git/repo_base_gogit.go @@ -28,14 +28,15 @@ const isGogit = true type Repository struct { Path string - tagCache *ObjectCache[*Tag] + tagCache *ObjectCache[*Tag] + commitCache map[string]*Commit gogitRepo *gogit.Repository gogitStorage *filesystem.Storage gpgSettings *GPGSettings Ctx context.Context - LastCommitCache *LastCommitCache + lastCommitCache *lastCommitCache objectFormat ObjectFormat } @@ -85,6 +86,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) { gogitRepo: gogitRepo, gogitStorage: storage, tagCache: newObjectCache[*Tag](), + commitCache: make(map[string]*Commit), Ctx: ctx, objectFormat: ParseGogitHash(plumbing.ZeroHash).Type(), }, nil @@ -99,8 +101,9 @@ func (repo *Repository) Close() error { gitealog.Error("Error closing storage: %v", err) } repo.gogitStorage = nil - repo.LastCommitCache = nil + repo.lastCommitCache = nil repo.tagCache = nil + repo.commitCache = nil return nil }