MCPcopy
hub / github.com/harness/harness / readLinePrefix

Function readLinePrefix

git/parser/diff_headers.go:101–125  ·  view source on GitHub ↗

readLinePrefix will consume the entire line from the reader, but will return only the first maxLen bytes from it - the rest is discarded. Returns io.EOF when the end of the input has been reached.

(br *bufio.Reader, maxLen int)

Source from the content-addressed store, hash-verified

99// but will return only the first maxLen bytes from it - the rest is discarded.
100// Returns io.EOF when the end of the input has been reached.
101func readLinePrefix(br *bufio.Reader, maxLen int) (line string, err error) {
102 for {
103 var raw []byte
104 var isPrefix bool
105
106 raw, isPrefix, err = br.ReadLine()
107 if err != nil && err != io.EOF { //nolint:errorlint
108 return "", err
109 }
110
111 if needMore := maxLen - len(line); needMore > 0 {
112 if len(raw) > needMore {
113 line += string(raw[:needMore])
114 } else {
115 line += string(raw)
116 }
117 }
118
119 if !isPrefix || len(raw) == 0 {
120 break
121 }
122 }
123
124 return line, err
125}

Callers 2

TestReadLinePrefixFunction · 0.85
GetHunkHeadersFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestReadLinePrefixFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…