aboutsummaryrefslogtreecommitdiffstats
path: root/packfile
diff options
context:
space:
mode:
authorAlex Guerrieri <alex@tyba.com>2015-10-14 11:08:11 +0200
committerAlex Guerrieri <alex@tyba.com>2015-10-14 11:08:11 +0200
commita2014124ca3b3f9ff28fbab0a83ce3c71bf4622e (patch)
tree9e1917bba4d724555f7e2bfbf1bba00a78fac2e4 /packfile
parent77906b653c3eb8a1cd5bd7254e161c00c6086d83 (diff)
downloadgo-git-a2014124ca3b3f9ff28fbab0a83ce3c71bf4622e.tar.gz
memory passed to NewGit(), changed git types name
Diffstat (limited to 'packfile')
-rw-r--r--packfile/reader.go12
-rw-r--r--packfile/reader_test.go4
2 files changed, 7 insertions, 9 deletions
diff --git a/packfile/reader.go b/packfile/reader.go
index 627fdfd..e761654 100644
--- a/packfile/reader.go
+++ b/packfile/reader.go
@@ -11,13 +11,11 @@ import (
const MaxObjectsLimit = 1000000
-const MaxSizeLimit = 300 * 1 << 20
-
var ErrMaxSize = fmt.Errorf("Max size exceeded for in-memory client")
type TrackingByteReader struct {
- r io.Reader
- n int
+ r io.Reader
+ n, l int
}
func (t *TrackingByteReader) Pos() int { return t.n }
@@ -28,7 +26,7 @@ func (t *TrackingByteReader) Read(p []byte) (n int, err error) {
return 0, err
}
t.n += n
- if t.n >= MaxSizeLimit {
+ if t.n >= t.l {
return n, ErrMaxSize
}
return n, err
@@ -67,9 +65,9 @@ type packfileDelta struct {
delta []byte
}
-func NewPackfileReader(r io.Reader, fn ContentCallback) (*PackfileReader, error) {
+func NewPackfileReader(r io.Reader, l int, fn ContentCallback) (*PackfileReader, error) {
return &PackfileReader{
- r: &TrackingByteReader{r: r, n: 0},
+ r: &TrackingByteReader{r: r, n: 0, l: l},
objects: make(map[string]packfileObject, 0),
offsets: make(map[int]string, 0),
contentCallback: fn,
diff --git a/packfile/reader_test.go b/packfile/reader_test.go
index e52cbc3..04f2948 100644
--- a/packfile/reader_test.go
+++ b/packfile/reader_test.go
@@ -14,7 +14,7 @@ func TestReadPackfile(t *testing.T) {
data, _ := base64.StdEncoding.DecodeString(packFileWithEmptyObjects)
d := bytes.NewReader(data)
- r, err := NewPackfileReader(d, nil)
+ r, err := NewPackfileReader(d, 8<<20, nil)
assert.Nil(t, err)
p, err := r.Read()
@@ -26,7 +26,7 @@ func TestReadPackfile(t *testing.T) {
}
func TestReadPackfileInvalid(t *testing.T) {
- r, err := NewPackfileReader(bytes.NewReader([]byte("dasdsadasas")), nil)
+ r, err := NewPackfileReader(bytes.NewReader([]byte("dasdsadasas")), 8<<20, nil)
assert.Nil(t, err)
_, err = r.Read()