-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change RepoPaths to be acquired via RepoPathCache
In order to optimize the number of git calls made, particularly at startup time, this change implements a RepoPathCache as the API by which RepoPaths instances are acquired.
- Loading branch information
Showing
28 changed files
with
2,088 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package git_commands | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" | ||
"github.com/kofalt/go-memoize" | ||
"github.com/patrickmn/go-cache" | ||
) | ||
|
||
type RepoPathCache struct { | ||
cmd oscommands.ICmdObjBuilder | ||
gitVersion *GitVersion | ||
cache memoize.Memoizer | ||
} | ||
|
||
func NewRepoPathCache(cmd oscommands.ICmdObjBuilder, gitVersion *GitVersion) RepoPathCache { | ||
return RepoPathCache{ | ||
cmd: cmd, | ||
gitVersion: gitVersion, | ||
cache: *memoize.NewMemoizer(cache.NoExpiration, cache.NoExpiration), | ||
} | ||
} | ||
|
||
func (self *RepoPathCache) GetRepoPathsForDir(dir string) (*RepoPaths, error) { | ||
getter := func() (interface{}, error) { | ||
return getRepoPaths(dir, self.cmd, self.gitVersion) | ||
} | ||
|
||
repoPaths, err, _ := self.cache.Memoize(dir, getter) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return repoPaths.(*RepoPaths), nil | ||
} | ||
|
||
func (self *RepoPathCache) GetRepoPaths() (*RepoPaths, error) { | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return self.GetRepoPathsForDir(cwd) | ||
} | ||
|
||
func (self *RepoPathCache) GetGitVersion() *GitVersion { | ||
return self.gitVersion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.