MCPcopy
hub / github.com/jesseduffield/lazygit / RenderPatchForFile

Method RenderPatchForFile

pkg/commands/patch/patch_builder.go:179–208  ·  view source on GitHub ↗
(opts RenderPatchForFileOpts)

Source from the content-addressed store, hash-verified

177}
178
179func (p *PatchBuilder) RenderPatchForFile(opts RenderPatchForFileOpts) string {
180 info, err := p.getFileInfo(opts.Filename)
181 if err != nil {
182 p.Log.Error(err)
183 return ""
184 }
185
186 if info.mode == UNSELECTED {
187 return ""
188 }
189
190 if info.mode == WHOLE && opts.Plain {
191 // Use the whole diff (spares us parsing it and then formatting it).
192 // TODO: see if this is actually noticeably faster.
193 // The reverse flag is only for part patches so we're ignoring it here.
194 return info.diff
195 }
196
197 patch := Parse(info.diff).
198 Transform(TransformOpts{
199 Reverse: opts.Reverse,
200 TurnAddedFilesIntoDiffAgainstEmptyFile: opts.TurnAddedFilesIntoDiffAgainstEmptyFile,
201 IncludedLineIndices: info.includedLineIndices,
202 })
203
204 if opts.Plain {
205 return patch.FormatPlain()
206 }
207 return patch.FormatView(FormatViewOpts{})
208}
209
210func (p *PatchBuilder) renderEachFilePatch(plain bool) []string {
211 // sort files by name then iterate through and render each patch

Callers 3

PatchToApplyMethod · 0.95
renderEachFilePatchMethod · 0.95

Calls 6

getFileInfoMethod · 0.95
ParseFunction · 0.85
TransformMethod · 0.80
FormatPlainMethod · 0.80
FormatViewMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected