aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/internal/index/index.go
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/index/index.go
parent98a22e72a808aa0d5dd62339817404fd9e1c4db6 (diff)
downloadgo-git-56adb5be3ad26a0045ea6c6a6d24dafdff15ba1c.tar.gz
format: packfile new interface
Diffstat (limited to 'storage/filesystem/internal/index/index.go')
-rw-r--r--storage/filesystem/internal/index/index.go26
1 files changed, 11 insertions, 15 deletions
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