mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
refactor
This commit is contained in:
@ -46,8 +46,9 @@ func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc) *PatchManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewPatchManager returns a new PatchManager
|
// NewPatchManager returns a new PatchManager
|
||||||
func (p *PatchManager) Start(parent string, diffMap map[string]string) {
|
func (p *PatchManager) Start(parent string, diffMap map[string]string, canRebase bool) {
|
||||||
p.Parent = parent
|
p.Parent = parent
|
||||||
|
p.CanRebase = canRebase
|
||||||
p.fileInfoMap = map[string]*fileInfo{}
|
p.fileInfoMap = map[string]*fileInfo{}
|
||||||
for filename, diff := range diffMap {
|
for filename, diff := range diffMap {
|
||||||
p.fileInfoMap[filename] = &fileInfo{
|
p.fileInfoMap[filename] = &fileInfo{
|
||||||
|
@ -6,6 +6,20 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// these are the possible ref types for refs that you can view files of.
|
||||||
|
// for local commits, we're allowed to build a patch and do things involving rebasing
|
||||||
|
// with that patch
|
||||||
|
REF_TYPE_LOCAL_COMMIT = iota
|
||||||
|
|
||||||
|
// for other kinds of commits like reflog commits, we can't do anything rebasey
|
||||||
|
REF_TYPE_OTHER_COMMIT
|
||||||
|
|
||||||
|
// for stash entries we can't do anything rebasey, and the command for
|
||||||
|
// obtaining the files is slightly different
|
||||||
|
REF_TYPE_STASH
|
||||||
|
)
|
||||||
|
|
||||||
func (gui *Gui) getSelectedCommitFile() *commands.CommitFile {
|
func (gui *Gui) getSelectedCommitFile() *commands.CommitFile {
|
||||||
selectedLine := gui.State.Panels.CommitFiles.SelectedLineIdx
|
selectedLine := gui.State.Panels.CommitFiles.SelectedLineIdx
|
||||||
if selectedLine == -1 {
|
if selectedLine == -1 {
|
||||||
@ -80,7 +94,8 @@ func (gui *Gui) refreshCommitFilesView() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err := gui.GitCommand.GetFilesInRef(gui.State.Panels.CommitFiles.refName, gui.State.Panels.CommitFiles.isStash, gui.GitCommand.PatchManager)
|
isStash := gui.State.Panels.CommitFiles.refType == REF_TYPE_STASH
|
||||||
|
files, err := gui.GitCommand.GetFilesInRef(gui.State.Panels.CommitFiles.refName, isStash, gui.GitCommand.PatchManager)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gui.surfaceError(err)
|
return gui.surfaceError(err)
|
||||||
}
|
}
|
||||||
@ -159,7 +174,8 @@ func (gui *Gui) startPatchManager() error {
|
|||||||
diffMap[commitFile.Name] = commitText
|
diffMap[commitFile.Name] = commitText
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.GitCommand.PatchManager.Start(gui.State.Panels.CommitFiles.refName, diffMap)
|
canRebase := gui.State.Panels.CommitFiles.refType == REF_TYPE_LOCAL_COMMIT
|
||||||
|
gui.GitCommand.PatchManager.Start(gui.State.Panels.CommitFiles.refName, diffMap, canRebase)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,14 +226,14 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error {
|
|||||||
return enterTheFile(selectedLineIdx)
|
return enterTheFile(selectedLineIdx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) switchToCommitFilesContext(refName string, isStash bool, context Context, windowName string) error {
|
func (gui *Gui) switchToCommitFilesContext(refName string, refType int, context Context, windowName string) error {
|
||||||
// sometimes the commitFiles view is already shown in another window, so we need to ensure that window
|
// sometimes the commitFiles view is already shown in another window, so we need to ensure that window
|
||||||
// no longer considers the commitFiles view as its main view.
|
// no longer considers the commitFiles view as its main view.
|
||||||
gui.resetWindowForView("commitFiles")
|
gui.resetWindowForView("commitFiles")
|
||||||
|
|
||||||
gui.State.Panels.CommitFiles.SelectedLineIdx = 0
|
gui.State.Panels.CommitFiles.SelectedLineIdx = 0
|
||||||
gui.State.Panels.CommitFiles.refName = refName
|
gui.State.Panels.CommitFiles.refName = refName
|
||||||
gui.State.Panels.CommitFiles.isStash = isStash
|
gui.State.Panels.CommitFiles.refType = refType
|
||||||
gui.Contexts.CommitFiles.Context.SetParentContext(context)
|
gui.Contexts.CommitFiles.Context.SetParentContext(context)
|
||||||
gui.Contexts.CommitFiles.Context.SetWindowName(windowName)
|
gui.Contexts.CommitFiles.Context.SetWindowName(windowName)
|
||||||
|
|
||||||
|
@ -505,7 +505,7 @@ func (gui *Gui) handleViewCommitFiles() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.BranchCommits.Context, "commits")
|
return gui.switchToCommitFilesContext(commit.Sha, REF_TYPE_LOCAL_COMMIT, gui.Contexts.BranchCommits.Context, "commits")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) {
|
func (gui *Gui) hasCommit(commits []*commands.Commit, target string) (int, bool) {
|
||||||
|
@ -188,7 +188,7 @@ type commitFilesPanelState struct {
|
|||||||
// this is the SHA of the commit or the stash index of the stash.
|
// this is the SHA of the commit or the stash index of the stash.
|
||||||
// Not sure if ref is actually the right word here
|
// Not sure if ref is actually the right word here
|
||||||
refName string
|
refName string
|
||||||
isStash bool // true if we're dealing with a stash entry rather than a commit
|
refType int // eg REF_TYPE_LOCAL_COMMIT
|
||||||
}
|
}
|
||||||
|
|
||||||
type panelStates struct {
|
type panelStates struct {
|
||||||
|
@ -119,5 +119,5 @@ func (gui *Gui) handleViewReflogCommitFiles() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.ReflogCommits.Context, "commits")
|
return gui.switchToCommitFilesContext(commit.Sha, REF_TYPE_OTHER_COMMIT, gui.Contexts.ReflogCommits.Context, "commits")
|
||||||
}
|
}
|
||||||
|
@ -135,5 +135,5 @@ func (gui *Gui) handleViewStashFiles() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.switchToCommitFilesContext(stashEntry.RefName(), true, gui.Contexts.Stash.Context, "stash")
|
return gui.switchToCommitFilesContext(stashEntry.RefName(), REF_TYPE_STASH, gui.Contexts.Stash.Context, "stash")
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user