diff options
author | Alberto Cortés <alberto@sourced.tech> | 2016-01-27 11:13:49 +0100 |
---|---|---|
committer | Alberto Cortés <alberto@sourced.tech> | 2016-01-27 11:55:26 +0100 |
commit | 4c897413b26c18c3a24c667b1bddaaffda7e098e (patch) | |
tree | d1d7f66e22b60cb1e3654cec11d417742d3659e4 | |
parent | f39e08f31be9df1620b751e93ed84c87de2b4e86 (diff) | |
download | go-git-4c897413b26c18c3a24c667b1bddaaffda7e098e.tar.gz |
fix zlib invalid header error
The return value of reads to the packfile were being ignored, so zlib
was getting invalid data on it read buffers.
-rw-r--r-- | formats/packfile/reader.go | 5 | ||||
-rw-r--r-- | tree_test.go | 68 |
2 files changed, 70 insertions, 3 deletions
diff --git a/formats/packfile/reader.go b/formats/packfile/reader.go index 37918b1..959e411 100644 --- a/formats/packfile/reader.go +++ b/formats/packfile/reader.go @@ -98,7 +98,7 @@ func (r *Reader) Read(s core.ObjectStorage) (int64, error) { func (r *Reader) validateHeader() error { var header = make([]byte, 4) - if _, err := r.r.Read(header); err != nil { + if _, err := io.ReadFull(r.r, header); err != nil { return err } @@ -127,7 +127,6 @@ func (r *Reader) readObjects(count uint32) error { start := r.r.position obj, err := r.newRAWObject() if err != nil && err != io.EOF { - fmt.Println(err) return err } @@ -188,7 +187,7 @@ func (r *Reader) newRAWObject() (core.Object, error) { func (r *Reader) readREFDelta(raw core.Object) error { var ref core.Hash - if _, err := r.r.Read(ref[:]); err != nil { + if _, err := io.ReadFull(r.r, ref[:]); err != nil { return err } diff --git a/tree_test.go b/tree_test.go index 049161c..17d7b68 100644 --- a/tree_test.go +++ b/tree_test.go @@ -2,6 +2,7 @@ package git import ( "os" + "sort" "gopkg.in/src-d/go-git.v2/core" "gopkg.in/src-d/go-git.v2/formats/packfile" @@ -26,6 +27,7 @@ func (s *SuiteTree) SetUpSuite(c *C) { {"https://github.com/jamesob/desk.git", "formats/packfile/fixtures/jamesob-desk.pack"}, {"https://github.com/spinnaker/spinnaker.git", "formats/packfile/fixtures/spinnaker-spinnaker.pack"}, {"https://github.com/alcortesm/binary-relations.git", "formats/packfile/fixtures/alcortesm-binary-relations.pack"}, + {"https://github.com/Tribler/dispersy.git", "formats/packfile/fixtures/tribler-dispersy.pack"}, } s.repos = make(map[string]*Repository, 0) for _, fixRepo := range fixtureRepos { @@ -132,3 +134,69 @@ func (s *SuiteTree) TestFile(c *C) { } } } + +func (s *SuiteTree) TestFiles(c *C) { + for i, t := range []struct { + repo string // the repo name as in localRepos + commit string // the commit to search for the file + files []string // the expected files in the commit + }{ + {"https://github.com/alcortesm/binary-relations.git", "b373f85fa2594d7dcd9989f4a5858a81647fb8ea", []string{ + "binary-relations.tex", + ".gitignore", + "imgs-gen/simple-graph/fig.fig", + "imgs-gen/simple-graph/Makefile", + "Makefile", + "src/map-slice/map-slice.go", + "src/simple-arrays/simple-arrays.go", + }}, + {"https://github.com/Tribler/dispersy.git", "f5a1fca709f760bf75a7adaa480bf0f0e1a547ee", []string{ + "authentication.py", + "bloomfilter.py", + "bootstrap.py", + "cache.py", + "callback.py", + "candidate.py", + "community.py", + "conversion.py", + "crypto.py", + "database.py", + "debugcommunity.py", + "debug.py", + "decorator.py", + "destination.py", + "dispersydatabase.py", + "dispersy.py", + "distribution.py", + "dprint.py", + "encoding.py", + "endpoint.py", + "__init__.py", + "member.py", + "message.py", + "meta.py", + "payload.py", + "requestcache.py", + "resolution.py", + "script.py", + "singleton.py", + "timeline.py", + "tool/callbackscript.py", + "tool/__init__.py", + "tool/scenarioscript.py", + }}, + {"https://github.com/Tribler/dispersy.git", "9d38ff85ca03adcf68dc14f5b68b8994f15229f4", []string(nil)}, + } { + commit, err := s.repos[t.repo].Commit(core.NewHash(t.commit)) + c.Assert(err, IsNil, Commentf("subtest %d: %v (%s)", i, err, t.commit)) + + tree := commit.Tree() + var output []string + for file := range tree.Files() { + output = append(output, file.Name) + } + sort.Strings(output) + sort.Strings(t.files) + c.Assert(output, DeepEquals, t.files, Commentf("subtest %d, repo=%s, commit=%s", i, t.repo, t.commit)) + } +} |