MCPcopy Create free account
hub / github.com/LegacyCodeHQ/clarity-cli / countLinesInFile

Function countLinesInFile

vcs/git/git_stats.go:469–503  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

467}
468
469func countLinesInFile(path string) (int, error) {
470 file, err := os.Open(path)
471 if err != nil {
472 return 0, err
473 }
474 defer file.Close()
475
476 buf := make([]byte, 32*1024)
477 lineCount := 0
478 hasContent := false
479 var lastByte byte
480
481 for {
482 n, err := file.Read(buf)
483 if n > 0 {
484 hasContent = true
485 lastByte = buf[n-1]
486 lineCount += bytes.Count(buf[:n], []byte{'\n'})
487 }
488 if err == io.EOF {
489 break
490 }
491 if err != nil {
492 return 0, err
493 }
494 }
495
496 if !hasContent {
497 return 0, nil
498 }
499 if lastByte != '\n' {
500 lineCount++
501 }
502 return lineCount, nil
503}
504
505func countLinesInFilesParallel(paths []string) map[string]int {
506 if len(paths) == 0 {

Callers 2

GetUncommittedFileDiffsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected