MCPcopy Index your code
hub / github.com/harness/harness / Diff

Method Diff

git/diff.go:363–430  ·  view source on GitHub ↗

nolint:gocognit

(
	ctx context.Context,
	params *DiffParams,
	files ...api.FileDiffRequest,
)

Source from the content-addressed store, hash-verified

361
362//nolint:gocognit
363func (s *Service) Diff(
364 ctx context.Context,
365 params *DiffParams,
366 files ...api.FileDiffRequest,
367) (<-chan *FileDiff, <-chan error) {
368 wg := sync.WaitGroup{}
369 ch := make(chan *FileDiff)
370 cherr := make(chan error, 1)
371
372 pr, pw := io.Pipe()
373
374 wg.Add(1)
375 go func() {
376 defer wg.Done()
377 defer pw.Close()
378
379 if err := params.Validate(); err != nil {
380 cherr <- err
381 return
382 }
383
384 err := s.rawDiff(ctx, pw, params, files...)
385 if err != nil {
386 cherr <- err
387 return
388 }
389 }()
390
391 wg.Add(1)
392 go func() {
393 defer wg.Done()
394 defer pr.Close()
395
396 parser := diff.Parser{
397 Reader: bufio.NewReader(pr),
398 IncludePatch: params.IncludePatch,
399 }
400
401 err := parser.Parse(func(f *diff.File) error {
402 ch <- &FileDiff{
403 SHA: f.SHA,
404 OldSHA: f.OldSHA,
405 Path: f.Path,
406 OldPath: f.OldPath,
407 Status: parseFileDiffStatus(f.Type),
408 Additions: int64(f.NumAdditions()),
409 Deletions: int64(f.NumDeletions()),
410 Changes: int64(f.NumChanges()),
411 Patch: f.Patch.Bytes(),
412 IsBinary: f.IsBinary,
413 IsSubmodule: f.IsSubmodule,
414 }
415 return nil
416 })
417 if err != nil {
418 cherr <- err
419 return
420 }

Callers

nothing calls this directly

Calls 11

rawDiffMethod · 0.95
ParseMethod · 0.95
parseFileDiffStatusFunction · 0.85
NumAdditionsMethod · 0.80
NumDeletionsMethod · 0.80
NumChangesMethod · 0.80
WaitMethod · 0.80
CloseMethod · 0.65
ValidateMethod · 0.65
BytesMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected