@@ -203,16 +203,7 @@ headerLoop:
203
203
}
204
204
205
205
// Discard the rest of the tag
206
- discard := size - n + 1
207
- for discard > math .MaxInt32 {
208
- _ , err := rd .Discard (math .MaxInt32 )
209
- if err != nil {
210
- return id , err
211
- }
212
- discard -= math .MaxInt32
213
- }
214
- _ , err := rd .Discard (int (discard ))
215
- return id , err
206
+ return id , DiscardFull (rd , size - n + 1 )
216
207
}
217
208
218
209
// ReadTreeID reads a tree ID from a cat-file --batch stream, throwing away the rest of the stream.
@@ -238,16 +229,7 @@ headerLoop:
238
229
}
239
230
240
231
// Discard the rest of the commit
241
- discard := size - n + 1
242
- for discard > math .MaxInt32 {
243
- _ , err := rd .Discard (math .MaxInt32 )
244
- if err != nil {
245
- return id , err
246
- }
247
- discard -= math .MaxInt32
248
- }
249
- _ , err := rd .Discard (int (discard ))
250
- return id , err
232
+ return id , DiscardFull (rd , size - n + 1 )
251
233
}
252
234
253
235
// git tree files are a list:
@@ -345,3 +327,21 @@ func init() {
345
327
_ , filename , _ , _ := runtime .Caller (0 )
346
328
callerPrefix = strings .TrimSuffix (filename , "modules/git/batch_reader.go" )
347
329
}
330
+
331
+ func DiscardFull (rd * bufio.Reader , discard int64 ) error {
332
+ if discard > math .MaxInt32 {
333
+ n , err := rd .Discard (math .MaxInt32 )
334
+ discard -= int64 (n )
335
+ if err != nil {
336
+ return err
337
+ }
338
+ }
339
+ for discard > 0 {
340
+ n , err := rd .Discard (int (discard ))
341
+ discard -= int64 (n )
342
+ if err != nil {
343
+ return err
344
+ }
345
+ }
346
+ return nil
347
+ }
0 commit comments