From ee106f9af8354867c7ce310a52c726e24891f596 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 13 Jan 2024 00:28:04 +1100 Subject: [PATCH] Do not perform IO work when getting disabled reason with local commits Because we obtain disabled reasons after every action, we need to keep the code for doing so super fast. As such, we should not be hitting the filesystem to get rebase state, instead we should just get the cached state. I feel like we should actually be using the cached state everywhere like we do with all our other models if only for the sake of consistency. --- pkg/gui/controllers/local_commits_controller.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index f3637397b..d3b92bc93 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -534,7 +534,7 @@ func (self *LocalCommitsController) rebaseCommandEnabled(action todo.TodoCommand } if !commit.IsTODO() { - if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE { + if self.c.Model().WorkingTreeStateAtLastCommitRefresh != enums.REBASE_MODE_NONE { // If we are in a rebase, the only action that is allowed for // non-todo commits is rewording the current head commit if !(action == todo.Reword && self.isHeadCommit()) { @@ -688,7 +688,7 @@ func (self *LocalCommitsController) amendTo(commit *models.Commit) error { } func (self *LocalCommitsController) getDisabledReasonForAmendTo(commit *models.Commit) string { - if !self.isHeadCommit() && self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE { + if !self.isHeadCommit() && self.c.Model().WorkingTreeStateAtLastCommitRefresh != enums.REBASE_MODE_NONE { return self.c.Tr.AlreadyRebasing } @@ -871,7 +871,7 @@ func (self *LocalCommitsController) squashAllAboveFixupCommits(commit *models.Co } func (self *LocalCommitsController) getDisabledReasonForSquashAllAboveFixupCommits(commit *models.Commit) string { - if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE { + if self.c.Model().WorkingTreeStateAtLastCommitRefresh != enums.REBASE_MODE_NONE { return self.c.Tr.AlreadyRebasing } @@ -880,7 +880,7 @@ func (self *LocalCommitsController) getDisabledReasonForSquashAllAboveFixupCommi // For getting disabled reason func (self *LocalCommitsController) notMidRebase() string { - if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE { + if self.c.Model().WorkingTreeStateAtLastCommitRefresh != enums.REBASE_MODE_NONE { return self.c.Tr.AlreadyRebasing }