aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/internal
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-09-07 02:04:43 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-09-07 02:04:43 +0200
commit56adb5be3ad26a0045ea6c6a6d24dafdff15ba1c (patch)
treebd8ecbb6674f01f03f97fb15083bed0a3e8e021d /storage/filesystem/internal
parent98a22e72a808aa0d5dd62339817404fd9e1c4db6 (diff)
downloadgo-git-56adb5be3ad26a0045ea6c6a6d24dafdff15ba1c.tar.gz
format: packfile new interface
Diffstat (limited to 'storage/filesystem/internal')
-rw-r--r--storage/filesystem/internal/dotgit/dotgit_test.go4
-rw-r--r--storage/filesystem/internal/index/index.go26
-rw-r--r--storage/filesystem/internal/index/index_test.go29
3 files changed, 39 insertions, 20 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit_test.go b/storage/filesystem/internal/dotgit/dotgit_test.go
index 3f0a0eb..0097821 100644
--- a/storage/filesystem/internal/dotgit/dotgit_test.go
+++ b/storage/filesystem/internal/dotgit/dotgit_test.go
@@ -54,7 +54,7 @@ func (s *SuiteDotGit) SetUpSuite(c *C) {
path, err := tgz.Extract(init.tgz)
c.Assert(err, IsNil, com)
- s.fixtures[init.name] = fs.NewOSClient(filepath.Join(path, ".git"))
+ s.fixtures[init.name] = fs.NewOS(filepath.Join(path, ".git"))
}
}
@@ -233,7 +233,7 @@ func (s *SuiteDotGit) TestNewObjectPack(c *C) {
log.Fatal(err)
}
- dot := New(fs.NewOSClient(dir))
+ dot := New(fs.NewOS(dir))
r, err := os.Open("../../../../formats/packfile/fixtures/git-fixture.ofs-delta")
c.Assert(err, IsNil)
diff --git a/storage/filesystem/internal/index/index.go b/storage/filesystem/internal/index/index.go
index 70b77c5..2fd2a55 100644
--- a/storage/filesystem/internal/index/index.go
+++ b/storage/filesystem/internal/index/index.go
@@ -1,7 +1,6 @@
package index
import (
- "fmt"
"io"
"gopkg.in/src-d/go-git.v4/core"
@@ -13,6 +12,10 @@ import (
// Objects are identified by their hash.
type Index map[core.Hash]int64
+func New() Index {
+ return make(Index)
+}
+
// Decode decodes a idxfile into the Index
func (i *Index) Decode(r io.Reader) error {
d := idxfile.NewDecoder(r)
@@ -30,23 +33,16 @@ func (i *Index) Decode(r io.Reader) error {
// NewFrompackfile returns a new index from a packfile reader.
func NewFromPackfile(r io.Reader) (Index, core.Hash, error) {
- index := make(Index)
+ p := packfile.NewScannerFromReader(r)
+ d := packfile.NewDecoder(p, nil)
- p := packfile.NewParser(r)
- _, count, err := p.Header()
+ checksum, err := d.Decode()
if err != nil {
return nil, core.ZeroHash, err
}
- for i := 0; i < int(count); i++ {
- h, err := p.NextObjectHeader()
- if err = index.Set(core.ZeroHash, h.Offset); err != nil {
- return nil, core.ZeroHash, err
- }
- }
-
- hash, err := p.Checksum()
- return index, hash, err
+ index := Index(d.Index())
+ return index, checksum, p.Close()
}
// Get returns the offset that an object has the packfile.
@@ -61,9 +57,9 @@ func (i Index) Get(h core.Hash) (int64, error) {
// Set adds a new hash-offset pair to the index, or substitutes an existing one.
func (i Index) Set(h core.Hash, o int64) error {
- if _, ok := i[h]; ok {
+ /*if _, ok := i[h]; ok {
return fmt.Errorf("index.Set failed: duplicated key: %s", h)
- }
+ }*/
i[h] = o
diff --git a/storage/filesystem/internal/index/index_test.go b/storage/filesystem/internal/index/index_test.go
index 4ddfc25..5261012 100644
--- a/storage/filesystem/internal/index/index_test.go
+++ b/storage/filesystem/internal/index/index_test.go
@@ -1,6 +1,7 @@
package index
import (
+ "io/ioutil"
"os"
"testing"
@@ -16,6 +17,22 @@ type SuiteIndex struct{}
var _ = Suite(&SuiteIndex{})
+func (s *SuiteIndex) TestNewFromPackfile(c *C) {
+ path := "../../../../formats/packfile/fixtures/spinnaker-spinnaker.pack"
+
+ pack, err := os.Open(path)
+ c.Assert(err, IsNil)
+
+ _, checksum, err := NewFromPackfile(pack)
+ c.Assert(err, IsNil)
+
+ leftover, err := ioutil.ReadAll(pack)
+ c.Assert(err, IsNil)
+ c.Assert(leftover, HasLen, 0)
+
+ c.Assert(checksum.String(), Equals, "da4c488bbbdc4e599c7c97d01753bb3144fccd9c")
+}
+
func (s *SuiteIndex) TestNewFromIdx(c *C) {
for i, test := range [...]struct {
idxPath string
@@ -33,7 +50,9 @@ func (s *SuiteIndex) TestNewFromIdx(c *C) {
idx, err := os.Open(test.idxPath)
c.Assert(err, IsNil, com)
- index, err := NewFromIdx(idx)
+ index := New()
+ err = index.Decode(idx)
+
if test.errRegexp != "" {
c.Assert(err, ErrorMatches, test.errRegexp, com)
} else {
@@ -78,7 +97,9 @@ func (s *SuiteIndex) TestGet(c *C) {
idx, err := os.Open(test.idx)
c.Assert(err, IsNil, com)
- index, err := NewFromIdx(idx)
+ index := New()
+ err = index.Decode(idx)
+
c.Assert(err, IsNil, com)
obt, err := index.Get(test.hash)
@@ -106,7 +127,9 @@ func (s *SuiteIndex) BenchmarkFromIdx(c *C) {
for i := 0; i < c.N; i++ {
c.StartTimer()
- index, _ := NewFromIdx(idx)
+ index := New()
+ index.Decode(idx)
+
c.StopTimer()
indexes = append(indexes, index)
}