mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 21:05:48 +02:00
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.
This commit is contained in:
parent
1a76a7da09
commit
13a35408e6
2 changed files with 27 additions and 8 deletions
|
@ -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 != ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue