@@ -15,14 +15,17 @@ import (
1515 "strconv"
1616 "strings"
1717 "time"
18+
19+ "github.com/golang/groupcache/lru"
1820)
1921
2022// Repository contains information of a Git repository.
2123type Repository struct {
2224 path string
2325
24- cachedCommits * objectCache
25- cachedTags * objectCache
26+ cachedCommits * lru.Cache
27+ cachedTags * lru.Cache
28+ cachedTrees * lru.Cache
2629}
2730
2831// Path returns the path of the repository.
@@ -84,9 +87,18 @@ func Init(path string, opts ...InitOptions) error {
8487 return err
8588}
8689
90+ // OpenOptions contains optional arguments for opening a repository.
91+ type OpenOptions struct {
92+ MaxCacheEntries int
93+ }
94+
8795// Open opens the repository at the given path. It returns an os.ErrNotExist if
8896// the path does not exist.
89- func Open (repoPath string ) (* Repository , error ) {
97+ func Open (repoPath string , opts ... OpenOptions ) (* Repository , error ) {
98+ var opt OpenOptions
99+ if len (opts ) > 0 {
100+ opt = opts [0 ]
101+ }
90102 repoPath , err := filepath .Abs (repoPath )
91103 if err != nil {
92104 return nil , err
@@ -96,8 +108,9 @@ func Open(repoPath string) (*Repository, error) {
96108
97109 return & Repository {
98110 path : repoPath ,
99- cachedCommits : newObjectCache (),
100- cachedTags : newObjectCache (),
111+ cachedCommits : lru .New (opt .MaxCacheEntries ),
112+ cachedTags : lru .New (opt .MaxCacheEntries ),
113+ cachedTrees : lru .New (opt .MaxCacheEntries ),
101114 }, nil
102115}
103116
0 commit comments