aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/internal/index/index.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-09-09 16:50:35 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-09-09 16:50:35 +0200
commitf09fb50cb092c241df4c0bd25c6755e6132e473e (patch)
treec67f4cdeacf70a64d00167cceceed7a68a5c9e4a /storage/filesystem/internal/index/index.go
parent59219f01bbf5f748876258fe5f4648d2cfd4d6e9 (diff)
downloadgo-git-f09fb50cb092c241df4c0bd25c6755e6132e473e.tar.gz
storage: filessytem read multiple packfiles support and index decoding
Diffstat (limited to 'storage/filesystem/internal/index/index.go')
-rw-r--r--storage/filesystem/internal/index/index.go71
1 files changed, 0 insertions, 71 deletions
diff --git a/storage/filesystem/internal/index/index.go b/storage/filesystem/internal/index/index.go
deleted file mode 100644
index 412b78f..0000000
--- a/storage/filesystem/internal/index/index.go
+++ /dev/null
@@ -1,71 +0,0 @@
-package index
-
-import (
- "fmt"
- "io"
-
- "gopkg.in/src-d/go-git.v4/core"
- "gopkg.in/src-d/go-git.v4/formats/idxfile"
- "gopkg.in/src-d/go-git.v4/formats/packfile"
- "gopkg.in/src-d/go-git.v4/storage/memory"
-)
-
-// Index is a database of objects and their offset in a packfile.
-// 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)
- idx := &idxfile.Idxfile{}
- if err := d.Decode(idx); err != nil {
- return err
- }
-
- for _, e := range idx.Entries {
- fmt.Println(e.CRC32)
- (*i)[e.Hash] = int64(e.Offset)
- }
-
- return nil
-}
-
-// NewFrompackfile returns a new index from a packfile reader.
-func NewFromPackfile(r io.Reader) (Index, core.Hash, error) {
- o := memory.NewStorage().ObjectStorage()
- s := packfile.NewScannerFromReader(r)
- d := packfile.NewDecoder(s, o)
-
- checksum, err := d.Decode()
- if err != nil {
- return nil, core.ZeroHash, err
- }
-
- index := Index(d.Offsets())
- return index, checksum, d.Close()
-}
-
-// Get returns the offset that an object has the packfile.
-func (i Index) Get(h core.Hash) (int64, error) {
- o, ok := i[h]
- if !ok {
- return 0, core.ErrObjectNotFound
- }
-
- return o, nil
-}
-
-// 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 {
- return fmt.Errorf("index.Set failed: duplicated key: %s", h)
- }*/
-
- i[h] = o
-
- return nil
-}