@@ -212,63 +212,6 @@ func To40ByteSHA(sha, out []byte) []byte {
212
212
return out
213
213
}
214
214
215
- // ParseTreeLineSkipMode reads an entry from a tree in a cat-file --batch stream
216
- // This simply skips the mode - saving a substantial amount of time and carefully avoids allocations - except where fnameBuf is too small.
217
- // It is recommended therefore to pass in an fnameBuf large enough to avoid almost all allocations
218
- //
219
- // Each line is composed of:
220
- // <mode-in-ascii-dropping-initial-zeros> SP <fname> NUL <20-byte SHA>
221
- //
222
- // We don't attempt to convert the 20-byte SHA to 40-byte SHA to save a lot of time
223
- func ParseTreeLineSkipMode (rd * bufio.Reader , fnameBuf , shaBuf []byte ) (fname , sha []byte , n int , err error ) {
224
- var readBytes []byte
225
- // Skip the Mode
226
- readBytes , err = rd .ReadSlice ('\x00' ) // NB: DOES NOT ALLOCATE SIMPLY RETURNS SLICE WITHIN READER BUFFER
227
- if err != nil {
228
- return
229
- }
230
- idx := bytes .IndexByte (readBytes , ' ' )
231
- if idx < 0 {
232
- log ("missing space in readBytes: %s" , readBytes )
233
- err = & ErrNotExist {}
234
- return
235
- }
236
- n += idx + 1
237
- readBytes = readBytes [idx + 1 :]
238
-
239
- // Deal with the fname
240
- copy (fnameBuf , readBytes )
241
- if len (fnameBuf ) > len (readBytes ) {
242
- fnameBuf = fnameBuf [:len (readBytes )] // cut the buf the correct size
243
- } else {
244
- fnameBuf = append (fnameBuf , readBytes [len (fnameBuf ):]... ) // extend the buf and copy in the missing bits
245
- }
246
- for err == bufio .ErrBufferFull { // Then we need to read more
247
- readBytes , err = rd .ReadSlice ('\x00' )
248
- fnameBuf = append (fnameBuf , readBytes ... ) // there is little point attempting to avoid allocations here so just extend
249
- }
250
- n += len (fnameBuf )
251
- if err != nil {
252
- return
253
- }
254
- fnameBuf = fnameBuf [:len (fnameBuf )- 1 ] // Drop the terminal NUL
255
- fname = fnameBuf // set the returnable fname to the slice
256
-
257
- // Now deal with the 20-byte SHA
258
- idx = 0
259
- for idx < 20 {
260
- read := 0
261
- read , err = rd .Read (shaBuf [idx :20 ])
262
- n += read
263
- if err != nil {
264
- return
265
- }
266
- idx += read
267
- }
268
- sha = shaBuf
269
- return
270
- }
271
-
272
215
// ParseTreeLine reads an entry from a tree in a cat-file --batch stream
273
216
// This carefully avoids allocations - except where fnameBuf is too small.
274
217
// It is recommended therefore to pass in an fnameBuf large enough to avoid almost all allocations
0 commit comments