MCPcopy
hub / github.com/harness/harness / diffCutFromHunk

Method diffCutFromHunk

git/api/diff.go:518–566  ·  view source on GitHub ↗
(
	ctx context.Context,
	repoPath string,
	oldSHA string,
	newSHA string,
	ignoreWhitespace bool,
	params parser.DiffCutParams,
)

Source from the content-addressed store, hash-verified

516}
517
518func (g *Git) diffCutFromHunk(
519 ctx context.Context,
520 repoPath string,
521 oldSHA string,
522 newSHA string,
523 ignoreWhitespace bool,
524 params parser.DiffCutParams,
525) (parser.HunkHeader, parser.Hunk, error) {
526 pipeRead, pipeWrite := io.Pipe()
527 stderr := bytes.NewBuffer(nil)
528 go func() {
529 var err error
530
531 defer func() {
532 // If running of the command below fails, make the pipe reader also fail with the same error.
533 _ = pipeWrite.CloseWithError(err)
534 }()
535
536 cmd := command.New("diff",
537 command.WithFlag("--patch"),
538 command.WithFlag("--full-index"),
539 command.WithFlag("--no-color"),
540 command.WithFlag("--unified=100000000"),
541 command.WithArg(oldSHA),
542 command.WithArg(newSHA))
543
544 if ignoreWhitespace {
545 // Ignore whitespace when comparing lines.
546 cmd.Add(command.WithFlag("-w"))
547 }
548
549 err = cmd.Run(ctx,
550 command.WithDir(repoPath),
551 command.WithStdout(pipeWrite),
552 command.WithStderr(stderr))
553 }()
554
555 diffCutHeader, linesHunk, err := parser.DiffCut(pipeRead, params)
556 if errStderr := parseDiffStderr(stderr); errStderr != nil {
557 // First check if there's something in the stderr buffer, if yes that's the error
558 return parser.HunkHeader{}, parser.Hunk{}, errStderr
559 }
560 if err != nil {
561 // Next check if reading the git diff output caused an error
562 return parser.HunkHeader{}, parser.Hunk{}, err
563 }
564
565 return diffCutHeader, linesHunk, nil
566}
567
568func (g *Git) diffCutFromBlob(
569 ctx context.Context,

Callers 1

DiffCutMethod · 0.95

Calls 12

NewFunction · 0.92
WithFlagFunction · 0.92
WithArgFunction · 0.92
WithDirFunction · 0.92
WithStdoutFunction · 0.92
WithStderrFunction · 0.92
DiffCutFunction · 0.92
parseDiffStderrFunction · 0.85
NewBufferMethod · 0.80
CloseWithErrorMethod · 0.80
RunMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected