@@ -73,7 +73,11 @@ func (p *PatchBuilder) PatchToApply(reverse bool) string {
7373 continue
7474 }
7575
76- patch += p .RenderPatchForFile (filename , true , reverse )
76+ patch += p .RenderPatchForFile (RenderPatchForFileOpts {
77+ Filename : filename ,
78+ Plain : true ,
79+ Reverse : reverse ,
80+ })
7781 }
7882
7983 return patch
@@ -172,8 +176,14 @@ func (p *PatchBuilder) RemoveFileLineRange(filename string, firstLineIdx, lastLi
172176 return nil
173177}
174178
175- func (p * PatchBuilder ) RenderPatchForFile (filename string , plain bool , reverse bool ) string {
176- info , err := p .getFileInfo (filename )
179+ type RenderPatchForFileOpts struct {
180+ Filename string
181+ Plain bool
182+ Reverse bool
183+ }
184+
185+ func (p * PatchBuilder ) RenderPatchForFile (opts RenderPatchForFileOpts ) string {
186+ info , err := p .getFileInfo (opts .Filename )
177187 if err != nil {
178188 p .Log .Error (err )
179189 return ""
@@ -183,7 +193,7 @@ func (p *PatchBuilder) RenderPatchForFile(filename string, plain bool, reverse b
183193 return ""
184194 }
185195
186- if info .mode == WHOLE && plain {
196+ if info .mode == WHOLE && opts . Plain {
187197 // Use the whole diff (spares us parsing it and then formatting it).
188198 // TODO: see if this is actually noticeably faster.
189199 // 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
192202
193203 patch := Parse (info .diff ).
194204 Transform (TransformOpts {
195- Reverse : reverse ,
205+ Reverse : opts . Reverse ,
196206 IncludedLineIndices : info .includedLineIndices ,
197207 })
198208
199- if plain {
209+ if opts . Plain {
200210 return patch .FormatPlain ()
201211 } else {
202212 return patch .FormatView (FormatViewOpts {})
@@ -209,7 +219,11 @@ func (p *PatchBuilder) renderEachFilePatch(plain bool) []string {
209219
210220 sort .Strings (filenames )
211221 patches := lo .Map (filenames , func (filename string , _ int ) string {
212- return p .RenderPatchForFile (filename , plain , false )
222+ return p .RenderPatchForFile (RenderPatchForFileOpts {
223+ Filename : filename ,
224+ Plain : plain ,
225+ Reverse : false ,
226+ })
213227 })
214228 output := lo .Filter (patches , func (patch string , _ int ) bool {
215229 return patch != ""
0 commit comments