MCPcopy
hub / github.com/harness/harness / GetDiffShortStat

Function GetDiffShortStat

git/api/diff.go:668–698  ·  view source on GitHub ↗

GetDiffShortStat counts number of changed files, number of additions and deletions.

(
	ctx context.Context,
	repoPath string,
	ignoreWhitespace bool,
	args ...string,
)

Source from the content-addressed store, hash-verified

666
667// GetDiffShortStat counts number of changed files, number of additions and deletions.
668func GetDiffShortStat(
669 ctx context.Context,
670 repoPath string,
671 ignoreWhitespace bool,
672 args ...string,
673) (DiffShortStat, error) {
674 // Now if we call:
675 // $ git diff --shortstat 1ebb35b98889ff77299f24d82da426b434b0cca0...788b8b1440462d477f45b0088875
676 // we get:
677 // " 9902 files changed, 2034198 insertions(+), 298800 deletions(-)\n"
678
679 cmd := command.New("diff",
680 command.WithFlag("--shortstat"),
681 command.WithArg(args...),
682 )
683
684 if ignoreWhitespace {
685 // Ignore whitespace when comparing lines.
686 cmd.Add(command.WithFlag("-w"))
687 }
688
689 stdout := &bytes.Buffer{}
690 if err := cmd.Run(ctx,
691 command.WithDir(repoPath),
692 command.WithStdout(stdout),
693 ); err != nil {
694 return DiffShortStat{}, err
695 }
696
697 return parseDiffStat(stdout.String())
698}
699
700var shortStatFormat = regexp.MustCompile(
701 `\s*(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?`)

Callers 1

DiffShortStatMethod · 0.85

Calls 9

NewFunction · 0.92
WithFlagFunction · 0.92
WithArgFunction · 0.92
WithDirFunction · 0.92
WithStdoutFunction · 0.92
parseDiffStatFunction · 0.85
RunMethod · 0.65
AddMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…