aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-01 21:16:31 -0800
committerJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-01 21:16:31 -0800
commitf26d06d8b3dafae8b849bb0b812f2ce58df92423 (patch)
tree8623788650232bc0bcb91dab5eee19b99e15c2c5
parentd5696c0b75a115001e67025181663b8952b02691 (diff)
parent1cad23e71e4db887700ef6d192ade463904261fd (diff)
downloadgo-git-f26d06d8b3dafae8b849bb0b812f2ce58df92423.tar.gz
Merge remote-tracking branch 'upstream/master' into generic-object-storage
-rw-r--r--.travis.yml14
-rw-r--r--Makefile36
-rw-r--r--formats/packfile/common.go7
-rw-r--r--formats/packfile/reader.go7
-rw-r--r--tree_test.go68
5 files changed, 116 insertions, 16 deletions
diff --git a/.travis.yml b/.travis.yml
index 7ab153a..9b7ee12 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,6 +3,7 @@ language: go
go:
- 1.4
- 1.5
+ - tip
install:
- rm -rf $GOPATH/src/gopkg.in/src-d
@@ -11,18 +12,7 @@ install:
- go get -v -t ./...
script:
- - go test -v ./...
-
-script:
- - go test -v gopkg.in/src-d/go-git.v2 -covermode=count -coverprofile=coverage.out
- - go test -v gopkg.in/src-d/go-git.v2/clients/common -covermode=count -coverprofile=tmp.out
- - tail -n +2 tmp.out >> coverage.out
- - go test -v gopkg.in/src-d/go-git.v2/clients/http -covermode=count -coverprofile=tmp.out
- - tail -n +2 tmp.out >> coverage.out
- - go test -v gopkg.in/src-d/go-git.v2/formats/packfile -covermode=count -coverprofile=tmp.out
- - tail -n +2 tmp.out >> coverage.out
- - go test -v gopkg.in/src-d/go-git.v2/formats/pktline -covermode=count -coverprofile=tmp.out
- - tail -n +2 tmp.out >> coverage.out
+ - make test-coverage
after_success:
- bash <(curl -s https://codecov.io/bash)
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..18e9991
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,36 @@
+# Default shell
+SHELL := /bin/bash
+
+# General
+WORKDIR = $(PWD)
+
+# Go parameters
+GOCMD = go
+GOTEST = $(GOCMD) test -v
+
+# Coverage
+COVERAGE_REPORT = coverage.txt
+COVERAGE_PROFILE = profile.out
+COVERAGE_MODE = atomic
+
+ifneq ($(origin CI), undefined)
+ WORKDIR := $(TRAVIS_BUILD_DIR)
+endif
+
+
+test:
+ $(GOTEST) ./...
+
+test-coverage:
+ cd $(WORKDIR); \
+ echo "" > $(COVERAGE_REPORT); \
+ for dir in `find . -name "*.go" | grep -o '.*/' | sort | uniq`; do \
+ $(GOTEST) $$dir -coverprofile=$(COVERAGE_PROFILE) -covermode=$(COVERAGE_MODE); \
+ if [ $$? != 0 ]; then \
+ exit 2; \
+ fi; \
+ if [ -f $(COVERAGE_PROFILE) ]; then \
+ cat $(COVERAGE_PROFILE) >> $(COVERAGE_REPORT); \
+ rm $(COVERAGE_PROFILE); \
+ fi; \
+ done; \
diff --git a/formats/packfile/common.go b/formats/packfile/common.go
index 06c63d4..57bc0b9 100644
--- a/formats/packfile/common.go
+++ b/formats/packfile/common.go
@@ -1,6 +1,7 @@
package packfile
import (
+ "bufio"
"fmt"
"io"
)
@@ -10,6 +11,12 @@ type trackingReader struct {
position int64
}
+func NewTrackingReader(r io.Reader) *trackingReader {
+ return &trackingReader{
+ r: bufio.NewReader(r),
+ }
+}
+
func (t *trackingReader) Read(p []byte) (n int, err error) {
n, err = t.r.Read(p)
if err != nil {
diff --git a/formats/packfile/reader.go b/formats/packfile/reader.go
index 3ff342f..959e411 100644
--- a/formats/packfile/reader.go
+++ b/formats/packfile/reader.go
@@ -59,7 +59,7 @@ func NewReader(r io.Reader) *Reader {
return &Reader{
MaxObjectsLimit: DefaultMaxObjectsLimit,
- r: &trackingReader{r: r},
+ r: NewTrackingReader(r),
offsets: make(map[int64]core.Hash, 0),
}
}
@@ -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))
+ }
+}