mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 20:36:03 +02:00
Remove sync mutex
I'm pretty convinced we don't need it. Git itself does a good job of making sure that concurrent operations don't corrupt anything.
This commit is contained in:
parent
67d6447e12
commit
be3b4bd791
8 changed files with 8 additions and 26 deletions
|
@ -7,7 +7,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/sasha-s/go-deadlock"
|
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
|
|
||||||
gogit "github.com/jesseduffield/go-git/v5"
|
gogit "github.com/jesseduffield/go-git/v5"
|
||||||
|
@ -63,7 +62,6 @@ func NewGitCommand(
|
||||||
version *git_commands.GitVersion,
|
version *git_commands.GitVersion,
|
||||||
osCommand *oscommands.OSCommand,
|
osCommand *oscommands.OSCommand,
|
||||||
gitConfig git_config.IGitConfig,
|
gitConfig git_config.IGitConfig,
|
||||||
syncMutex *deadlock.Mutex,
|
|
||||||
) (*GitCommand, error) {
|
) (*GitCommand, error) {
|
||||||
currentPath, err := os.Getwd()
|
currentPath, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -118,7 +116,6 @@ func NewGitCommand(
|
||||||
gitConfig,
|
gitConfig,
|
||||||
repoPaths,
|
repoPaths,
|
||||||
repository,
|
repository,
|
||||||
syncMutex,
|
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +126,6 @@ func NewGitCommandAux(
|
||||||
gitConfig git_config.IGitConfig,
|
gitConfig git_config.IGitConfig,
|
||||||
repoPaths *git_commands.RepoPaths,
|
repoPaths *git_commands.RepoPaths,
|
||||||
repo *gogit.Repository,
|
repo *gogit.Repository,
|
||||||
syncMutex *deadlock.Mutex,
|
|
||||||
) *GitCommand {
|
) *GitCommand {
|
||||||
cmd := NewGitCmdObjBuilder(cmn.Log, osCommand.Cmd)
|
cmd := NewGitCmdObjBuilder(cmn.Log, osCommand.Cmd)
|
||||||
|
|
||||||
|
@ -140,7 +136,7 @@ func NewGitCommandAux(
|
||||||
// common ones are: cmn, osCommand, dotGitDir, configCommands
|
// common ones are: cmn, osCommand, dotGitDir, configCommands
|
||||||
configCommands := git_commands.NewConfigCommands(cmn, gitConfig, repo)
|
configCommands := git_commands.NewConfigCommands(cmn, gitConfig, repo)
|
||||||
|
|
||||||
gitCommon := git_commands.NewGitCommon(cmn, version, cmd, osCommand, repoPaths, repo, configCommands, syncMutex)
|
gitCommon := git_commands.NewGitCommon(cmn, version, cmd, osCommand, repoPaths, repo, configCommands)
|
||||||
|
|
||||||
fileLoader := git_commands.NewFileLoader(gitCommon, cmd, configCommands)
|
fileLoader := git_commands.NewFileLoader(gitCommon, cmd, configCommands)
|
||||||
statusCommands := git_commands.NewStatusCommands(gitCommon)
|
statusCommands := git_commands.NewStatusCommands(gitCommon)
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
gogit "github.com/jesseduffield/go-git/v5"
|
gogit "github.com/jesseduffield/go-git/v5"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/common"
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
"github.com/sasha-s/go-deadlock"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GitCommon struct {
|
type GitCommon struct {
|
||||||
|
@ -15,8 +14,6 @@ type GitCommon struct {
|
||||||
repoPaths *RepoPaths
|
repoPaths *RepoPaths
|
||||||
repo *gogit.Repository
|
repo *gogit.Repository
|
||||||
config *ConfigCommands
|
config *ConfigCommands
|
||||||
// mutex for doing things like push/pull/fetch
|
|
||||||
syncMutex *deadlock.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGitCommon(
|
func NewGitCommon(
|
||||||
|
@ -27,7 +24,6 @@ func NewGitCommon(
|
||||||
repoPaths *RepoPaths,
|
repoPaths *RepoPaths,
|
||||||
repo *gogit.Repository,
|
repo *gogit.Repository,
|
||||||
config *ConfigCommands,
|
config *ConfigCommands,
|
||||||
syncMutex *deadlock.Mutex,
|
|
||||||
) *GitCommon {
|
) *GitCommon {
|
||||||
return &GitCommon{
|
return &GitCommon{
|
||||||
Common: cmn,
|
Common: cmn,
|
||||||
|
@ -37,6 +33,5 @@ func NewGitCommon(
|
||||||
repoPaths: repoPaths,
|
repoPaths: repoPaths,
|
||||||
repo: repo,
|
repo: repo,
|
||||||
config: config,
|
config: config,
|
||||||
syncMutex: syncMutex,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ func (self *RemoteCommands) DeleteRemoteBranch(task gocui.Task, remoteName strin
|
||||||
Arg(remoteName, "--delete", branchName).
|
Arg(remoteName, "--delete", branchName).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).WithMutex(self.syncMutex).Run()
|
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RemoteCommands) DeleteRemoteTag(task gocui.Task, remoteName string, tagName string) error {
|
func (self *RemoteCommands) DeleteRemoteTag(task gocui.Task, remoteName string, tagName string) error {
|
||||||
|
@ -61,7 +61,7 @@ func (self *RemoteCommands) DeleteRemoteTag(task gocui.Task, remoteName string,
|
||||||
Arg(remoteName, "--delete", tagName).
|
Arg(remoteName, "--delete", tagName).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).WithMutex(self.syncMutex).Run()
|
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckRemoteBranchExists Returns remote branch
|
// CheckRemoteBranchExists Returns remote branch
|
||||||
|
|
|
@ -36,7 +36,7 @@ func (self *SyncCommands) PushCmdObj(task gocui.Task, opts PushOpts) (oscommands
|
||||||
ArgIf(opts.UpstreamBranch != "", opts.UpstreamBranch).
|
ArgIf(opts.UpstreamBranch != "", opts.UpstreamBranch).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
cmdObj := self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).WithMutex(self.syncMutex)
|
cmdObj := self.cmd.New(cmdArgs).PromptOnCredentialRequest(task)
|
||||||
return cmdObj, nil
|
return cmdObj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,6 @@ func (self *SyncCommands) FetchBackgroundCmdObj() oscommands.ICmdObj {
|
||||||
|
|
||||||
cmdObj := self.cmd.New(cmdArgs)
|
cmdObj := self.cmd.New(cmdArgs)
|
||||||
cmdObj.DontLog().FailOnCredentialRequest()
|
cmdObj.DontLog().FailOnCredentialRequest()
|
||||||
cmdObj.WithMutex(self.syncMutex)
|
|
||||||
return cmdObj
|
return cmdObj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +95,7 @@ func (self *SyncCommands) Pull(task gocui.Task, opts PullOptions) error {
|
||||||
|
|
||||||
// setting GIT_SEQUENCE_EDITOR to ':' as a way of skipping it, in case the user
|
// setting GIT_SEQUENCE_EDITOR to ':' as a way of skipping it, in case the user
|
||||||
// has 'pull.rebase = interactive' configured.
|
// has 'pull.rebase = interactive' configured.
|
||||||
return self.cmd.New(cmdArgs).AddEnvVars("GIT_SEQUENCE_EDITOR=:").PromptOnCredentialRequest(task).WithMutex(self.syncMutex).Run()
|
return self.cmd.New(cmdArgs).AddEnvVars("GIT_SEQUENCE_EDITOR=:").PromptOnCredentialRequest(task).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SyncCommands) FastForward(
|
func (self *SyncCommands) FastForward(
|
||||||
|
@ -110,7 +109,7 @@ func (self *SyncCommands) FastForward(
|
||||||
Arg(remoteBranchName + ":" + branchName).
|
Arg(remoteBranchName + ":" + branchName).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).WithMutex(self.syncMutex).Run()
|
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SyncCommands) FetchRemote(task gocui.Task, remoteName string) error {
|
func (self *SyncCommands) FetchRemote(task gocui.Task, remoteName string) error {
|
||||||
|
@ -118,5 +117,5 @@ func (self *SyncCommands) FetchRemote(task gocui.Task, remoteName string) error
|
||||||
Arg(remoteName).
|
Arg(remoteName).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).WithMutex(self.syncMutex).Run()
|
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,5 +52,5 @@ func (self *TagCommands) Push(task gocui.Task, remoteName string, tagName string
|
||||||
cmdArgs := NewGitCmd("push").Arg(remoteName, "tag", tagName).
|
cmdArgs := NewGitCmd("push").Arg(remoteName, "tag", tagName).
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).WithMutex(self.syncMutex).Run()
|
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,11 +173,6 @@ func (self *ReposHelper) DispatchSwitchTo(path string, errMsg string, contextKey
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// these two mutexes are used by our background goroutines (triggered via `self.goEvery`. We don't want to
|
|
||||||
// switch to a repo while one of these goroutines is in the process of updating something
|
|
||||||
self.c.Mutexes().SyncMutex.Lock()
|
|
||||||
defer self.c.Mutexes().SyncMutex.Unlock()
|
|
||||||
|
|
||||||
self.c.Mutexes().RefreshingFilesMutex.Lock()
|
self.c.Mutexes().RefreshingFilesMutex.Lock()
|
||||||
defer self.c.Mutexes().RefreshingFilesMutex.Unlock()
|
defer self.c.Mutexes().RefreshingFilesMutex.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -300,7 +300,6 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
|
||||||
gui.gitVersion,
|
gui.gitVersion,
|
||||||
gui.os,
|
gui.os,
|
||||||
git_config.NewStdCachedGitConfig(gui.Log),
|
git_config.NewStdCachedGitConfig(gui.Log),
|
||||||
gui.Mutexes.SyncMutex,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -490,7 +489,6 @@ func NewGui(
|
||||||
RefreshingFilesMutex: &deadlock.Mutex{},
|
RefreshingFilesMutex: &deadlock.Mutex{},
|
||||||
RefreshingBranchesMutex: &deadlock.Mutex{},
|
RefreshingBranchesMutex: &deadlock.Mutex{},
|
||||||
RefreshingStatusMutex: &deadlock.Mutex{},
|
RefreshingStatusMutex: &deadlock.Mutex{},
|
||||||
SyncMutex: &deadlock.Mutex{},
|
|
||||||
LocalCommitsMutex: &deadlock.Mutex{},
|
LocalCommitsMutex: &deadlock.Mutex{},
|
||||||
SubCommitsMutex: &deadlock.Mutex{},
|
SubCommitsMutex: &deadlock.Mutex{},
|
||||||
AuthorsMutex: &deadlock.Mutex{},
|
AuthorsMutex: &deadlock.Mutex{},
|
||||||
|
|
|
@ -262,7 +262,6 @@ type Mutexes struct {
|
||||||
RefreshingFilesMutex *deadlock.Mutex
|
RefreshingFilesMutex *deadlock.Mutex
|
||||||
RefreshingBranchesMutex *deadlock.Mutex
|
RefreshingBranchesMutex *deadlock.Mutex
|
||||||
RefreshingStatusMutex *deadlock.Mutex
|
RefreshingStatusMutex *deadlock.Mutex
|
||||||
SyncMutex *deadlock.Mutex
|
|
||||||
LocalCommitsMutex *deadlock.Mutex
|
LocalCommitsMutex *deadlock.Mutex
|
||||||
SubCommitsMutex *deadlock.Mutex
|
SubCommitsMutex *deadlock.Mutex
|
||||||
AuthorsMutex *deadlock.Mutex
|
AuthorsMutex *deadlock.Mutex
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue