@@ -221,21 +221,22 @@ func (p *Parser) indexObjects() error {
221221 ota = newBaseObject (oh .Offset , oh .Length , t )
222222 }
223223
224- size , crc , err := p .scanner .NextObject (buf )
224+ _ , crc , err := p .scanner .NextObject (buf )
225225 if err != nil {
226226 return err
227227 }
228228
229229 ota .Crc32 = crc
230- ota .PackSize = size
231230 ota .Length = oh .Length
232231
233232 data := buf .Bytes ()
234233 if ! delta {
235- if _ , err := ota .Write (data ); err != nil {
234+ sha1 , err := getSHA1 (ota .Type , data )
235+ if err != nil {
236236 return err
237237 }
238- ota .SHA1 = ota .Sum ()
238+
239+ ota .SHA1 = sha1
239240 p .oiByHash [ota .SHA1 ] = ota
240241 }
241242
@@ -291,18 +292,12 @@ func (p *Parser) resolveDeltas() error {
291292 delete (p .deltas , obj .Offset )
292293 }
293294 }
294-
295- obj .Content = nil
296295 }
297296
298297 return nil
299298}
300299
301300func (p * Parser ) get (o * objectInfo ) ([]byte , error ) {
302- if len (o .Content ) > 0 {
303- return o .Content , nil
304- }
305-
306301 b , ok := p .cache .Get (o .Offset )
307302 // If it's not on the cache and is not a delta we can try to find it in the
308303 // storage, if there's one.
@@ -406,8 +401,6 @@ func (p *Parser) readData(o *objectInfo) ([]byte, error) {
406401 return data , nil
407402 }
408403
409- // TODO: skip header. Header size can be calculated with the offset of the
410- // next offset in the first pass.
411404 if _ , err := p .scanner .SeekFromStart (o .Offset ); err != nil {
412405 return nil , err
413406 }
@@ -431,33 +424,37 @@ func applyPatchBase(ota *objectInfo, data, base []byte) ([]byte, error) {
431424 }
432425
433426 ota .Type = ota .Parent .Type
434- ota . Hasher = plumbing . NewHasher (ota .Type , int64 ( len ( patched )) )
435- if _ , err := ota . Write ( patched ); err != nil {
427+ sha1 , err := getSHA1 (ota .Type , patched )
428+ if err != nil {
436429 return nil , err
437430 }
438- ota .SHA1 = ota .Sum ()
431+
432+ ota .SHA1 = sha1
439433 ota .Length = int64 (len (patched ))
440434
441435 return patched , nil
442436}
443437
444- type objectInfo struct {
445- plumbing.Hasher
438+ func getSHA1 (t plumbing.ObjectType , data []byte ) (plumbing.Hash , error ) {
439+ hasher := plumbing .NewHasher (t , int64 (len (data )))
440+ if _ , err := hasher .Write (data ); err != nil {
441+ return plumbing .ZeroHash , err
442+ }
443+
444+ return hasher .Sum (), nil
445+ }
446446
447- Offset int64
448- Length int64
449- HeaderLength int64
450- PackSize int64
451- Type plumbing.ObjectType
452- DiskType plumbing.ObjectType
447+ type objectInfo struct {
448+ Offset int64
449+ Length int64
450+ Type plumbing.ObjectType
451+ DiskType plumbing.ObjectType
453452
454453 Crc32 uint32
455454
456455 Parent * objectInfo
457456 Children []* objectInfo
458457 SHA1 plumbing.Hash
459-
460- Content []byte
461458}
462459
463460func newBaseObject (offset , length int64 , t plumbing.ObjectType ) * objectInfo {
@@ -469,29 +466,18 @@ func newDeltaObject(
469466 t plumbing.ObjectType ,
470467 parent * objectInfo ,
471468) * objectInfo {
472- children := make ([]* objectInfo , 0 )
473-
474469 obj := & objectInfo {
475- Hasher : plumbing .NewHasher (t , length ),
476470 Offset : offset ,
477471 Length : length ,
478- PackSize : 0 ,
479472 Type : t ,
480473 DiskType : t ,
481474 Crc32 : 0 ,
482475 Parent : parent ,
483- Children : children ,
484476 }
485477
486478 return obj
487479}
488480
489- func (o * objectInfo ) Write (b []byte ) (int , error ) {
490- o .Content = make ([]byte , len (b ))
491- copy (o .Content , b )
492- return o .Hasher .Write (b )
493- }
494-
495481func (o * objectInfo ) IsDelta () bool {
496482 return o .Type .IsDelta ()
497483}
0 commit comments