Skip to content

Commit f130838

Browse files
committed
Fix lint
1 parent 6005f34 commit f130838

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

modules/git/commit_info_gogit.go

+9-18
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,19 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
3434
return nil, nil, err
3535
}
3636

37-
var revs map[string]*Commit
38-
if commit.repo.LastCommitCache != nil {
39-
var unHitPaths []string
40-
revs, unHitPaths, err = getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths, commit.repo.LastCommitCache)
37+
revs, unHitPaths, err := commit.repo.lastCommitCache.getLastCommitForPathsByCache(commit.ID.String(), treePath, entryPaths)
38+
if err != nil {
39+
return nil, nil, err
40+
}
41+
if len(unHitPaths) > 0 {
42+
revs2, err := GetLastCommitForPaths(ctx, commit.repo.lastCommitCache, c, treePath, unHitPaths)
4143
if err != nil {
4244
return nil, nil, err
4345
}
44-
if len(unHitPaths) > 0 {
45-
revs2, err := GetLastCommitForPaths(ctx, commit.repo.LastCommitCache, c, treePath, unHitPaths)
46-
if err != nil {
47-
return nil, nil, err
48-
}
4946

50-
for k, v := range revs2 {
51-
revs[k] = v
52-
}
47+
for k, v := range revs2 {
48+
revs[k] = v
5349
}
54-
} else {
55-
revs, err = GetLastCommitForPaths(ctx, nil, c, treePath, entryPaths)
56-
}
57-
if err != nil {
58-
return nil, nil, err
5950
}
6051

6152
commit.repo.gogitStorage.Close()
@@ -154,7 +145,7 @@ func getFileHashes(c cgobject.CommitNode, treePath string, paths []string) (map[
154145
}
155146

156147
// GetLastCommitForPaths returns last commit information
157-
func GetLastCommitForPaths(ctx context.Context, cache *LastCommitCache, c cgobject.CommitNode, treePath string, paths []string) (map[string]*Commit, error) {
148+
func GetLastCommitForPaths(ctx context.Context, cache *lastCommitCache, c cgobject.CommitNode, treePath string, paths []string) (map[string]*Commit, error) {
158149
refSha := c.ID().String()
159150

160151
// We do a tree traversal with nodes sorted by commit time

modules/git/last_commit_cache_gogit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
func (c *lastCommitCache) CacheCommit(ctx context.Context, commit *Commit) error {
1717
commitNodeIndex, _ := c.repo.CommitNodeIndex()
1818

19-
index, err := commitNodeIndex.Get(plumbing.Hash(c.ID.RawValue()))
19+
index, err := commitNodeIndex.Get(plumbing.Hash(commit.ID.RawValue()))
2020
if err != nil {
2121
return err
2222
}

modules/git/repo_base_gogit.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ const isGogit = true
2828
type Repository struct {
2929
Path string
3030

31-
tagCache *ObjectCache[*Tag]
31+
tagCache *ObjectCache[*Tag]
32+
commitCache map[string]*Commit
3233

3334
gogitRepo *gogit.Repository
3435
gogitStorage *filesystem.Storage
3536
gpgSettings *GPGSettings
3637

3738
Ctx context.Context
38-
LastCommitCache *LastCommitCache
39+
lastCommitCache *lastCommitCache
3940
objectFormat ObjectFormat
4041
}
4142

@@ -85,6 +86,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
8586
gogitRepo: gogitRepo,
8687
gogitStorage: storage,
8788
tagCache: newObjectCache[*Tag](),
89+
commitCache: make(map[string]*Commit),
8890
Ctx: ctx,
8991
objectFormat: ParseGogitHash(plumbing.ZeroHash).Type(),
9092
}, nil
@@ -99,8 +101,9 @@ func (repo *Repository) Close() error {
99101
gitealog.Error("Error closing storage: %v", err)
100102
}
101103
repo.gogitStorage = nil
102-
repo.LastCommitCache = nil
104+
repo.lastCommitCache = nil
103105
repo.tagCache = nil
106+
repo.commitCache = nil
104107
return nil
105108
}
106109

0 commit comments

Comments
 (0)