diff options
Diffstat (limited to 'storage/filesystem/internal/index/index.go')
-rw-r--r-- | storage/filesystem/internal/index/index.go | 26 |
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 |