diff options
author | Alberto Cortés <alcortesm@gmail.com> | 2016-11-14 18:27:31 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-11-14 18:27:31 +0100 |
commit | eb89d2dd9a36440d58aea224c055b364e49785f7 (patch) | |
tree | 79aac22df69ef70827ed24fa4fb3fb9bbc4d260b /plumbing/format/packfile | |
parent | 3e7f535beae601d334186f7316af957bc24bd865 (diff) | |
download | go-git-eb89d2dd9a36440d58aea224c055b364e49785f7.tar.gz |
Fix nil tx bug (#124)v4.0.0-rc4
* add test for non-seekable packfiles
* packfile: do not throw away the newly created transactioner
Diffstat (limited to 'plumbing/format/packfile')
-rw-r--r-- | plumbing/format/packfile/decoder.go | 6 | ||||
-rw-r--r-- | plumbing/format/packfile/decoder_test.go | 28 |
2 files changed, 31 insertions, 3 deletions
diff --git a/plumbing/format/packfile/decoder.go b/plumbing/format/packfile/decoder.go index 470e59b..5c103a0 100644 --- a/plumbing/format/packfile/decoder.go +++ b/plumbing/format/packfile/decoder.go @@ -121,7 +121,7 @@ func (d *Decoder) readObjectsWithObjectStorer(count int) error { } func (d *Decoder) readObjectsWithObjectStorerTx(count int) error { - tx := d.o.(storer.Transactioner).Begin() + d.tx = d.o.(storer.Transactioner).Begin() for i := 0; i < count; i++ { obj, err := d.ReadObject() @@ -129,7 +129,7 @@ func (d *Decoder) readObjectsWithObjectStorerTx(count int) error { return err } - if _, err := tx.SetObject(obj); err != nil { + if _, err := d.tx.SetObject(obj); err != nil { if rerr := d.tx.Rollback(); rerr != nil { return ErrRollback.AddDetails( "error: %s, during tx.Set error: %s", rerr, err, @@ -141,7 +141,7 @@ func (d *Decoder) readObjectsWithObjectStorerTx(count int) error { } - return tx.Commit() + return d.tx.Commit() } // ReadObject reads a object from the stream and return it diff --git a/plumbing/format/packfile/decoder_test.go b/plumbing/format/packfile/decoder_test.go index e510cf2..936f589 100644 --- a/plumbing/format/packfile/decoder_test.go +++ b/plumbing/format/packfile/decoder_test.go @@ -57,6 +57,34 @@ func (s *ReaderSuite) TestDecodeInMemory(c *C) { }) } +type nonSeekableReader struct { + r io.Reader +} + +func (nsr nonSeekableReader) Read(b []byte) (int, error) { + return nsr.r.Read(b) +} + +func (s *ReaderSuite) TestDecodeNoSeekable(c *C) { + fixtures.Basic().ByTag("packfile").Test(c, func(f *fixtures.Fixture) { + reader := nonSeekableReader{ + r: f.Packfile(), + } + + scanner := NewScanner(reader) + storage := memory.NewStorage() + d, err := NewDecoder(scanner, storage) + c.Assert(err, IsNil) + defer d.Close() + + ch, err := d.Decode() + c.Assert(err, IsNil) + c.Assert(ch, Equals, f.PackfileHash) + + assertObjects(c, storage, expectedHashes) + }) +} + var expectedHashes = []string{ "918c48b83bd081e863dbe1b80f8998f058cd8294", "af2d6a6954d532f8ffb47615169c8fdf9d383a1a", |