aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format/idxfile
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/format/idxfile')
-rw-r--r--plumbing/format/idxfile/decoder_test.go3
-rw-r--r--plumbing/format/idxfile/encoder_test.go4
-rw-r--r--plumbing/format/idxfile/writer.go29
-rw-r--r--plumbing/format/idxfile/writer_test.go6
4 files changed, 24 insertions, 18 deletions
diff --git a/plumbing/format/idxfile/decoder_test.go b/plumbing/format/idxfile/decoder_test.go
index 94059cc..2c4a801 100644
--- a/plumbing/format/idxfile/decoder_test.go
+++ b/plumbing/format/idxfile/decoder_test.go
@@ -5,7 +5,6 @@ import (
"encoding/base64"
"fmt"
"io"
- "io/ioutil"
"testing"
"github.com/go-git/go-git/v5/plumbing"
@@ -119,7 +118,7 @@ ch2xUA==
func BenchmarkDecode(b *testing.B) {
f := fixtures.Basic().One()
- fixture, err := ioutil.ReadAll(f.Idx())
+ fixture, err := io.ReadAll(f.Idx())
if err != nil {
b.Errorf("unexpected error reading idx file: %s", err)
}
diff --git a/plumbing/format/idxfile/encoder_test.go b/plumbing/format/idxfile/encoder_test.go
index 32b60f9..b8ece83 100644
--- a/plumbing/format/idxfile/encoder_test.go
+++ b/plumbing/format/idxfile/encoder_test.go
@@ -2,7 +2,7 @@ package idxfile_test
import (
"bytes"
- "io/ioutil"
+ "io"
. "github.com/go-git/go-git/v5/plumbing/format/idxfile"
@@ -12,7 +12,7 @@ import (
func (s *IdxfileSuite) TestDecodeEncode(c *C) {
fixtures.ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
- expected, err := ioutil.ReadAll(f.Idx())
+ expected, err := io.ReadAll(f.Idx())
c.Assert(err, IsNil)
idx := new(MemoryIndex)
diff --git a/plumbing/format/idxfile/writer.go b/plumbing/format/idxfile/writer.go
index daa1605..c4c21e1 100644
--- a/plumbing/format/idxfile/writer.go
+++ b/plumbing/format/idxfile/writer.go
@@ -84,11 +84,8 @@ func (w *Writer) OnFooter(h plumbing.Hash) error {
w.checksum = h
w.finished = true
_, err := w.createIndex()
- if err != nil {
- return err
- }
- return nil
+ return err
}
// creatIndex returns a filled MemoryIndex with the information filled by
@@ -139,15 +136,23 @@ func (w *Writer) createIndex() (*MemoryIndex, error) {
offset := o.Offset
if offset > math.MaxInt32 {
- offset = w.addOffset64(offset)
+ var err error
+ offset, err = w.addOffset64(offset)
+ if err != nil {
+ return nil, err
+ }
}
buf.Truncate(0)
- binary.WriteUint32(buf, uint32(offset))
+ if err := binary.WriteUint32(buf, uint32(offset)); err != nil {
+ return nil, err
+ }
idx.Offset32[bucket] = append(idx.Offset32[bucket], buf.Bytes()...)
buf.Truncate(0)
- binary.WriteUint32(buf, o.CRC32)
+ if err := binary.WriteUint32(buf, o.CRC32); err != nil {
+ return nil, err
+ }
idx.CRC32[bucket] = append(idx.CRC32[bucket], buf.Bytes()...)
}
@@ -161,15 +166,17 @@ func (w *Writer) createIndex() (*MemoryIndex, error) {
return idx, nil
}
-func (w *Writer) addOffset64(pos uint64) uint64 {
+func (w *Writer) addOffset64(pos uint64) (uint64, error) {
buf := new(bytes.Buffer)
- binary.WriteUint64(buf, pos)
- w.index.Offset64 = append(w.index.Offset64, buf.Bytes()...)
+ if err := binary.WriteUint64(buf, pos); err != nil {
+ return 0, err
+ }
+ w.index.Offset64 = append(w.index.Offset64, buf.Bytes()...)
index := uint64(w.offset64 | (1 << 31))
w.offset64++
- return index
+ return index, nil
}
func (o objects) Len() int {
diff --git a/plumbing/format/idxfile/writer_test.go b/plumbing/format/idxfile/writer_test.go
index fba3e42..eaa8605 100644
--- a/plumbing/format/idxfile/writer_test.go
+++ b/plumbing/format/idxfile/writer_test.go
@@ -3,7 +3,7 @@ package idxfile_test
import (
"bytes"
"encoding/base64"
- "io/ioutil"
+ "io"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/idxfile"
@@ -34,7 +34,7 @@ func (s *WriterSuite) TestWriter(c *C) {
c.Assert(err, IsNil)
idxFile := f.Idx()
- expected, err := ioutil.ReadAll(idxFile)
+ expected, err := io.ReadAll(idxFile)
c.Assert(err, IsNil)
idxFile.Close()
@@ -65,7 +65,7 @@ func (s *WriterSuite) TestWriterLarge(c *C) {
// load fixture index
f := bytes.NewBufferString(fixtureLarge4GB)
- expected, err := ioutil.ReadAll(base64.NewDecoder(base64.StdEncoding, f))
+ expected, err := io.ReadAll(base64.NewDecoder(base64.StdEncoding, f))
c.Assert(err, IsNil)
buf := new(bytes.Buffer)