MCPcopy Index your code
hub / github.com/go-git/go-git / getFileStatsFromFilePatches

Function getFileStatsFromFilePatches

plumbing/object/patch.go:289–337  ·  view source on GitHub ↗
(filePatches []fdiff.FilePatch)

Source from the content-addressed store, hash-verified

287}
288
289func getFileStatsFromFilePatches(filePatches []fdiff.FilePatch) FileStats {
290 var fileStats FileStats
291
292 for _, fp := range filePatches {
293 // ignore empty patches (binary files, submodule refs updates)
294 if len(fp.Chunks()) == 0 {
295 continue
296 }
297
298 cs := FileStat{}
299 from, to := fp.Files()
300 if from == nil {
301 // New File is created.
302 cs.Name = to.Path()
303 } else if to == nil {
304 // File is deleted.
305 cs.Name = from.Path()
306 } else if from.Path() != to.Path() {
307 // File is renamed.
308 cs.Name = fmt.Sprintf("%s => %s", from.Path(), to.Path())
309 } else {
310 cs.Name = from.Path()
311 }
312
313 for _, chunk := range fp.Chunks() {
314 s := chunk.Content()
315 if len(s) == 0 {
316 continue
317 }
318
319 switch chunk.Type() {
320 case fdiff.Add:
321 cs.Addition += strings.Count(s, "\n")
322 if s[len(s)-1] != '\n' {
323 cs.Addition++
324 }
325 case fdiff.Delete:
326 cs.Deletion += strings.Count(s, "\n")
327 if s[len(s)-1] != '\n' {
328 cs.Deletion++
329 }
330 }
331 }
332
333 fileStats = append(fileStats, cs)
334 }
335
336 return fileStats
337}

Callers 2

StatsMethod · 0.85
StatsContextMethod · 0.85

Calls 6

ChunksMethod · 0.65
FilesMethod · 0.65
PathMethod · 0.65
ContentMethod · 0.65
TypeMethod · 0.65
CountMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…