Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #17 from alcortesm/fix-zlib-invalid-header
Browse files Browse the repository at this point in the history
fix zlib invalid header error
  • Loading branch information
mcuadros committed Jan 27, 2016
2 parents f39e08f + 4c89741 commit 35ee4d7
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
5 changes: 2 additions & 3 deletions formats/packfile/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
68 changes: 68 additions & 0 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
}
}

0 comments on commit 35ee4d7

Please sign in to comment.