summaryrefslogtreecommitdiffstats
path: root/pkg/commands
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 /pkg/commands
parent7ce3165afa6e71ea853e9cddba279971f61579c1 (diff)
rename patch manager to patch builder
Diffstat (limited to 'pkg/commands')
-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
3 files changed, 41 insertions, 42 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 {