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