diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-08 23:58:41 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-08 23:58:41 +0200 |
commit | 3b1baea2dd9353f42b3a9d93f6bc92ecbe9f4f01 (patch) | |
tree | d255b7e6edbcbaba1f98cf0c666a82c0f9750019 /formats/idxfile/encoder.go | |
parent | 2293a3dbda0a96f5cbac851bb73e1e675417e4f3 (diff) | |
download | go-git-3b1baea2dd9353f42b3a9d93f6bc92ecbe9f4f01.tar.gz |
format: packfile based on ObjectStorage and CRC32 calculation
Diffstat (limited to 'formats/idxfile/encoder.go')
-rw-r--r-- | formats/idxfile/encoder.go | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/formats/idxfile/encoder.go b/formats/idxfile/encoder.go index 6a61137..e9b0338 100644 --- a/formats/idxfile/encoder.go +++ b/formats/idxfile/encoder.go @@ -65,25 +65,24 @@ func (e *Encoder) encodeFanout(idx *Idxfile) (int, error) { } func (e *Encoder) encodeHashes(idx *Idxfile) (int, error) { - return e.encodeEntryField(idx, true) -} + sz := 0 + for _, ent := range idx.Entries { + i, err := e.Write(ent.Hash[:]) + sz += i -func (e *Encoder) encodeCRC32(idx *Idxfile) (int, error) { - return e.encodeEntryField(idx, false) + if err != nil { + return sz, err + } + } + + return sz, nil } -func (e *Encoder) encodeEntryField(idx *Idxfile, isHash bool) (int, error) { +func (e *Encoder) encodeCRC32(idx *Idxfile) (int, error) { sz := 0 for _, ent := range idx.Entries { - var data []byte - if isHash { - data = ent.Hash[:] - } else { - data = ent.CRC32[:] - } - - i, err := e.Write(data) - sz += i + err := binary.Write(e, binary.BigEndian, ent.CRC32) + sz += 4 if err != nil { return sz, err |