MCPcopy Create free account
hub / github.com/harness/harness / DiffCut

Method DiffCut

git/diff.go:284–331  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

282// DiffCut extracts diff snippet from a git diff hunk.
283// The snippet is from the diff between the specified commit SHAs.
284func (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
333type FileDiff struct {
334 SHA string `json:"sha"`

Callers

nothing calls this directly

Calls 6

InvalidArgumentFunction · 0.92
getFullPathForRepoFunction · 0.85
GetMergeBaseMethod · 0.80
DiffCutMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected