1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-31 23:19:40 +02:00

rename patch manager to patch builder

This commit is contained in:
Jesse Duffield 2023-03-19 16:09:03 +11:00
parent 7ce3165afa
commit 60f902f026
15 changed files with 83 additions and 84 deletions

View File

@ -117,14 +117,14 @@ func NewGitCommandAux(
workingTreeCommands := git_commands.NewWorkingTreeCommands(gitCommon, submoduleCommands, fileLoader) workingTreeCommands := git_commands.NewWorkingTreeCommands(gitCommon, submoduleCommands, fileLoader)
rebaseCommands := git_commands.NewRebaseCommands(gitCommon, commitCommands, workingTreeCommands) rebaseCommands := git_commands.NewRebaseCommands(gitCommon, commitCommands, workingTreeCommands)
stashCommands := git_commands.NewStashCommands(gitCommon, fileLoader, workingTreeCommands) stashCommands := git_commands.NewStashCommands(gitCommon, fileLoader, workingTreeCommands)
// TODO: have patch manager take workingTreeCommands in its entirety // TODO: have patch builder take workingTreeCommands in its entirety
patchManager := patch.NewPatchManager(cmn.Log, workingTreeCommands.ApplyPatch, patchBuilder := patch.NewPatchBuilder(cmn.Log, workingTreeCommands.ApplyPatch,
func(from string, to string, reverse bool, filename string, plain bool) (string, error) { func(from string, to string, reverse bool, filename string, plain bool) (string, error) {
// TODO: make patch manager take Gui.IgnoreWhitespaceInDiffView into // TODO: make patch builder take Gui.IgnoreWhitespaceInDiffView into
// account. For now we just pass false. // account. For now we just pass false.
return workingTreeCommands.ShowFileDiff(from, to, reverse, filename, plain, false) return workingTreeCommands.ShowFileDiff(from, to, reverse, filename, plain, false)
}) })
patchCommands := git_commands.NewPatchCommands(gitCommon, rebaseCommands, commitCommands, statusCommands, stashCommands, patchManager) patchCommands := git_commands.NewPatchCommands(gitCommon, rebaseCommands, commitCommands, statusCommands, stashCommands, patchBuilder)
bisectCommands := git_commands.NewBisectCommands(gitCommon) bisectCommands := git_commands.NewBisectCommands(gitCommon)
branchLoader := git_commands.NewBranchLoader(cmn, branchCommands.GetRawBranches, branchCommands.CurrentBranchInfo, configCommands) branchLoader := git_commands.NewBranchLoader(cmn, branchCommands.GetRawBranches, branchCommands.CurrentBranchInfo, configCommands)

View File

@ -16,7 +16,7 @@ type PatchCommands struct {
status *StatusCommands status *StatusCommands
stash *StashCommands stash *StashCommands
PatchManager *patch.PatchManager PatchBuilder *patch.PatchBuilder
} }
func NewPatchCommands( func NewPatchCommands(
@ -25,7 +25,7 @@ func NewPatchCommands(
commit *CommitCommands, commit *CommitCommands,
status *StatusCommands, status *StatusCommands,
stash *StashCommands, stash *StashCommands,
patchManager *patch.PatchManager, patchBuilder *patch.PatchBuilder,
) *PatchCommands { ) *PatchCommands {
return &PatchCommands{ return &PatchCommands{
GitCommon: gitCommon, GitCommon: gitCommon,
@ -33,7 +33,7 @@ func NewPatchCommands(
commit: commit, commit: commit,
status: status, status: status,
stash: stash, stash: stash,
PatchManager: patchManager, PatchBuilder: patchBuilder,
} }
} }
@ -44,7 +44,7 @@ func (self *PatchCommands) DeletePatchesFromCommit(commits []*models.Commit, com
} }
// apply each patch in reverse // apply each patch in reverse
if err := self.PatchManager.ApplyPatches(true); err != nil { if err := self.PatchBuilder.ApplyPatches(true); err != nil {
_ = self.rebase.AbortRebase() _ = self.rebase.AbortRebase()
return err return err
} }
@ -55,7 +55,7 @@ func (self *PatchCommands) DeletePatchesFromCommit(commits []*models.Commit, com
} }
self.rebase.onSuccessfulContinue = func() error { self.rebase.onSuccessfulContinue = func() error {
self.PatchManager.Reset() self.PatchBuilder.Reset()
return nil return nil
} }
@ -70,7 +70,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
} }
// apply each patch forward // apply each patch forward
if err := self.PatchManager.ApplyPatches(false); err != nil { if err := self.PatchBuilder.ApplyPatches(false); err != nil {
// Don't abort the rebase here; this might cause conflicts, so give // Don't abort the rebase here; this might cause conflicts, so give
// the user a chance to resolve them // the user a chance to resolve them
return err return err
@ -82,7 +82,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
} }
self.rebase.onSuccessfulContinue = func() error { self.rebase.onSuccessfulContinue = func() error {
self.PatchManager.Reset() self.PatchBuilder.Reset()
return nil return nil
} }
@ -117,7 +117,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
} }
// apply each patch in reverse // apply each patch in reverse
if err := self.PatchManager.ApplyPatches(true); err != nil { if err := self.PatchBuilder.ApplyPatches(true); err != nil {
_ = self.rebase.AbortRebase() _ = self.rebase.AbortRebase()
return err return err
} }
@ -152,7 +152,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
} }
self.rebase.onSuccessfulContinue = func() error { self.rebase.onSuccessfulContinue = func() error {
self.PatchManager.Reset() self.PatchBuilder.Reset()
return nil return nil
} }
@ -173,7 +173,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId
return err return err
} }
if err := self.PatchManager.ApplyPatches(true); err != nil { if err := self.PatchBuilder.ApplyPatches(true); err != nil {
if self.status.WorkingTreeState() == enums.REBASE_MODE_REBASING { if self.status.WorkingTreeState() == enums.REBASE_MODE_REBASING {
_ = self.rebase.AbortRebase() _ = self.rebase.AbortRebase()
} }
@ -210,7 +210,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId
} }
} }
self.PatchManager.Reset() self.PatchBuilder.Reset()
return nil return nil
} }
@ -222,7 +222,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm
return err return err
} }
if err := self.PatchManager.ApplyPatches(true); err != nil { if err := self.PatchBuilder.ApplyPatches(true); err != nil {
_ = self.rebase.AbortRebase() _ = self.rebase.AbortRebase()
return err return err
} }
@ -253,7 +253,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm
return errors.New("You are midway through another rebase operation. Please abort to start again") return errors.New("You are midway through another rebase operation. Please abort to start again")
} }
self.PatchManager.Reset() self.PatchBuilder.Reset()
return self.rebase.ContinueRebase() return self.rebase.ContinueRebase()
} }

