(opts RenderPatchForFileOpts)
| 177 | } |
| 178 | |
| 179 | func (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 | |
| 210 | func (p *PatchBuilder) renderEachFilePatch(plain bool) []string { |
| 211 | // sort files by name then iterate through and render each patch |
no test coverage detected