From 6ad4ffea3b90a7b8f739d43b2df6961e2bc0e507 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 28 Aug 2024 10:18:34 +0200 Subject: [PATCH] Cleanup: remove unnecessary viewFiles indirection viewFiles is only called from enter; it doesn't make much sense to fill in a SwitchToCommitFilesContextOpts struct to pass it to viewFiles for this one call. Simply inline viewFiles into enter and get rid of all that. --- .../switch_to_diff_files_controller.go | 20 ++++++------------- pkg/gui/controllers/types.go | 18 ----------------- 2 files changed, 6 insertions(+), 32 deletions(-) delete mode 100644 pkg/gui/controllers/types.go diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index 4b7e9e930..3a0898f5c 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -60,24 +60,16 @@ func (self *SwitchToDiffFilesController) GetOnClick() func() error { } func (self *SwitchToDiffFilesController) enter(ref types.Ref) error { - return self.viewFiles(SwitchToCommitFilesContextOpts{ - Ref: ref, - CanRebase: self.context.CanRebase(), - Context: self.context, - }) -} - -func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesContextOpts) error { commitFilesContext := self.c.Contexts().CommitFiles commitFilesContext.SetSelection(0) - commitFilesContext.SetRef(opts.Ref) - commitFilesContext.SetTitleRef(opts.Ref.Description()) - commitFilesContext.SetCanRebase(opts.CanRebase) - commitFilesContext.SetParentContext(opts.Context) - commitFilesContext.SetWindowName(opts.Context.GetWindowName()) + commitFilesContext.SetRef(ref) + commitFilesContext.SetTitleRef(ref.Description()) + commitFilesContext.SetCanRebase(self.context.CanRebase()) + commitFilesContext.SetParentContext(self.context) + commitFilesContext.SetWindowName(self.context.GetWindowName()) commitFilesContext.ClearSearchString() - commitFilesContext.GetView().TitlePrefix = opts.Context.GetView().TitlePrefix + commitFilesContext.GetView().TitlePrefix = self.context.GetView().TitlePrefix if err := self.c.Refresh(types.RefreshOptions{ Scope: []types.RefreshableView{types.COMMIT_FILES}, diff --git a/pkg/gui/controllers/types.go b/pkg/gui/controllers/types.go deleted file mode 100644 index f719b5de0..000000000 --- a/pkg/gui/controllers/types.go +++ /dev/null @@ -1,18 +0,0 @@ -package controllers - -import ( - "github.com/jesseduffield/lazygit/pkg/gui/types" -) - -// all fields mandatory (except `CanRebase` because it's boolean) -type SwitchToCommitFilesContextOpts struct { - // this is something like a commit or branch - Ref types.Ref - - // from the local commits view we're allowed to do rebase stuff with any patch - // we generate from the diff files context, but we don't have that same ability - // with say the sub commits context or the reflog context. - CanRebase bool - - Context types.Context -}