View File

@ -33,8 +33,8 @@ type (
loadFileDiffFunc func(from string, to string, reverse bool, filename string, plain bool) (string, error) loadFileDiffFunc func(from string, to string, reverse bool, filename string, plain bool) (string, error)
) )
// PatchManager manages the building of a patch for a commit to be applied to another commit (or the working tree, or removed from the current commit). We also support building patches from things like stashes, for which there is less flexibility // PatchBuilder manages the building of a patch for a commit to be applied to another commit (or the working tree, or removed from the current commit). We also support building patches from things like stashes, for which there is less flexibility
type PatchManager struct { type PatchBuilder struct {
// To is the commit sha if we're dealing with files of a commit, or a stash ref for a stash // To is the commit sha if we're dealing with files of a commit, or a stash ref for a stash
To string To string
From string From string
@ -53,17 +53,16 @@ type PatchManager struct {
loadFileDiff loadFileDiffFunc loadFileDiff loadFileDiffFunc
} }
// NewPatchManager returns a new PatchManager // NewPatchBuilder returns a new PatchBuilder
func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc, loadFileDiff loadFileDiffFunc) *PatchManager { func NewPatchBuilder(log *logrus.Entry, applyPatch applyPatchFunc, loadFileDiff loadFileDiffFunc) *PatchBuilder {
return &PatchManager{ return &PatchBuilder{
Log: log, Log: log,
applyPatch: applyPatch, applyPatch: applyPatch,
loadFileDiff: loadFileDiff, loadFileDiff: loadFileDiff,
} }
} }
// NewPatchManager returns a new PatchManager func (p *PatchBuilder) Start(from, to string, reverse bool, canRebase bool) {
func (p *PatchManager) Start(from, to string, reverse bool, canRebase bool) {
p.To = to p.To = to
p.From = from p.From = from
p.reverse = reverse p.reverse = reverse
@ -71,7 +70,7 @@ func (p *PatchManager) Start(from, to string, reverse bool, canRebase bool) {
p.fileInfoMap = map[string]*fileInfo{} p.fileInfoMap = map[string]*fileInfo{}
} }
func (p *PatchManager) addFileWhole(info *fileInfo) { func (p *PatchBuilder) addFileWhole(info *fileInfo) {
info.mode = WHOLE info.mode = WHOLE
lineCount := len(strings.Split(info.diff, "\n")) lineCount := len(strings.Split(info.diff, "\n"))
// add every line index // add every line index
@ -82,12 +81,12 @@ func (p *PatchManager) addFileWhole(info *fileInfo) {
} }
} }
func (p *PatchManager) removeFile(info *fileInfo) { func (p *PatchBuilder) removeFile(info *fileInfo) {
info.mode = UNSELECTED info.mode = UNSELECTED
info.includedLineIndices = nil info.includedLineIndices = nil
} }
func (p *PatchManager) AddFileWhole(filename string) error { func (p *PatchBuilder) AddFileWhole(filename string) error {
info, err := p.getFileInfo(filename) info, err := p.getFileInfo(filename)
if err != nil { if err != nil {
return err return err
@ -98,7 +97,7 @@ func (p *PatchManager) AddFileWhole(filename string) error {
return nil return nil
} }
func (p *PatchManager) RemoveFile(filename string) error { func (p *PatchBuilder) RemoveFile(filename string) error {
info, err := p.getFileInfo(filename) info, err := p.getFileInfo(filename)
if err != nil { if err != nil {
return err return err
@ -117,7 +116,7 @@ func getIndicesForRange(first, last int) []int {
return indices return indices
} }
func (p *PatchManager) getFileInfo(filename string) (*fileInfo, error) { func (p *PatchBuilder) getFileInfo(filename string) (*fileInfo, error) {
info, ok := p.fileInfoMap[filename] info, ok := p.fileInfoMap[filename]
if ok { if ok {
return info, nil return info, nil
@ -137,7 +136,7 @@ func (p *PatchManager) getFileInfo(filename string) (*fileInfo, error) {
return info, nil return info, nil
} }
func (p *PatchManager) AddFileLineRange(filename string, firstLineIdx, lastLineIdx int) error { func (p *PatchBuilder) AddFileLineRange(filename string, firstLineIdx, lastLineIdx int) error {
info, err := p.getFileInfo(filename) info, err := p.getFileInfo(filename)
if err != nil { if err != nil {
return err return err
@ -148,7 +147,7 @@ func (p *PatchManager) AddFileLineRange(filename string, firstLineIdx, lastLineI
return nil return nil
} }
func (p *PatchManager) RemoveFileLineRange(filename string, firstLineIdx, lastLineIdx int) error { func (p *PatchBuilder) RemoveFileLineRange(filename string, firstLineIdx, lastLineIdx int) error {
info, err := p.getFileInfo(filename) info, err := p.getFileInfo(filename)
if err != nil { if err != nil {
return err return err
@ -162,7 +161,7 @@ func (p *PatchManager) RemoveFileLineRange(filename string, firstLineIdx, lastLi
return nil return nil
} }
func (p *PatchManager) RenderPatchForFile(filename string, plain bool, reverse bool) string { func (p *PatchBuilder) RenderPatchForFile(filename string, plain bool, reverse bool) string {
info, err := p.getFileInfo(filename) info, err := p.getFileInfo(filename)
if err != nil { if err != nil {
p.Log.Error(err) p.Log.Error(err)
@ -195,7 +194,7 @@ func (p *PatchManager) RenderPatchForFile(filename string, plain bool, reverse b
} }
} }
func (p *PatchManager) renderEachFilePatch(plain bool) []string { func (p *PatchBuilder) renderEachFilePatch(plain bool) []string {
// sort files by name then iterate through and render each patch // sort files by name then iterate through and render each patch
filenames := maps.Keys(p.fileInfoMap) filenames := maps.Keys(p.fileInfoMap)
@ -210,11 +209,11 @@ func (p *PatchManager) renderEachFilePatch(plain bool) []string {
return output return output
} }
func (p *PatchManager) RenderAggregatedPatch(plain bool) string { func (p *PatchBuilder) RenderAggregatedPatch(plain bool) string {
return strings.Join(p.renderEachFilePatch(plain), "") return strings.Join(p.renderEachFilePatch(plain), "")
} }
func (p *PatchManager) GetFileStatus(filename string, parent string) PatchStatus { func (p *PatchBuilder) GetFileStatus(filename string, parent string) PatchStatus {
if parent != p.To { if parent != p.To {
return UNSELECTED return UNSELECTED
} }
@ -227,7 +226,7 @@ func (p *PatchManager) GetFileStatus(filename string, parent string) PatchStatus
return info.mode return info.mode
} }
func (p *PatchManager) GetFileIncLineIndices(filename string) ([]int, error) { func (p *PatchBuilder) GetFileIncLineIndices(filename string) ([]int, error) {
info, err := p.getFileInfo(filename) info, err := p.getFileInfo(filename)
if err != nil { if err != nil {
return nil, err return nil, err
@ -235,7 +234,7 @@ func (p *PatchManager) GetFileIncLineIndices(filename string) ([]int, error) {
return info.includedLineIndices, nil return info.includedLineIndices, nil
} }
func (p *PatchManager) ApplyPatches(reverse bool) error { func (p *PatchBuilder) ApplyPatches(reverse bool) error {
patch := "" patch := ""
applyFlags := []string{"index", "3way"} applyFlags := []string{"index", "3way"}
@ -255,16 +254,16 @@ func (p *PatchManager) ApplyPatches(reverse bool) error {
} }
// clears the patch // clears the patch
func (p *PatchManager) Reset() { func (p *PatchBuilder) Reset() {
p.To = "" p.To = ""
p.fileInfoMap = map[string]*fileInfo{} p.fileInfoMap = map[string]*fileInfo{}
} }
func (p *PatchManager) Active() bool { func (p *PatchBuilder) Active() bool {
return p.To != "" return p.To != ""
} }
func (p *PatchManager) IsEmpty() bool { func (p *PatchBuilder) IsEmpty() bool {
for _, fileInfo := range p.fileInfoMap { for _, fileInfo := range p.fileInfoMap {
if fileInfo.mode == WHOLE || (fileInfo.mode == PART && len(fileInfo.includedLineIndices) > 0) { if fileInfo.mode == WHOLE || (fileInfo.mode == PART && len(fileInfo.includedLineIndices) > 0) {
return false return false
@ -275,11 +274,11 @@ func (p *PatchManager) IsEmpty() bool {
} }
// if any of these things change we'll need to reset and start a new patch // if any of these things change we'll need to reset and start a new patch
func (p *PatchManager) NewPatchRequired(from string, to string, reverse bool) bool { func (p *PatchBuilder) NewPatchRequired(from string, to string, reverse bool) bool {
return from != p.From || to != p.To || reverse != p.reverse return from != p.From || to != p.To || reverse != p.reverse
} }
func (p *PatchManager) AllFilesInPatch() []string { func (p *PatchBuilder) AllFilesInPatch() []string {
files := make([]string, 0, len(p.fileInfoMap)) files := make([]string, 0, len(p.fileInfoMap))
for filename := range p.fileInfoMap { for filename := range p.fileInfoMap {

View File

@ -51,8 +51,8 @@ func (gui *Gui) branchCommitsRenderToMain() error {
} }
func (gui *Gui) secondaryPatchPanelUpdateOpts() *types.ViewUpdateOpts { func (gui *Gui) secondaryPatchPanelUpdateOpts() *types.ViewUpdateOpts {
if gui.git.Patch.PatchManager.Active() { if gui.git.Patch.PatchBuilder.Active() {
patch := gui.git.Patch.PatchManager.RenderAggregatedPatch(false) patch := gui.git.Patch.PatchBuilder.RenderAggregatedPatch(false)
return &types.ViewUpdateOpts{ return &types.ViewUpdateOpts{
Task: types.NewRenderStringWithoutScrollTask(patch), Task: types.NewRenderStringWithoutScrollTask(patch),

View File

@ -150,15 +150,15 @@ func (gui *Gui) contextTree() *context.ContextTree {
func(opts types.OnFocusLostOpts) error { func(opts types.OnFocusLostOpts) error {
gui.Views.PatchBuilding.Wrap = true gui.Views.PatchBuilding.Wrap = true
if gui.git.Patch.PatchManager.IsEmpty() { if gui.git.Patch.PatchBuilder.IsEmpty() {
gui.git.Patch.PatchManager.Reset() gui.git.Patch.PatchBuilder.Reset()
} }
return nil return nil
}, },
func() []int { func() []int {
filename := gui.State.Contexts.CommitFiles.GetSelectedPath() filename := gui.State.Contexts.CommitFiles.GetSelectedPath()
includedLineIndices, err := gui.git.Patch.PatchManager.GetFileIncLineIndices(filename) includedLineIndices, err := gui.git.Patch.PatchBuilder.GetFileIncLineIndices(filename)
if err != nil { if err != nil {
gui.Log.Error(err) gui.Log.Error(err)
return nil return nil

View File

@ -157,8 +157,8 @@ func (self *CommitFilesController) edit(node *filetree.CommitFileNode) error {
func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) error { func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) error {
toggle := func() error { toggle := func() error {
return self.c.WithWaitingStatus(self.c.Tr.LcUpdatingPatch, func() error { return self.c.WithWaitingStatus(self.c.Tr.LcUpdatingPatch, func() error {
if !self.git.Patch.PatchManager.Active() { if !self.git.Patch.PatchBuilder.Active() {
if err := self.startPatchManager(); err != nil { if err := self.startPatchBuilder(); err != nil {
return err return err
} }
} }
@ -166,34 +166,34 @@ func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode)
// if there is any file that hasn't been fully added we'll fully add everything, // if there is any file that hasn't been fully added we'll fully add everything,
// otherwise we'll remove everything // otherwise we'll remove everything
adding := node.SomeFile(func(file *models.CommitFile) bool { adding := node.SomeFile(func(file *models.CommitFile) bool {
return self.git.Patch.PatchManager.GetFileStatus(file.Name, self.context().GetRef().RefName()) != patch.WHOLE return self.git.Patch.PatchBuilder.GetFileStatus(file.Name, self.context().GetRef().RefName()) != patch.WHOLE
}) })
err := node.ForEachFile(func(file *models.CommitFile) error { err := node.ForEachFile(func(file *models.CommitFile) error {
if adding { if adding {
return self.git.Patch.PatchManager.AddFileWhole(file.Name) return self.git.Patch.PatchBuilder.AddFileWhole(file.Name)
} else { } else {
return self.git.Patch.PatchManager.RemoveFile(file.Name) return self.git.Patch.PatchBuilder.RemoveFile(file.Name)
} }
}) })
if err != nil { if err != nil {
return self.c.Error(err) return self.c.Error(err)
} }
if self.git.Patch.PatchManager.IsEmpty() { if self.git.Patch.PatchBuilder.IsEmpty() {
self.git.Patch.PatchManager.Reset() self.git.Patch.PatchBuilder.Reset()
} }
return self.c.PostRefreshUpdate(self.context()) return self.c.PostRefreshUpdate(self.context())
}) })
} }
if self.git.Patch.PatchManager.Active() && self.git.Patch.PatchManager.To != self.context().GetRef().RefName() { if self.git.Patch.PatchBuilder.Active() && self.git.Patch.PatchBuilder.To != self.context().GetRef().RefName() {
return self.c.Confirm(types.ConfirmOpts{ return self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.DiscardPatch, Title: self.c.Tr.DiscardPatch,
Prompt: self.c.Tr.DiscardPatchConfirm, Prompt: self.c.Tr.DiscardPatchConfirm,
HandleConfirm: func() error { HandleConfirm: func() error {
self.git.Patch.PatchManager.Reset() self.git.Patch.PatchBuilder.Reset()
return toggle() return toggle()
}, },
}) })
@ -207,7 +207,7 @@ func (self *CommitFilesController) toggleAllForPatch(_ *filetree.CommitFileNode)
return self.toggleForPatch(root) return self.toggleForPatch(root)
} }
func (self *CommitFilesController) startPatchManager() error { func (self *CommitFilesController) startPatchBuilder() error {
commitFilesContext := self.context() commitFilesContext := self.context()
canRebase := commitFilesContext.GetCanRebase() canRebase := commitFilesContext.GetCanRebase()
@ -215,7 +215,7 @@ func (self *CommitFilesController) startPatchManager() error {
to := ref.RefName() to := ref.RefName()
from, reverse := self.modes.Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName()) from, reverse := self.modes.Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName())
self.git.Patch.PatchManager.Start(from, to, reverse, canRebase) self.git.Patch.PatchBuilder.Start(from, to, reverse, canRebase)
return nil return nil
} }
@ -229,8 +229,8 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode
} }
enterTheFile := func() error { enterTheFile := func() error {
if !self.git.Patch.PatchManager.Active() { if !self.git.Patch.PatchBuilder.Active() {
if err := self.startPatchManager(); err != nil { if err := self.startPatchBuilder(); err != nil {
return err return err
} }
} }
@ -238,12 +238,12 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode
return self.c.PushContext(self.contexts.CustomPatchBuilder, opts) return self.c.PushContext(self.contexts.CustomPatchBuilder, opts)
} }
if self.git.Patch.PatchManager.Active() && self.git.Patch.PatchManager.To != self.context().GetRef().RefName() { if self.git.Patch.PatchBuilder.Active() && self.git.Patch.PatchBuilder.To != self.context().GetRef().RefName() {
return self.c.Confirm(types.ConfirmOpts{ return self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.DiscardPatch, Title: self.c.Tr.DiscardPatch,
Prompt: self.c.Tr.DiscardPatchConfirm, Prompt: self.c.Tr.DiscardPatchConfirm,
HandleConfirm: func() error { HandleConfirm: func() error {
self.git.Patch.PatchManager.Reset() self.git.Patch.PatchBuilder.Reset()
return enterTheFile() return enterTheFile()
}, },
}) })

View File

@ -101,7 +101,7 @@ func (self *ContextLinesController) applyChange() error {
} }
func (self *ContextLinesController) checkCanChangeContext() error { func (self *ContextLinesController) checkCanChangeContext() error {
if self.git.Patch.PatchManager.Active() { if self.git.Patch.PatchBuilder.Active() {
return errors.New(self.c.Tr.CantChangeContextSizeError) return errors.New(self.c.Tr.CantChangeContextSizeError)
} }

View File

@ -43,7 +43,7 @@ func (self *PatchBuildingHelper) Escape() error {
// kills the custom patch and returns us back to the commit files panel if needed // kills the custom patch and returns us back to the commit files panel if needed
func (self *PatchBuildingHelper) Reset() error { func (self *PatchBuildingHelper) Reset() error {
self.git.Patch.PatchManager.Reset() self.git.Patch.PatchBuilder.Reset()
if self.c.CurrentStaticContext().GetKind() != types.SIDE_CONTEXT { if self.c.CurrentStaticContext().GetKind() != types.SIDE_CONTEXT {
if err := self.Escape(); err != nil { if err := self.Escape(); err != nil {

View File

@ -106,7 +106,7 @@ func (self *PatchBuildingController) toggleSelection() error {
self.context().GetMutex().Lock() self.context().GetMutex().Lock()
defer self.context().GetMutex().Unlock() defer self.context().GetMutex().Unlock()
toggleFunc := self.git.Patch.PatchManager.AddFileLineRange toggleFunc := self.git.Patch.PatchBuilder.AddFileLineRange
filename := self.contexts.CommitFiles.GetSelectedPath() filename := self.contexts.CommitFiles.GetSelectedPath()
if filename == "" { if filename == "" {
return nil return nil
@ -114,13 +114,13 @@ func (self *PatchBuildingController) toggleSelection() error {
state := self.context().GetState() state := self.context().GetState()
includedLineIndices, err := self.git.Patch.PatchManager.GetFileIncLineIndices(filename) includedLineIndices, err := self.git.Patch.PatchBuilder.GetFileIncLineIndices(filename)
if err != nil { if err != nil {
return err return err
} }
currentLineIsStaged := lo.Contains(includedLineIndices, state.GetSelectedLineIdx()) currentLineIsStaged := lo.Contains(includedLineIndices, state.GetSelectedLineIdx())
if currentLineIsStaged { if currentLineIsStaged {
toggleFunc = self.git.Patch.PatchManager.RemoveFileLineRange toggleFunc = self.git.Patch.PatchBuilder.RemoveFileLineRange
} }
// add range of lines to those set for the file // add range of lines to those set for the file

View File

@ -8,7 +8,7 @@ import (
) )
func (gui *Gui) handleCreatePatchOptionsMenu() error { func (gui *Gui) handleCreatePatchOptionsMenu() error {
if !gui.git.Patch.PatchManager.Active() { if !gui.git.Patch.PatchBuilder.Active() {
return gui.c.ErrorMsg(gui.c.Tr.NoPatchError) return gui.c.ErrorMsg(gui.c.Tr.NoPatchError)
} }
@ -30,10 +30,10 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
}, },
} }
if gui.git.Patch.PatchManager.CanRebase && gui.git.Status.WorkingTreeState() == enums.REBASE_MODE_NONE { if gui.git.Patch.PatchBuilder.CanRebase && gui.git.Status.WorkingTreeState() == enums.REBASE_MODE_NONE {
menuItems = append(menuItems, []*types.MenuItem{ menuItems = append(menuItems, []*types.MenuItem{
{ {
Label: fmt.Sprintf("remove patch from original commit (%s)", gui.git.Patch.PatchManager.To), Label: fmt.Sprintf("remove patch from original commit (%s)", gui.git.Patch.PatchBuilder.To),
OnPress: gui.handleDeletePatchFromCommit, OnPress: gui.handleDeletePatchFromCommit,
Key: 'd', Key: 'd',
}, },
@ -51,7 +51,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
if gui.currentContext().GetKey() == gui.State.Contexts.LocalCommits.GetKey() { if gui.currentContext().GetKey() == gui.State.Contexts.LocalCommits.GetKey() {
selectedCommit := gui.getSelectedLocalCommit() selectedCommit := gui.getSelectedLocalCommit()
if selectedCommit != nil && gui.git.Patch.PatchManager.To != selectedCommit.Sha { if selectedCommit != nil && gui.git.Patch.PatchBuilder.To != selectedCommit.Sha {
// adding this option to index 1 // adding this option to index 1
menuItems = append( menuItems = append(
menuItems[:1], menuItems[:1],
@ -82,7 +82,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
func (gui *Gui) getPatchCommitIndex() int { func (gui *Gui) getPatchCommitIndex() int {
for index, commit := range gui.State.Model.Commits { for index, commit := range gui.State.Model.Commits {
if commit.Sha == gui.git.Patch.PatchManager.To { if commit.Sha == gui.git.Patch.PatchBuilder.To {
return index return index
} }
} }
@ -195,14 +195,14 @@ func (gui *Gui) handleApplyPatch(reverse bool) error {
action = "Apply patch in reverse" action = "Apply patch in reverse"
} }
gui.c.LogAction(action) gui.c.LogAction(action)
if err := gui.git.Patch.PatchManager.ApplyPatches(reverse); err != nil { if err := gui.git.Patch.PatchBuilder.ApplyPatches(reverse); err != nil {
return gui.c.Error(err) return gui.c.Error(err)
} }
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
} }
func (gui *Gui) copyPatchToClipboard() error { func (gui *Gui) copyPatchToClipboard() error {
patch := gui.git.Patch.PatchManager.RenderAggregatedPatch(true) patch := gui.git.Patch.PatchBuilder.RenderAggregatedPatch(true)
gui.c.LogAction(gui.c.Tr.Actions.CopyPatchToClipboard) gui.c.LogAction(gui.c.Tr.Actions.CopyPatchToClipboard)
if err := gui.os.CopyToClipboard(patch); err != nil { if err := gui.os.CopyToClipboard(patch); err != nil {

View File

@ -243,7 +243,7 @@ func (gui *Gui) commitFilesListContext() *context.CommitFilesContext {
return [][]string{{style.FgRed.Sprint("(none)")}} return [][]string{{style.FgRed.Sprint("(none)")}}
} }
lines := presentation.RenderCommitFileTree(gui.State.Contexts.CommitFiles.CommitFileTreeViewModel, gui.State.Modes.Diffing.Ref, gui.git.Patch.PatchManager) lines := presentation.RenderCommitFileTree(gui.State.Contexts.CommitFiles.CommitFileTreeViewModel, gui.State.Modes.Diffing.Ref, gui.git.Patch.PatchBuilder)
return slices.Map(lines, func(line string) []string { return slices.Map(lines, func(line string) []string {
return []string{line} return []string{line}
}) })

View File

@ -30,7 +30,7 @@ func (gui *Gui) modeStatuses() []modeStatus {
reset: gui.exitDiffMode, reset: gui.exitDiffMode,
}, },
{ {
isActive: gui.git.Patch.PatchManager.Active, isActive: gui.git.Patch.PatchBuilder.Active,
description: func() string { description: func() string {
return gui.withResetButton(gui.c.Tr.LcBuildingPatch, style.FgYellow.SetBold()) return gui.withResetButton(gui.c.Tr.LcBuildingPatch, style.FgYellow.SetBold())
}, },

View File

@ -40,7 +40,7 @@ func RenderFileTree(
func RenderCommitFileTree( func RenderCommitFileTree(
tree *filetree.CommitFileTreeViewModel, tree *filetree.CommitFileTreeViewModel,
diffName string, diffName string,
patchManager *patch.PatchManager, patchBuilder *patch.PatchBuilder,
) []string { ) []string {
return renderAux(tree.GetRoot().Raw(), tree.CollapsedPaths(), "", -1, func(node *filetree.Node[models.CommitFile], depth int) string { return renderAux(tree.GetRoot().Raw(), tree.CollapsedPaths(), "", -1, func(node *filetree.Node[models.CommitFile], depth int) string {
// This is a little convoluted because we're dealing with either a leaf or a non-leaf. // This is a little convoluted because we're dealing with either a leaf or a non-leaf.
@ -49,11 +49,11 @@ func RenderCommitFileTree(
// based on the leaves of that subtree // based on the leaves of that subtree
var status patch.PatchStatus var status patch.PatchStatus
if node.EveryFile(func(file *models.CommitFile) bool { if node.EveryFile(func(file *models.CommitFile) bool {
return patchManager.GetFileStatus(file.Name, tree.GetRef().RefName()) == patch.WHOLE return patchBuilder.GetFileStatus(file.Name, tree.GetRef().RefName()) == patch.WHOLE
}) { }) {
status = patch.WHOLE status = patch.WHOLE
} else if node.EveryFile(func(file *models.CommitFile) bool { } else if node.EveryFile(func(file *models.CommitFile) bool {
return patchManager.GetFileStatus(file.Name, tree.GetRef().RefName()) == patch.UNSELECTED return patchBuilder.GetFileStatus(file.Name, tree.GetRef().RefName()) == patch.UNSELECTED
}) { }) {
status = patch.UNSELECTED status = patch.UNSELECTED
} else { } else {

View File

@ -134,15 +134,15 @@ M file1
for _, path := range s.collapsedPaths { for _, path := range s.collapsedPaths {
viewModel.ToggleCollapsed(path) viewModel.ToggleCollapsed(path)
} }
patchManager := patch.NewPatchManager( patchBuilder := patch.NewPatchBuilder(
utils.NewDummyLog(), utils.NewDummyLog(),
func(patch string, flags ...string) error { return nil }, func(patch string, flags ...string) error { return nil },
func(from string, to string, reverse bool, filename string, plain bool) (string, error) { func(from string, to string, reverse bool, filename string, plain bool) (string, error) {
return "", nil return "", nil
}, },
) )
patchManager.Start("from", "to", false, false) patchBuilder.Start("from", "to", false, false)
result := RenderCommitFileTree(viewModel, "", patchManager) result := RenderCommitFileTree(viewModel, "", patchBuilder)
assert.EqualValues(t, s.expected, result) assert.EqualValues(t, s.expected, result)
}) })
} }

View File

@ -653,7 +653,7 @@ func (gui *Gui) refreshPatchBuildingPanel(opts types.OnFocusOpts) error {
selectedLineIdx = opts.ClickedViewLineIdx selectedLineIdx = opts.ClickedViewLineIdx
} }
if !gui.git.Patch.PatchManager.Active() { if !gui.git.Patch.PatchBuilder.Active() {
return gui.helpers.PatchBuilding.Escape() return gui.helpers.PatchBuilding.Escape()
} }
@ -672,7 +672,7 @@ func (gui *Gui) refreshPatchBuildingPanel(opts types.OnFocusOpts) error {
return err return err
} }
secondaryDiff := gui.git.Patch.PatchManager.RenderPatchForFile(path, false, false) secondaryDiff := gui.git.Patch.PatchBuilder.RenderPatchForFile(path, false, false)
if err != nil { if err != nil {
return err return err
} }