aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem
diff options
context:
space:
mode:
Diffstat (limited to 'storage/filesystem')
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go2
-rw-r--r--storage/filesystem/internal/index/index.go54
-rw-r--r--storage/filesystem/object.go4
3 files changed, 14 insertions, 46 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go
index 71af7a0..3a985d5 100644
--- a/storage/filesystem/internal/dotgit/dotgit.go
+++ b/storage/filesystem/internal/dotgit/dotgit.go
@@ -230,7 +230,7 @@ func newPackWrite(fs fs.Filesystem) (*PackWriter, error) {
func (w *PackWriter) buildIndex() {
defer w.pipeReader.Close()
- index, hash, err := index.NewFromPackfileInMemory(w.pipeReader)
+ index, hash, err := index.NewFromPackfile(w.pipeReader)
w.index = index
w.hash = hash
diff --git a/storage/filesystem/internal/index/index.go b/storage/filesystem/internal/index/index.go
index d33533e..70b77c5 100644
--- a/storage/filesystem/internal/index/index.go
+++ b/storage/filesystem/internal/index/index.go
@@ -13,69 +13,39 @@ import (
// Objects are identified by their hash.
type Index map[core.Hash]int64
-// NewFromIdx returns a new index from an idx file reader.
-func NewFromIdx(r io.Reader) (Index, error) {
+// Decode decodes a idxfile into the Index
+func (i *Index) Decode(r io.Reader) error {
d := idxfile.NewDecoder(r)
idx := &idxfile.Idxfile{}
- err := d.Decode(idx)
- if err != nil {
- return nil, err
+ if err := d.Decode(idx); err != nil {
+ return err
}
- ind := make(Index)
for _, e := range idx.Entries {
- if _, ok := ind[e.Hash]; ok {
- return nil, fmt.Errorf("duplicated hash: %s", e.Hash)
- }
- ind[e.Hash] = int64(e.Offset)
+ (*i)[e.Hash] = int64(e.Offset)
}
- return ind, nil
+ return nil
}
// NewFrompackfile returns a new index from a packfile reader.
-func NewFromPackfile(rs io.ReadSeeker) (Index, core.Hash, error) {
- s := packfile.NewSeekable(rs)
- return newFromPackfile(rs, s)
-}
-
-func NewFromPackfileInMemory(rs io.Reader) (Index, core.Hash, error) {
- s := packfile.NewStream(rs)
- return newFromPackfile(rs, s)
-}
-
-func newFromPackfile(r io.Reader, s packfile.ReadRecaller) (Index, core.Hash, error) {
+func NewFromPackfile(r io.Reader) (Index, core.Hash, error) {
index := make(Index)
- p := packfile.NewParser(s)
- count, err := p.ReadHeader()
+ p := packfile.NewParser(r)
+ _, count, err := p.Header()
if err != nil {
return nil, core.ZeroHash, err
}
for i := 0; i < int(count); i++ {
- offset, err := s.Offset()
- if err != nil {
- return nil, core.ZeroHash, err
- }
-
- obj := &core.MemoryObject{}
- if err := p.FillObject(obj); err != nil {
- return nil, core.ZeroHash, err
- }
-
- err = s.Remember(offset, obj)
- if err != nil {
- return nil, core.ZeroHash, err
- }
-
- if err = index.Set(obj.Hash(), offset); err != nil {
+ h, err := p.NextObjectHeader()
+ if err = index.Set(core.ZeroHash, h.Offset); err != nil {
return nil, core.ZeroHash, err
}
}
- //The trailer records 20-byte SHA-1 checksum of all of the above.
- hash, err := p.ReadHash()
+ hash, err := p.Checksum()
return index, hash, err
}
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index c66e1ff..aef30ec 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -1,7 +1,6 @@
package filesystem
import (
- "bytes"
"fmt"
"io"
"os"
@@ -34,8 +33,7 @@ func (s *ObjectStorage) NewObject() core.Object {
// Writer method not supported on Memory storage
func (o *ObjectStorage) Writer() (io.WriteCloser, error) {
- file := bytes.NewBuffer(nil)
- return newPackWrite(o, file), nil
+ return o.dir.NewObjectPack()
}
// Set adds a new object to the storage. As this functionality is not