diff options
author | Ryooooooga <eial5q265e5@gmail.com> | 2022-03-26 22:18:08 +0900 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-04-02 17:04:42 +1100 |
commit | 4835fc00b861c6117c1d4d6873a05d808e54b4cf (patch) | |
tree | 6f521eb16da8c9310cab776d6b57e84de32d4752 /pkg/gui/controllers | |
parent | 30be50b641dbe594d7968e79536028f22beee1b0 (diff) |
introduce Ref interface
Diffstat (limited to 'pkg/gui/controllers')
-rw-r--r-- | pkg/gui/controllers/commits_files_controller.go | 14 | ||||
-rw-r--r-- | pkg/gui/controllers/switch_to_diff_files_controller.go | 20 | ||||
-rw-r--r-- | pkg/gui/controllers/switch_to_sub_commits_controller.go | 13 | ||||
-rw-r--r-- | pkg/gui/controllers/types.go | 8 |
4 files changed, 24 insertions, 31 deletions
diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index b28578822..20e78997e 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -112,7 +112,7 @@ func (self *CommitFilesController) onClickMain(opts gocui.ViewMouseBindingOpts) func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error { self.c.LogAction(self.c.Tr.Actions.CheckoutFile) - if err := self.git.WorkingTree.CheckoutFile(self.context().GetRefName(), node.GetPath()); err != nil { + if err := self.git.WorkingTree.CheckoutFile(self.context().GetRef().RefName(), node.GetPath()); err != nil { return self.c.Error(err) } @@ -166,7 +166,7 @@ func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) // if there is any file that hasn't been fully added we'll fully add everything, // otherwise we'll remove everything adding := node.AnyFile(func(file *models.CommitFile) bool { - return self.git.Patch.PatchManager.GetFileStatus(file.Name, self.context().GetRefName()) != patch.WHOLE + return self.git.Patch.PatchManager.GetFileStatus(file.Name, self.context().GetRef().RefName()) != patch.WHOLE }) err := node.ForEachFile(func(file *models.CommitFile) error { @@ -188,7 +188,7 @@ func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) }) } - if self.git.Patch.PatchManager.Active() && self.git.Patch.PatchManager.To != self.context().GetRefName() { + if self.git.Patch.PatchManager.Active() && self.git.Patch.PatchManager.To != self.context().GetRef().RefName() { return self.c.Confirm(types.ConfirmOpts{ Title: self.c.Tr.DiscardPatch, Prompt: self.c.Tr.DiscardPatchConfirm, @@ -212,9 +212,9 @@ func (self *CommitFilesController) startPatchManager() error { commitFilesContext := self.context() canRebase := commitFilesContext.GetCanRebase() - to := commitFilesContext.GetRefName() - - from, reverse := self.modes.Diffing.GetFromAndReverseArgsForDiff(to) + ref := commitFilesContext.GetRef() + to := ref.RefName() + from, reverse := self.modes.Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName()) self.git.Patch.PatchManager.Start(from, to, reverse, canRebase) return nil @@ -239,7 +239,7 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode return self.c.PushContext(self.contexts.PatchBuilding, opts) } - if self.git.Patch.PatchManager.Active() && self.git.Patch.PatchManager.To != self.context().GetRefName() { + if self.git.Patch.PatchManager.Active() && self.git.Patch.PatchManager.To != self.context().GetRef().RefName() { return self.c.Confirm(types.ConfirmOpts{ Title: self.c.Tr.DiscardPatch, Prompt: self.c.Tr.DiscardPatchConfirm, diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index c41dbdd37..275a5ebb2 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -11,8 +11,7 @@ var _ types.IController = &SwitchToDiffFilesController{} type CanSwitchToDiffFiles interface { types.Context CanRebase() bool - GetSelectedRefName() string - GetSelectedDescription() string + GetSelectedRef() types.Ref } type SwitchToDiffFilesController struct { @@ -51,23 +50,22 @@ func (self *SwitchToDiffFilesController) GetOnClick() func() error { return self.checkSelected(self.enter) } -func (self *SwitchToDiffFilesController) checkSelected(callback func(string) error) func() error { +func (self *SwitchToDiffFilesController) checkSelected(callback func(types.Ref) error) func() error { return func() error { - refName := self.context.GetSelectedRefName() - if refName == "" { + ref := self.context.GetSelectedRef() + if ref == nil { return nil } - return callback(refName) + return callback(ref) } } -func (self *SwitchToDiffFilesController) enter(refName string) error { +func (self *SwitchToDiffFilesController) enter(ref types.Ref) error { return self.viewFiles(SwitchToCommitFilesContextOpts{ - RefName: refName, - RefDescription: self.context.GetSelectedDescription(), - CanRebase: self.context.CanRebase(), - Context: self.context, + Ref: ref, + CanRebase: self.context.CanRebase(), + Context: self.context, }) } diff --git a/pkg/gui/controllers/switch_to_sub_commits_controller.go b/pkg/gui/controllers/switch_to_sub_commits_controller.go index d59f4fdbf..b41d122ed 100644 --- a/pkg/gui/controllers/switch_to_sub_commits_controller.go +++ b/pkg/gui/controllers/switch_to_sub_commits_controller.go @@ -10,8 +10,7 @@ var _ types.IController = &SwitchToSubCommitsController{} type CanSwitchToSubCommits interface { types.Context - GetSelectedRefName() string - GetSelectedDescription() string + GetSelectedRef() types.Ref } type SwitchToSubCommitsController struct { @@ -52,8 +51,8 @@ func (self *SwitchToSubCommitsController) GetOnClick() func() error { } func (self *SwitchToSubCommitsController) viewCommits() error { - refName := self.context.GetSelectedRefName() - if refName == "" { + ref := self.context.GetSelectedRef() + if ref == nil { return nil } @@ -63,7 +62,7 @@ func (self *SwitchToSubCommitsController) viewCommits() error { Limit: true, FilterPath: self.modes.Filtering.GetPath(), IncludeRebaseCommits: false, - RefName: refName, + RefName: ref.RefName(), }, ) if err != nil { @@ -75,8 +74,8 @@ func (self *SwitchToSubCommitsController) viewCommits() error { self.contexts.SubCommits.SetSelectedLineIdx(0) self.contexts.SubCommits.SetParentContext(self.context) self.contexts.SubCommits.SetWindowName(self.context.GetWindowName()) - self.contexts.SubCommits.SetTitleRef(self.context.GetSelectedDescription()) - self.contexts.SubCommits.SetRefName(refName) + self.contexts.SubCommits.SetTitleRef(ref.Description()) + self.contexts.SubCommits.SetRefName(ref.RefName()) err = self.c.PostRefreshUpdate(self.contexts.SubCommits) if err != nil { diff --git a/pkg/gui/controllers/types.go b/pkg/gui/controllers/types.go index e9af41089..f719b5de0 100644 --- a/pkg/gui/controllers/types.go +++ b/pkg/gui/controllers/types.go @@ -6,12 +6,8 @@ import ( // all fields mandatory (except `CanRebase` because it's boolean) type SwitchToCommitFilesContextOpts struct { - // this is something like a commit sha or branch name - RefName string - - // this will be displayed in the title of the view so we know whose diff files - // we're viewing - RefDescription string + // 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 |