aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Guerrieri <alex@tyba.com>2015-10-13 12:51:22 +0200
committerAlex Guerrieri <alex@tyba.com>2015-10-13 14:20:18 +0200
commit77906b653c3eb8a1cd5bd7254e161c00c6086d83 (patch)
tree6ee58ddba7a1931817cda9321a1be47dc0f025c3
parent465cba710284204f9851854587c2887c247222db (diff)
downloadgo-git-77906b653c3eb8a1cd5bd7254e161c00c6086d83.tar.gz
Switch of repo size
-rw-r--r--packfile/packfile.go1
-rw-r--r--packfile/reader.go9
2 files changed, 10 insertions, 0 deletions
diff --git a/packfile/packfile.go b/packfile/packfile.go
index e670cd0..11ef969 100644
--- a/packfile/packfile.go
+++ b/packfile/packfile.go
@@ -4,6 +4,7 @@ import "fmt"
type Packfile struct {
Version uint32
+ Size int64
ObjectCount int
Checksum []byte
Commits map[string]*Commit
diff --git a/packfile/reader.go b/packfile/reader.go
index 73afdb9..627fdfd 100644
--- a/packfile/reader.go
+++ b/packfile/reader.go
@@ -11,6 +11,10 @@ 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
@@ -24,6 +28,9 @@ func (t *TrackingByteReader) Read(p []byte) (n int, err error) {
return 0, err
}
t.n += n
+ if t.n >= MaxSizeLimit {
+ return n, ErrMaxSize
+ }
return n, err
}
@@ -103,6 +110,8 @@ func (pr *PackfileReader) Read() (*Packfile, error) {
return nil, err
}
+ packfile.Size = int64(pr.r.Pos())
+
return packfile, nil
}