diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-06-21 19:52:49 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-06-23 12:40:31 +0200 |
commit | 13a35408e6f27e08a40813adbba83183e8ea6599 (patch) | |
tree | a7c6d2a95222990f321304d4f5abe6b86897b9e3 /pkg | |
parent | 1a76a7da094c346ee47cba6c3acfbd0ed6f60484 (diff) |
Introduce options struct for RenderPatchForFile
We're going to add another argument in the next commit, and that's getting a bit
much, especially when most of the arguments are bool and you only see true and
false at the call sites without knowing what they mean.
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/patch/patch_builder.go | 28 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/patch_building_helper.go | 7 |
2 files changed, 27 insertions, 8 deletions
diff --git a/pkg/commands/patch/patch_builder.go b/pkg/commands/patch/patch_builder.go index a1e2f5194..e18c7d1bb 100644 --- a/pkg/commands/patch/patch_builder.go +++ b/pkg/commands/patch/patch_builder.go @@ -73,7 +73,11 @@ func (p *PatchBuilder) PatchToApply(reverse bool) string { continue } - patch += p.RenderPatchForFile(filename, true, reverse) + patch += p.RenderPatchForFile(RenderPatchForFileOpts{ + Filename: filename, + Plain: true, + Reverse: reverse, + }) } return patch @@ -172,8 +176,14 @@ func (p *PatchBuilder) RemoveFileLineRange(filename string, firstLineIdx, lastLi return nil } -func (p *PatchBuilder) RenderPatchForFile(filename string, plain bool, reverse bool) string { - info, err := p.getFileInfo(filename) +type RenderPatchForFileOpts struct { + Filename string + Plain bool + Reverse bool +} + +func (p *PatchBuilder) RenderPatchForFile(opts RenderPatchForFileOpts) string { + info, err := p.getFileInfo(opts.Filename) if err != nil { p.Log.Error(err) return "" @@ -183,7 +193,7 @@ func (p *PatchBuilder) RenderPatchForFile(filename string, plain bool, reverse b return "" } - if info.mode == WHOLE && plain { + if info.mode == WHOLE && opts.Plain { // Use the whole diff (spares us parsing it and then formatting it). // TODO: see if this is actually noticeably faster. // The reverse flag is only for part patches so we're ignoring it here. @@ -192,11 +202,11 @@ func (p *PatchBuilder) RenderPatchForFile(filename string, plain bool, reverse b patch := Parse(info.diff). Transform(TransformOpts{ - Reverse: reverse, + Reverse: opts.Reverse, IncludedLineIndices: info.includedLineIndices, }) - if plain { + if opts.Plain { return patch.FormatPlain() } else { return patch.FormatView(FormatViewOpts{}) @@ -209,7 +219,11 @@ func (p *PatchBuilder) renderEachFilePatch(plain bool) []string { sort.Strings(filenames) patches := lo.Map(filenames, func(filename string, _ int) string { - return p.RenderPatchForFile(filename, plain, false) + return p.RenderPatchForFile(RenderPatchForFileOpts{ + Filename: filename, + Plain: plain, + Reverse: false, + }) }) output := lo.Filter(patches, func(patch string, _ int) bool { return patch != "" diff --git a/pkg/gui/controllers/helpers/patch_building_helper.go b/pkg/gui/controllers/helpers/patch_building_helper.go index d8f83255d..423c9f814 100644 --- a/pkg/gui/controllers/helpers/patch_building_helper.go +++ b/pkg/gui/controllers/helpers/patch_building_helper.go @@ -3,6 +3,7 @@ package helpers import ( "errors" + "github.com/jesseduffield/lazygit/pkg/commands/patch" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/gui/patch_exploring" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -80,7 +81,11 @@ func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpt return err } - secondaryDiff := self.c.Git().Patch.PatchBuilder.RenderPatchForFile(path, false, false) + secondaryDiff := self.c.Git().Patch.PatchBuilder.RenderPatchForFile(patch.RenderPatchForFileOpts{ + Filename: path, + Plain: false, + Reverse: false, + }) context := self.c.Contexts().CustomPatchBuilder |