DiffCut extracts diff snippet from a git diff hunk. The snippet is from the diff between the specified commit SHAs.
(ctx context.Context, params *DiffCutParams)
| 282 | // DiffCut extracts diff snippet from a git diff hunk. |
| 283 | // The snippet is from the diff between the specified commit SHAs. |
| 284 | func (s *Service) DiffCut(ctx context.Context, params *DiffCutParams) (DiffCutOutput, error) { |
| 285 | if params.SourceCommitSHA == params.TargetCommitSHA { |
| 286 | return DiffCutOutput{}, errors.InvalidArgument("source and target SHA cannot be the same") |
| 287 | } |
| 288 | |
| 289 | repoPath := getFullPathForRepo(s.reposRoot, params.RepoUID) |
| 290 | |
| 291 | mergeBaseSHA, _, err := s.git.GetMergeBase(ctx, repoPath, "", params.TargetCommitSHA, params.SourceCommitSHA) |
| 292 | if err != nil { |
| 293 | return DiffCutOutput{}, fmt.Errorf("failed to find merge base: %w", err) |
| 294 | } |
| 295 | |
| 296 | header, linesHunk, err := s.git.DiffCut( |
| 297 | ctx, |
| 298 | repoPath, |
| 299 | params.TargetCommitSHA, |
| 300 | params.SourceCommitSHA, |
| 301 | params.Path, |
| 302 | params.IgnoreWhitespace, |
| 303 | parser.DiffCutParams{ |
| 304 | LineStart: params.LineStart, |
| 305 | LineStartNew: params.LineStartNew, |
| 306 | LineEnd: params.LineEnd, |
| 307 | LineEndNew: params.LineEndNew, |
| 308 | BeforeLines: 2, |
| 309 | AfterLines: 2, |
| 310 | LineLimit: params.LineLimit, |
| 311 | }, |
| 312 | ) |
| 313 | if err != nil { |
| 314 | return DiffCutOutput{}, fmt.Errorf("DiffCut: failed to get diff hunk: %w", err) |
| 315 | } |
| 316 | |
| 317 | hunkHeader := HunkHeader{ |
| 318 | OldLine: header.OldLine, |
| 319 | OldSpan: header.OldSpan, |
| 320 | NewLine: header.NewLine, |
| 321 | NewSpan: header.NewSpan, |
| 322 | Text: header.Text, |
| 323 | } |
| 324 | |
| 325 | return DiffCutOutput{ |
| 326 | Header: hunkHeader, |
| 327 | LinesHeader: linesHunk.HunkHeader.String(), |
| 328 | Lines: linesHunk.Lines, |
| 329 | MergeBaseSHA: mergeBaseSHA, |
| 330 | }, nil |
| 331 | } |
| 332 | |
| 333 | type FileDiff struct { |
| 334 | SHA string `json:"sha"` |
nothing calls this directly
no test coverage detected