@@ -203,16 +203,7 @@ headerLoop:
203203 }
204204
205205 // 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 )
216207}
217208
218209// ReadTreeID reads a tree ID from a cat-file --batch stream, throwing away the rest of the stream.
@@ -238,16 +229,7 @@ headerLoop:
238229 }
239230
240231 // 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 )
251233}
252234
253235// git tree files are a list:
@@ -345,3 +327,21 @@ func init() {
345327 _ , filename , _ , _ := runtime .Caller (0 )
346328 callerPrefix = strings .TrimSuffix (filename , "modules/git/batch_reader.go" )
347329}
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