pull/34311/head
Lunny Xiao 2025-04-29 09:42:24 -07:00
parent 0cfc7f4e4f
commit 35497493c8
3 changed files with 16 additions and 22 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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
}