MCPcopy
hub / github.com/harness/harness / getCommitFileStats

Function getCommitFileStats

git/api/commit.go:238–280  ·  view source on GitHub ↗
(
	ctx context.Context,
	repoPath string,
	sha sha.SHA,
)

Source from the content-addressed store, hash-verified

236}
237
238func getCommitFileStats(
239 ctx context.Context,
240 repoPath string,
241 sha sha.SHA,
242) ([]CommitFileStats, error) {
243 g, ctx := errgroup.WithContext(ctx)
244 var changeInfoChanges map[string]changeInfoChange
245 var changeInfoTypes map[string]changeInfoType
246
247 g.Go(func() error {
248 var err error
249 changeInfoChanges, err = getChangeInfoChanges(ctx, repoPath, sha)
250 return err
251 })
252
253 g.Go(func() error {
254 var err error
255 changeInfoTypes, err = getChangeInfoTypes(ctx, repoPath, sha)
256 return err
257 })
258
259 if err := g.Wait(); err != nil {
260 return nil, fmt.Errorf("failed to get change infos: %w", err)
261 }
262
263 if len(changeInfoTypes) == 0 {
264 return []CommitFileStats{}, nil
265 }
266
267 fileStats := make([]CommitFileStats, len(changeInfoChanges))
268 i := 0
269 for path, info := range changeInfoChanges {
270 fileStats[i] = CommitFileStats{
271 Path: changeInfoTypes[path].Path,
272 OldPath: changeInfoTypes[path].OldPath,
273 ChangeType: changeInfoTypes[path].Status,
274 Insertions: info.Insertions,
275 Deletions: info.Deletions,
276 }
277 i++
278 }
279 return fileStats, nil
280}
281
282// In case of rename of a file, same commit will be listed twice - Once in old file and second time in new file.
283// Hence, we are making it a pattern to only list it as part of new file and not as part of old file.

Callers 1

ListCommitsMethod · 0.85

Calls 4

getChangeInfoChangesFunction · 0.85
getChangeInfoTypesFunction · 0.85
WaitMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…