summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-03-19 16:09:03 +1100
committerJesse Duffield <jessedduffield@gmail.com>2023-03-19 16:35:57 +1100
commit60f902f026559b1501b34ea3cfbacaf1fff168bf (patch)
treecca09391436d59a10ba342d528b4a8a14a5ccf09
parent7ce3165afa6e71ea853e9cddba279971f61579c1 (diff)
rename patch manager to patch builder
-rw-r--r--pkg/commands/git.go8
-rw-r--r--pkg/commands/git_commands/patch.go26
-rw-r--r--pkg/commands/patch/patch_builder.go (renamed from pkg/commands/patch/patch_manager.go)49
-rw-r--r--pkg/gui/commits_panel.go4
-rw-r--r--pkg/gui/context_config.go6
-rw-r--r--pkg/gui/controllers/commits_files_controller.go30
-rw-r--r--pkg/gui/controllers/context_lines_controller.go2
-rw-r--r--pkg/gui/controllers/helpers/patch_building_helper.go2
-rw-r--r--pkg/gui/controllers/patch_building_controller.go6
-rw-r--r--pkg/gui/custom_patch_options_panel.go14
-rw-r--r--pkg/gui/list_context_config.go2
-rw-r--r--pkg/gui/modes.go2
-rw-r--r--pkg/gui/presentation/files.go6
-rw-r--r--pkg/gui/presentation/files_test.go6
-rw-r--r--pkg/gui/refresh.go4
15 files changed, 83 insertions, 84 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index 35cead260..caf03db75 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -117,14 +117,14 @@ func NewGitCommandAux(
workingTreeCommands := git_commands.NewWorkingTreeCommands(gitCommon, submoduleCommands, fileLoader)
rebaseCommands := git_commands.NewRebaseCommands(gitCommon, commitCommands, workingTreeCommands)
stashCommands := git_commands.NewStashCommands(gitCommon, fileLoader, workingTreeCommands)
- // TODO: have patch manager take workingTreeCommands in its entirety
- patchManager := patch.NewPatchManager(cmn.Log, workingTreeCommands.ApplyPatch,
+ // TODO: have patch builder take workingTreeCommands in its entirety
+ patchBuilder := patch.NewPatchBuilder(cmn.Log, workingTreeCommands.ApplyPatch,
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.
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)
branchLoader := git_commands.NewBranchLoader(cmn, branchCommands.GetRawBranches, branchCommands.CurrentBranchInfo, configCommands)
diff --git a/pkg/commands/git_commands/patch.go b/pkg/commands/git_commands/patch.go
index 643091f63..7511d1a5b 100644
--- a/pkg/commands/git_commands/patch.go
+++ b/pkg/commands/git_commands/patch.go
@@ -16,7 +16,7 @@ type PatchCommands struct {
status *StatusCommands
stash *StashCommands
- PatchManager *patch.PatchManager
+ PatchBuilder *patch.PatchBuilder
}
func NewPatchCommands(
@@ -25,7 +25,7 @@ func NewPatchCommands(
commit *CommitCommands,
status *StatusCommands,
stash *StashCommands,
- patchManager *patch.PatchManager,
+ patchBuilder *patch.PatchBuilder,
) *PatchCommands {
return &PatchCommands{
GitCommon: gitCommon,
@@ -33,7 +33,7 @@ func NewPatchCommands(
commit: commit,
status: status,
stash: stash,
- PatchManager: patchManager,
+ PatchBuilder: patchBuilder,
}
}
@@ -44,7 +44,7 @@ func (self *PatchCommands) DeletePatchesFromCommit(commits []*models.Commit, com
}
// apply each patch in reverse
- if err := self.PatchManager.ApplyPatches(true); err != nil {
+ if err := self.PatchBuilder.ApplyPatches(true); err != nil {
_ = self.rebase.AbortRebase()
return err
}
@@ -55,7 +55,7 @@ func (self *PatchCommands) DeletePatchesFromCommit(commits []*models.Commit, com
}
self.rebase.onSuccessfulContinue = func() error {
- self.PatchManager.Reset()
+ self.PatchBuilder.Reset()
return nil
}
@@ -70,7 +70,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
}
// 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
// the user a chance to resolve them
return err
@@ -82,7 +82,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
}
self.rebase.onSuccessfulContinue = func() error {
- self.PatchManager.Reset()
+ self.PatchBuilder.Reset()
return nil
}
@@ -117,7 +117,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
}
// apply each patch in reverse
- if err := self.PatchManager.ApplyPatches(true); err != nil {
+ if err := self.PatchBuilder.ApplyPatches(true); err != nil {
_ = self.rebase.AbortRebase()
return err
}
@@ -152,7 +152,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s
}
self.rebase.onSuccessfulContinue = func() error {
- self.PatchManager.Reset()
+ self.PatchBuilder.Reset()
return nil
}
@@ -173,7 +173,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId
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 {
_ = self.rebase.AbortRebase()
}
@@ -210,7 +210,7 @@ func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitId
}
}
- self.PatchManager.Reset()
+ self.PatchBuilder.Reset()
return nil
}
@@ -222,7 +222,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm
return err
}
- if err := self.PatchManager.ApplyPatches(true); err != nil {
+ if err := self.PatchBuilder.ApplyPatches(true); err != nil {
_ = self.rebase.AbortRebase()
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")
}
- self.PatchManager.Reset()
+ self.PatchBuilder.Reset()
return self.rebase.ContinueRebase()
}
diff --git a/pkg/commands/patch/patch_manager.go b/pkg/commands/patch/patch_builder.go
index 8e06dccd7..0053ccaa5 100644
--- a/pkg/commands/patch/patch_manager.go
+++ b/pkg/commands/patch/patch_builder.go
@@ -33,8 +33,8 @@ type (
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
-type PatchManager struct {
+// 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 PatchBuilder struct {
// To is the commit sha if we're dealing with files of a commit, or a stash ref for a stash
To string
From string
@@ -53,17 +53,16 @@ type PatchManager struct {
loadFileDiff loadFileDiffFunc
}
-// NewPatchManager returns a new PatchManager
-func NewPatchManager(log *logrus.Entry, applyPatch applyPatchFunc, loadFileDiff loadFileDiffFunc) *PatchManager {
- return &PatchManager{
+// NewPatchBuilder returns a new PatchBuilder
+func NewPatchBuilder(log *logrus.Entry, applyPatch applyPatchFunc, loadFileDiff loadFileDiffFunc) *PatchBuilder {
+ return &PatchBuilder{
Log: log,
applyPatch: applyPatch,
loadFileDiff: loadFileDiff,
}
}
-// NewPatchManager returns a new PatchManager
-func (p *PatchManager) Start(from, to string, reverse bool, canRebase bool) {
+func (p *PatchBuilder) Start(from, to string, reverse bool, canRebase bool) {
p.To = to
p.From = from
p.reverse = reverse
@@ -71,7 +70,7 @@ func (p *PatchManager) Start(from, to string, reverse bool, canRebase bool) {
p.fileInfoMap = map[string]*fileInfo{}
}
-func (p *PatchManager) addFileWhole(info *fileInfo) {
+func (p *PatchBuilder) addFileWhole(info *fileInfo) {
info.mode = WHOLE
lineCount := len(strings.Split(info.diff, "\n"))
// 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.includedLineIndices = nil
}
-func (p *PatchManager) AddFileWhole(filename string) error {
+func (p *PatchBuilder) AddFileWhole(filename string) error {
info, err := p.getFileInfo(filename)
if err != nil {
return err
@@ -98,7 +97,7 @@ func (p *PatchManager) AddFileWhole(filename string) error {
return nil
}
-func (p *PatchManager) RemoveFile(filename string) error {
+func (p *PatchBuilder) RemoveFile(filename string) error {
info, err := p.getFileInfo(filename)
if err != nil {
return err
@@ -117,7 +116,7 @@ func getIndicesForRange(first, last int) []int {
return indices
}
-func (p *PatchManager) getFileInfo(filename string) (*fileInfo, error) {
+func (p *PatchBuilder) getFileInfo(filename string) (*fileInfo, error) {
info, ok := p.fileInfoMap[filename]
if ok {
return info, nil
@@ -137,7 +136,7 @@ func (p *PatchManager) getFileInfo(filename string) (*fileInfo, error) {
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)
if err != nil {
return err
@@ -148,7 +147,7 @@ func (p *PatchManager) AddFileLineRange(filename string, firstLineIdx, lastLineI
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)
if err != nil {
return err
@@ -162,7 +161,7 @@ func (p *PatchManager) RemoveFileLineRange(filename string, firstLineIdx, lastLi
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)
if err != nil {
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
filenames := maps.Keys(p.fileInfoMap)
@@ -210,11 +209,11 @@ func (p *PatchManager) renderEachFilePatch(plain bool) []string {
return output
}
-func (p *PatchManager) RenderAggregatedPatch(plain bool) string {
+func (p *PatchBuilder) RenderAggregatedPatch(plain bool) string {
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 {
return UNSELECTED
}
@@ -227,7 +226,7 @@ func (p *PatchManager) GetFileStatus(filename string, parent string) PatchStatus
return info.mode
}
-func (p *PatchManager) GetFileIncLineIndices(filename string) ([]int, error) {
+func (p *PatchBuilder) GetFileIncLineIndices(filename string) ([]int, error) {
info, err := p.getFileInfo(filename)
if err != nil {
return nil, err
@@ -235,7 +234,7 @@ func (p *PatchManager) GetFileIncLineIndices(filename string) ([]int, error) {
return info.includedLineIndices, nil
}
-func (p *PatchManager) ApplyPatches(reverse bool) error {
+func (p *PatchBuilder) ApplyPatches(reverse bool) error {
patch := ""
applyFlags := []string{"index", "3way"}
@@ -255,16 +254,16 @@ func (p *PatchManager) ApplyPatches(reverse bool) error {
}
// clears the patch
-func (p *PatchManager) Reset() {
+func (p *PatchBuilder) Reset() {
p.To = ""
p.fileInfoMap = map[string]*fileInfo{}
}
-func (p *PatchManager) Active() bool {
+func (p *PatchBuilder) Active() bool {
return p.To != ""
}
-func (p *PatchManager) IsEmpty() bool {
+func (p *PatchBuilder) IsEmpty() bool {
for _, fileInfo := range p.fileInfoMap {
if fileInfo.mode == WHOLE || (fileInfo.mode == PART && len(fileInfo.includedLineIndices) > 0) {
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
-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
}
-func (p *PatchManager) AllFilesInPatch() []string {
+func (p *PatchBuilder) AllFilesInPatch() []string {
files := make([]string, 0, len(p.fileInfoMap))
for filename := range p.fileInfoMap {
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index b56b3af2b..8b8c74eec 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -51,8 +51,8 @@ func (gui *Gui) branchCommitsRenderToMain() error {
}
func (gui *Gui) secondaryPatchPanelUpdateOpts() *types.ViewUpdateOpts {
- if gui.git.Patch.PatchManager.Active() {
- patch := gui.git.Patch.PatchManager.RenderAggregatedPatch(false)
+ if gui.git.Patch.PatchBuilder.Active() {
+ patch := gui.git.Patch.PatchBuilder.RenderAggregatedPatch(false)
return &types.ViewUpdateOpts{
Task: types.NewRenderStringWithoutScrollTask(patch),
diff --git a/pkg/gui/context_config.go b/pkg/gui/context_config.go
index 063690ff5..b19824237 100644
--- a/pkg/gui/context_config.go
+++ b/pkg/gui/context_config.go
@@ -150,15 +150,15 @@ func (gui *Gui) contextTree() *context.ContextTree {
func(opts types.OnFocusLostOpts) error {
gui.Views.PatchBuilding.Wrap = true
- if gui.git.Patch.PatchManager.IsEmpty() {
- gui.git.Patch.PatchManager.Reset()
+ if gui.git.Patch.PatchBuilder.IsEmpty() {
+ gui.git.Patch.PatchBuilder.Reset()
}
return nil
},
func() []int {
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 {
gui.Log.Error(err)
return nil
diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go
index f11005cd4..a5c5e667d 100644
--- a/pkg/gui/controllers/commits_files_controller.go
+++ b/pkg/gui/controllers/commits_files_controller.go
@@ -157,8 +157,8 @@ func (self *CommitFilesController) edit(node *filetree.CommitFileNode) error {
func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) error {
toggle := func() error {
return self.c.WithWaitingStatus(self.c.Tr.LcUpdatingPatch, func() error {
- if !self.git.Patch.PatchManager.Active() {
- if err := self.startPatchManager(); err != nil {
+ if !self.git.Patch.PatchBuilder.Active() {
+ if err := self.startPatchBuilder(); err != nil {
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,
// otherwise we'll remove everything
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 {
if adding {
- return self.git.Patch.PatchManager.AddFileWhole(file.Name)
+ return self.git.Patch.PatchBuilder.AddFileWhole(file.Name)
} else {
- return self.git.Patch.PatchManager.RemoveFile(file.Name)
+ return self.git.Patch.PatchBuilder.RemoveFile(file.Name)
}
})
if err != nil {
return self.c.Error(err)
}
- if self.git.Patch.PatchManager.IsEmpty() {
- self.git.Patch.PatchManager.Reset()
+ if self.git.Patch.PatchBuilder.IsEmpty() {
+ self.git.Patch.PatchBuilder.Reset()
}
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{
Title: self.c.Tr.DiscardPatch,
Prompt: self.c.Tr.DiscardPatchConfirm,
HandleConfirm: func() error {
- self.git.Patch.PatchManager.Reset()
+ self.git.Patch.PatchBuilder.Reset()
return toggle()
},
})
@@ -207,7 +207,7 @@ func (self *CommitFilesController) toggleAllForPatch(_ *filetree.CommitFileNode)
return self.toggleForPatch(root)
}
-func (self *CommitFilesController) startPatchManager() error {
+func (self *CommitFilesController) startPatchBuilder() error {
commitFilesContext := self.context()
canRebase := commitFilesContext.GetCanRebase()
@@ -215,7 +215,7 @@ func (self *CommitFilesController) startPatchManager() error {
to := ref.RefName()
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
}
@@ -229,8 +229,8 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode
}
enterTheFile := func() error {
- if !self.git.Patch.PatchManager.Active() {
- if err := self.startPatchManager(); err != nil {
+ if !self.git.Patch.PatchBuilder.Active() {
+ if err := self.startPatchBuilder(); err != nil {
return err
}
}
@@ -238,12 +238,12 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode
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{
Title: self.c.Tr.DiscardPatch,
Prompt: self.c.Tr.DiscardPatchConfirm,
HandleConfirm: func() error {
- self.git.Patch.PatchManager.Reset()
+ self.git.Patch.PatchBuilder.Reset()
return enterTheFile()
},
})
diff --git a/pkg/gui/controllers/context_lines_controller.go b/pkg/gui/controllers/context_lines_controller.go
index c90bd9c9f..5a4fb291b 100644
--- a/pkg/gui/controllers/context_lines_controller.go
+++ b/pkg/gui/controllers/context_lines_controller.go
@@ -101,7 +101,7 @@ func (self *ContextLinesController) applyChange() 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)
}
diff --git a/pkg/gui/controllers/helpers/patch_building_helper.go b/pkg/gui/controllers/helpers/patch_building_helper.go
index 646a8f167..59de50b99 100644
--- a/pkg/gui/controllers/helpers/patch_building_helper.go
+++ b/pkg/gui/controllers/helpers/patch_building_helper.go
@@ -43,7 +43,7 @@ func (self *PatchBuildingHelper) Escape() error {
// kills the custom patch and returns us back to the commit files panel if needed
func (self *PatchBuildingHelper) Reset() error {
- self.git.Patch.PatchManager.Reset()
+ self.git.Patch.PatchBuilder.Reset()
if self.c.CurrentStaticContext().GetKind() != types.SIDE_CONTEXT {
if err := self.Escape(); err != nil {
diff --git a/pkg/gui/controllers/patch_building_controller.go b/pkg/gui/controllers/patch_building_controller.go
index b2d60b770..abbb4bdd1 100644
--- a/pkg/gui/controllers/patch_building_controller.go
+++ b/pkg/gui/controllers/patch_building_controller.go
@@ -106,7 +106,7 @@ func (self *PatchBuildingController) toggleSelection() error {
self.context().GetMutex().Lock()
defer self.context().GetMutex().Unlock()
- toggleFunc := self.git.Patch.PatchManager.AddFileLineRange
+ toggleFunc := self.git.Patch.PatchBuilder.AddFileLineRange
filename := self.contexts.CommitFiles.GetSelectedPath()
if filename == "" {
return nil
@@ -114,13 +114,13 @@ func (self *PatchBuildingController) toggleSelection() error {
state := self.context().GetState()
- includedLineIndices, err := self.git.Patch.PatchManager.GetFileIncLineIndices(filename)
+ includedLineIndices, err := self.git.Patch.PatchBuilder.GetFileIncLineIndices(filename)
if err != nil {
return err
}
currentLineIsStaged := lo.Contains(includedLineIndices, state.GetSelectedLineIdx())
if currentLineIsStaged {
- toggleFunc = self.git.Patch.PatchManager.RemoveFileLineRange
+ toggleFunc = self.git.Patch.PatchBuilder.RemoveFileLineRange
}
// add range of lines to those set for the file
diff --git a/pkg/gui/custom_patch_options_panel.go b/pkg/gui/custom_patch_options_panel.go
index 2dfcf4e1e..a25fc9580 100644
--- a/pkg/gui/custom_patch_options_panel.go
+++ b/pkg/gui/custom_patch_options_panel.go
@@ -8,7 +8,7 @@ import (
)
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)
}
@@ -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{
{
- 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,
Key: 'd',
},
@@ -51,7 +51,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
if gui.currentContext().GetKey() == gui.State.Contexts.LocalCommits.GetKey() {
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
menuItems = append(
menuItems[:1],
@@ -82,7 +82,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
func (gui *Gui) getPatchCommitIndex() int {
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
}
}
@@ -195,14 +195,14 @@ func (gui *Gui) handleApplyPatch(reverse bool) error {
action = "Apply patch in reverse"
}
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.Refresh(types.RefreshOptions{Mode: types.ASYNC})
}
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)
if err := gui.os.CopyToClipboard(patch); err != nil {
diff --git a/pkg/gui/list_context_config.go b/pkg/gui/list_context_config.go
index a6cc8c42b..7969c4d20 100644
--- a/pkg/gui/list_context_config.go
+++ b/pkg/gui/list_context_config.go
@@ -243,7 +243,7 @@ func (gui *Gui) commitFilesListContext() *context.CommitFilesContext {
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 []string{line}
})
diff --git a/pkg/gui/modes.go b/pkg/gui/modes.go
index 70d403db2..750d1ad92 100644
--- a/pkg/gui/modes.go
+++ b/pkg/gui/modes.go
@@ -30,7 +30,7 @@ func (gui *Gui) modeStatuses() []modeStatus {
reset: gui.exitDiffMode,
},
{
- isActive: gui.git.Patch.PatchManager.Active,
+ isActive: gui.git.Patch.PatchBuilder.Active,
description: func() string {
return gui.withResetButton(gui.c.Tr.LcBuildingPatch, style.FgYellow.SetBold())
},
diff --git a/pkg/gui/presentation/files.go b/pkg/gui/presentation/files.go
index a941314c7..5180264e3 100644
--- a/pkg/gui/presentation/files.go
+++ b/pkg/gui/presentation/files.go
@@ -40,7 +40,7 @@ func RenderFileTree(
func RenderCommitFileTree(
tree *filetree.CommitFileTreeViewModel,
diffName string,
- patchManager *patch.PatchManager,
+ patchBuilder *patch.PatchBuilder,
) []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.
@@ -49,11 +49,11 @@ func RenderCommitFileTree(
// based on the leaves of that subtree
var status patch.PatchStatus
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
} 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
} else {
diff --git a/pkg/gui/presentation/files_test.go b/pkg/gui/presentation/files_test.go
index 729d0d8cf..025def566 100644
--- a/pkg/gui/presentation/files_test.go
+++ b/pkg/gui/presentation/files_test.go
@@ -134,15 +134,15 @@ M file1
for _, path := range s.collapsedPaths {
viewModel.ToggleCollapsed(path)
}
- patchManager := patch.NewPatchManager(
+ patchBuilder := patch.NewPatchBuilder(
utils.NewDummyLog(),
func(patch string, flags ...string) error { return nil },
func(from string, to string, reverse bool, filename string, plain bool) (string, error) {
return "", nil
},
)
- patchManager.Start("from", "to", false, false)
- result := RenderCommitFileTree(viewModel, "", patchManager)
+ patchBuilder.Start("from", "to", false, false)
+ result := RenderCommitFileTree(viewModel, "", patchBuilder)
assert.EqualValues(t, s.expected, result)
})
}
diff --git a/pkg/gui/refresh.go b/pkg/gui/refresh.go
index 0c6315767..2926152ed 100644
--- a/pkg/gui/refresh.go
+++ b/pkg/gui/refresh.go
@@ -653,7 +653,7 @@ func (gui *Gui) refreshPatchBuildingPanel(opts types.OnFocusOpts) error {
selectedLineIdx = opts.ClickedViewLineIdx
}
- if !gui.git.Patch.PatchManager.Active() {
+ if !gui.git.Patch.PatchBuilder.Active() {
return gui.helpers.PatchBuilding.Escape()
}
@@ -672,7 +672,7 @@ func (gui *Gui) refreshPatchBuildingPanel(opts types.OnFocusOpts) error {
return err
}
- secondaryDiff := gui.git.Patch.PatchManager.RenderPatchForFile(path, false, false)
+ secondaryDiff := gui.git.Patch.PatchBuilder.RenderPatchForFile(path, false, false)
if err != nil {
return err
}