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

Function parseDiffStat

git/api/diff.go:703–734  ·  view source on GitHub ↗
(stdout string)

Source from the content-addressed store, hash-verified

701 `\s*(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?`)
702
703func parseDiffStat(stdout string) (stat DiffShortStat, err error) {
704 if len(stdout) == 0 || stdout == "\n" {
705 return DiffShortStat{}, nil
706 }
707 groups := shortStatFormat.FindStringSubmatch(stdout)
708 if len(groups) != 4 {
709 return DiffShortStat{}, fmt.Errorf("unable to parse shortstat: %s groups: %s", stdout, groups)
710 }
711
712 stat.Files, err = strconv.Atoi(groups[1])
713 if err != nil {
714 return DiffShortStat{}, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumFiles %w",
715 stdout, err)
716 }
717
718 if len(groups[2]) != 0 {
719 stat.Additions, err = strconv.Atoi(groups[2])
720 if err != nil {
721 return DiffShortStat{}, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumAdditions %w",
722 stdout, err)
723 }
724 }
725
726 if len(groups[3]) != 0 {
727 stat.Deletions, err = strconv.Atoi(groups[3])
728 if err != nil {
729 return DiffShortStat{}, fmt.Errorf("unable to parse shortstat: %s. Error parsing NumDeletions %w",
730 stdout, err)
731 }
732 }
733 return stat, nil
734}
735
736func parseDiffStderr(stderr *bytes.Buffer) error {
737 errRaw := stderr.String() // assume there will never be a lot of output to stdout

Callers 1

GetDiffShortStatFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…