From b33cab2b34e743ad5eb2d50af801b0cde9d6e692 Mon Sep 17 00:00:00 2001 From: Aaron Boodman Date: Tue, 16 Jun 2015 16:19:16 -0700 Subject: [PATCH] Rename package 'store' to 'chunks'. This is in preparation for renaming the 'Commit' abstraction to DataStore. So we will essentially have a 'chunkstore' abstraction and a 'datastore' abstraction. --- {store => chunks}/chunk_store.go | 10 ++++++++-- {store => chunks}/file_store.go | 2 +- {store => chunks}/file_store_test.go | 2 +- {store => chunks}/memory_store.go | 2 +- {store => chunks}/memory_store_test.go | 2 +- {store => chunks}/nop_sink.go | 2 +- {store => chunks}/nop_sink_test.go | 2 +- {store => chunks}/s3_store.go | 2 +- {store => chunks}/s3_store_test.go | 2 +- commit/commit.go | 8 ++++---- commit/commit_test.go | 4 ++-- commit/memcache_reachable.go | 6 +++--- enc/blob_codec.go | 6 +++--- enc/blob_codec_test.go | 4 ++-- enc/json_decode.go | 16 ++++++++-------- enc/json_decode_test.go | 4 ++-- enc/json_encode.go | 14 +++++++------- enc/json_encode_test.go | 6 +++--- enc/read_value.go | 6 +++--- enc/reffer_impl.go | 4 ++-- enc/write_value.go | 4 ++-- enc/write_value_test.go | 6 +++--- 22 files changed, 60 insertions(+), 54 deletions(-) rename {store => chunks}/chunk_store.go (73%) rename {store => chunks}/file_store.go (99%) rename {store => chunks}/file_store_test.go (99%) rename {store => chunks}/memory_store.go (98%) rename {store => chunks}/memory_store_test.go (97%) rename {store => chunks}/nop_sink.go (95%) rename {store => chunks}/nop_sink_test.go (96%) rename {store => chunks}/s3_store.go (99%) rename {store => chunks}/s3_store_test.go (99%) diff --git a/store/chunk_store.go b/chunks/chunk_store.go similarity index 73% rename from store/chunk_store.go rename to chunks/chunk_store.go index 486b65f9cb..91e6973ef3 100644 --- a/store/chunk_store.go +++ b/chunks/chunk_store.go @@ -1,4 +1,4 @@ -package store +package chunks import ( "io" @@ -6,7 +6,13 @@ import ( "github.com/attic-labs/noms/ref" ) -type RootStore interface { +type ChunkStore interface { + RootTracker + ChunkSource + ChunkSink +} + +type RootTracker interface { Root() ref.Ref UpdateRoot(current, last ref.Ref) bool } diff --git a/store/file_store.go b/chunks/file_store.go similarity index 99% rename from store/file_store.go rename to chunks/file_store.go index 7ca0691783..f0aac2f9af 100644 --- a/store/file_store.go +++ b/chunks/file_store.go @@ -1,4 +1,4 @@ -package store +package chunks import ( "flag" diff --git a/store/file_store_test.go b/chunks/file_store_test.go similarity index 99% rename from store/file_store_test.go rename to chunks/file_store_test.go index 59c90626c5..27b7463c5c 100644 --- a/store/file_store_test.go +++ b/chunks/file_store_test.go @@ -1,4 +1,4 @@ -package store +package chunks import ( "io/ioutil" diff --git a/store/memory_store.go b/chunks/memory_store.go similarity index 98% rename from store/memory_store.go rename to chunks/memory_store.go index 084a8f559a..03fb77fdc3 100644 --- a/store/memory_store.go +++ b/chunks/memory_store.go @@ -1,4 +1,4 @@ -package store +package chunks import ( "bytes" diff --git a/store/memory_store_test.go b/chunks/memory_store_test.go similarity index 97% rename from store/memory_store_test.go rename to chunks/memory_store_test.go index 6a681366d0..ca831ed3c7 100644 --- a/store/memory_store_test.go +++ b/chunks/memory_store_test.go @@ -1,4 +1,4 @@ -package store +package chunks import ( "io/ioutil" diff --git a/store/nop_sink.go b/chunks/nop_sink.go similarity index 95% rename from store/nop_sink.go rename to chunks/nop_sink.go index febbcaa483..e0a9b0ae82 100644 --- a/store/nop_sink.go +++ b/chunks/nop_sink.go @@ -1,4 +1,4 @@ -package store +package chunks import ( "hash" diff --git a/store/nop_sink_test.go b/chunks/nop_sink_test.go similarity index 96% rename from store/nop_sink_test.go rename to chunks/nop_sink_test.go index 022051a291..834040d595 100644 --- a/store/nop_sink_test.go +++ b/chunks/nop_sink_test.go @@ -1,4 +1,4 @@ -package store +package chunks import ( "testing" diff --git a/store/s3_store.go b/chunks/s3_store.go similarity index 99% rename from store/s3_store.go rename to chunks/s3_store.go index 2bca3a898b..9a8d539ad9 100644 --- a/store/s3_store.go +++ b/chunks/s3_store.go @@ -1,4 +1,4 @@ -package store +package chunks import ( "flag" diff --git a/store/s3_store_test.go b/chunks/s3_store_test.go similarity index 99% rename from store/s3_store_test.go rename to chunks/s3_store_test.go index 865a96eadd..1e15338980 100644 --- a/store/s3_store_test.go +++ b/chunks/s3_store_test.go @@ -1,4 +1,4 @@ -package store +package chunks import ( "bytes" diff --git a/commit/commit.go b/commit/commit.go index 1f82976c51..2bceb84957 100644 --- a/commit/commit.go +++ b/commit/commit.go @@ -1,10 +1,10 @@ package commit import ( + "github.com/attic-labs/noms/chunks" . "github.com/attic-labs/noms/dbg" "github.com/attic-labs/noms/enc" "github.com/attic-labs/noms/ref" - "github.com/attic-labs/noms/store" "github.com/attic-labs/noms/types" ) @@ -13,9 +13,9 @@ type Reachable interface { } type Commit struct { - root store.RootStore - source store.ChunkSource - sink store.ChunkSink + root chunks.RootTracker + source chunks.ChunkSource + sink chunks.ChunkSink reachable Reachable } diff --git a/commit/commit_test.go b/commit/commit_test.go index a0e34dcacb..3c128e58bf 100644 --- a/commit/commit_test.go +++ b/commit/commit_test.go @@ -5,8 +5,8 @@ import ( "os" "testing" + "github.com/attic-labs/noms/chunks" "github.com/attic-labs/noms/enc" - "github.com/attic-labs/noms/store" "github.com/attic-labs/noms/types" "github.com/stretchr/testify/assert" ) @@ -17,7 +17,7 @@ func TestCommit(t *testing.T) { defer os.Remove(dir) assert.NoError(err) - store := store.NewFileStore(dir, "root") + store := chunks.NewFileStore(dir, "root") commit := &Commit{ store, store, diff --git a/commit/memcache_reachable.go b/commit/memcache_reachable.go index 5e20342f8b..a717a6d0e7 100644 --- a/commit/memcache_reachable.go +++ b/commit/memcache_reachable.go @@ -1,16 +1,16 @@ package commit import ( + "github.com/attic-labs/noms/chunks" . "github.com/attic-labs/noms/dbg" "github.com/attic-labs/noms/enc" "github.com/attic-labs/noms/ref" - "github.com/attic-labs/noms/store" "github.com/attic-labs/noms/types" ) // TODO(rafael): type memcacheReachable struct { - source store.ChunkSource + source chunks.ChunkSource refs map[string]bool } @@ -54,7 +54,7 @@ func (cache *memcacheReachable) IsSupercededFrom(candidate, root ref.Ref) bool { return ok } -func NewMemCacheReachable(source store.ChunkSource) Reachable { +func NewMemCacheReachable(source chunks.ChunkSource) Reachable { return &memcacheReachable{ source, make(map[string]bool), diff --git a/enc/blob_codec.go b/enc/blob_codec.go index 9ee8e5b565..190c386a85 100644 --- a/enc/blob_codec.go +++ b/enc/blob_codec.go @@ -4,9 +4,9 @@ import ( "bytes" "io" + "github.com/attic-labs/noms/chunks" . "github.com/attic-labs/noms/dbg" "github.com/attic-labs/noms/ref" - "github.com/attic-labs/noms/store" "github.com/attic-labs/noms/types" ) @@ -14,7 +14,7 @@ var ( blobTag = []byte("b ") ) -func blobEncode(b types.Blob, s store.ChunkSink) (r ref.Ref, err error) { +func blobEncode(b types.Blob, s chunks.ChunkSink) (r ref.Ref, err error) { w := s.Put() if _, err = w.Write(blobTag); err != nil { return @@ -25,7 +25,7 @@ func blobEncode(b types.Blob, s store.ChunkSink) (r ref.Ref, err error) { return w.Ref() } -func blobDecode(r io.Reader, s store.ChunkSource) (types.Value, error) { +func blobDecode(r io.Reader, s chunks.ChunkSource) (types.Value, error) { buf := &bytes.Buffer{} _, err := io.CopyN(buf, r, int64(len(blobTag))) if err != nil { diff --git a/enc/blob_codec_test.go b/enc/blob_codec_test.go index 16fac1bcd0..1d9aabcf77 100644 --- a/enc/blob_codec_test.go +++ b/enc/blob_codec_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "github.com/attic-labs/noms/store" + "github.com/attic-labs/noms/chunks" "github.com/attic-labs/noms/types" "github.com/stretchr/testify/assert" ) @@ -16,7 +16,7 @@ func TestBlobCodec(t *testing.T) { dir, err := ioutil.TempDir(os.TempDir(), "") defer os.Remove(dir) assert.NoError(err) - fs := store.NewFileStore(dir, "root") + fs := chunks.NewFileStore(dir, "root") b1 := types.NewBlob([]byte{}) r1, err := blobEncode(b1, fs) // echo -n 'b ' | sha1sum diff --git a/enc/json_decode.go b/enc/json_decode.go index 4bebbc9385..7fbecf0331 100644 --- a/enc/json_decode.go +++ b/enc/json_decode.go @@ -5,13 +5,13 @@ import ( "fmt" "io" + "github.com/attic-labs/noms/chunks" . "github.com/attic-labs/noms/dbg" "github.com/attic-labs/noms/ref" - "github.com/attic-labs/noms/store" "github.com/attic-labs/noms/types" ) -func jsonDecode(reader io.Reader, s store.ChunkSource) (types.Value, error) { +func jsonDecode(reader io.Reader, s chunks.ChunkSource) (types.Value, error) { prefix := make([]byte, len(jsonTag)) _, err := io.ReadFull(reader, prefix) if err != nil { @@ -30,7 +30,7 @@ func jsonDecode(reader io.Reader, s store.ChunkSource) (types.Value, error) { return jsonDecodeValue(v, s) } -func jsonDecodeValue(v interface{}, s store.ChunkSource) (types.Value, error) { +func jsonDecodeValue(v interface{}, s chunks.ChunkSource) (types.Value, error) { switch v := v.(type) { case bool: return types.Bool(v), nil @@ -43,7 +43,7 @@ func jsonDecodeValue(v interface{}, s store.ChunkSource) (types.Value, error) { } } -func jsonDecodeTaggedValue(m map[string]interface{}, s store.ChunkSource) (types.Value, error) { +func jsonDecodeTaggedValue(m map[string]interface{}, s chunks.ChunkSource) (types.Value, error) { Chk.Equal(1, len(m)) for k, v := range m { switch k { @@ -91,7 +91,7 @@ func jsonDecodeTaggedValue(m map[string]interface{}, s store.ChunkSource) (types return nil, fmt.Errorf("Cannot decode tagged json value: %+v", m) } -func jsonDecodeList(input []interface{}, s store.ChunkSource) (types.Value, error) { +func jsonDecodeList(input []interface{}, s chunks.ChunkSource) (types.Value, error) { output := types.NewList() for _, inVal := range input { outVal, err := jsonDecodeValue(inVal, s) @@ -103,7 +103,7 @@ func jsonDecodeList(input []interface{}, s store.ChunkSource) (types.Value, erro return output, nil } -func jsonDecodeSet(input []interface{}, s store.ChunkSource) (types.Value, error) { +func jsonDecodeSet(input []interface{}, s chunks.ChunkSource) (types.Value, error) { vals := []types.Value{} for _, inVal := range input { outVal, err := jsonDecodeValue(inVal, s) @@ -115,7 +115,7 @@ func jsonDecodeSet(input []interface{}, s store.ChunkSource) (types.Value, error return types.NewSet(vals...), nil } -func jsonDecodeMap(input []interface{}, s store.ChunkSource) (types.Value, error) { +func jsonDecodeMap(input []interface{}, s chunks.ChunkSource) (types.Value, error) { output := types.NewMap() Chk.Equal(0, len(input)%2, "Length on input array must be multiple of 2") for i := 0; i < len(input); i += 2 { @@ -135,7 +135,7 @@ func jsonDecodeMap(input []interface{}, s store.ChunkSource) (types.Value, error return output, nil } -func jsonDecodeRef(refStr string, s store.ChunkSource) (types.Value, error) { +func jsonDecodeRef(refStr string, s chunks.ChunkSource) (types.Value, error) { ref, err := ref.Parse(refStr) if err != nil { return nil, err diff --git a/enc/json_decode_test.go b/enc/json_decode_test.go index f52438750b..78cc667887 100644 --- a/enc/json_decode_test.go +++ b/enc/json_decode_test.go @@ -4,14 +4,14 @@ import ( "strings" "testing" - "github.com/attic-labs/noms/store" + "github.com/attic-labs/noms/chunks" "github.com/attic-labs/noms/types" "github.com/stretchr/testify/assert" ) func TestJSONDecode(t *testing.T) { assert := assert.New(t) - cs := store.MemoryStore{} + cs := chunks.MemoryStore{} put := func(s string) { s += "\n" diff --git a/enc/json_encode.go b/enc/json_encode.go index 76567d14ed..a71621759e 100644 --- a/enc/json_encode.go +++ b/enc/json_encode.go @@ -5,9 +5,9 @@ import ( "fmt" "sort" + "github.com/attic-labs/noms/chunks" . "github.com/attic-labs/noms/dbg" "github.com/attic-labs/noms/ref" - "github.com/attic-labs/noms/store" "github.com/attic-labs/noms/types" ) @@ -15,7 +15,7 @@ var ( jsonTag = []byte("j ") ) -func jsonEncode(v types.Value, s store.ChunkSink) (r ref.Ref, err error) { +func jsonEncode(v types.Value, s chunks.ChunkSink) (r ref.Ref, err error) { var j interface{} j, err = getJSON(v, s) if err != nil { @@ -32,7 +32,7 @@ func jsonEncode(v types.Value, s store.ChunkSink) (r ref.Ref, err error) { return w.Ref() } -func getJSON(v types.Value, s store.ChunkSink) (interface{}, error) { +func getJSON(v types.Value, s chunks.ChunkSink) (interface{}, error) { switch v := v.(type) { case types.Blob: Chk.Fail(fmt.Sprintf("jsonEncode doesn't support encoding blobs - didn't expect to get here: %+v", v)) @@ -83,7 +83,7 @@ func getJSON(v types.Value, s store.ChunkSink) (interface{}, error) { } return nil, nil } -func getJSONList(l types.List, s store.ChunkSink) (r interface{}, err error) { +func getJSONList(l types.List, s chunks.ChunkSink) (r interface{}, err error) { j := []interface{}{} for i := uint64(0); i < l.Len(); i++ { var cj interface{} @@ -99,7 +99,7 @@ func getJSONList(l types.List, s store.ChunkSink) (r interface{}, err error) { return } -func getJSONMap(m types.Map, s store.ChunkSink) (r interface{}, err error) { +func getJSONMap(m types.Map, s chunks.ChunkSink) (r interface{}, err error) { // Iteration through Set is random, but we need a deterministic order for serialization. Let's order using the refs of the values in the set. order := types.MapEntrySlice{} m.Iter(func(entry types.MapEntry) (stop bool) { @@ -128,7 +128,7 @@ func getJSONMap(m types.Map, s store.ChunkSink) (r interface{}, err error) { return } -func getJSONSet(set types.Set, s store.ChunkSink) (r interface{}, err error) { +func getJSONSet(set types.Set, s chunks.ChunkSink) (r interface{}, err error) { // Iteration through Set is random, but we need a deterministic order for serialization. Let's order using the refs of the values in the set. lookup := map[ref.Ref]types.Value{} order := ref.RefSlice{} @@ -156,7 +156,7 @@ func getJSONSet(set types.Set, s store.ChunkSink) (r interface{}, err error) { return } -func getChildJSON(v types.Value, s store.ChunkSink) (interface{}, error) { +func getChildJSON(v types.Value, s chunks.ChunkSink) (interface{}, error) { var r ref.Ref var err error switch v := v.(type) { diff --git a/enc/json_encode_test.go b/enc/json_encode_test.go index 20018f1215..38abcb79f7 100644 --- a/enc/json_encode_test.go +++ b/enc/json_encode_test.go @@ -4,18 +4,18 @@ import ( "crypto/sha1" "testing" + "github.com/attic-labs/noms/chunks" "github.com/attic-labs/noms/ref" - "github.com/attic-labs/noms/store" "github.com/attic-labs/noms/types" "github.com/stretchr/testify/assert" ) func TestJsonEncode(t *testing.T) { assert := assert.New(t) - var s *store.MemoryStore + var s *chunks.MemoryStore testEncode := func(expected string, v types.Value) ref.Ref { - s = &store.MemoryStore{} + s = &chunks.MemoryStore{} r, err := jsonEncode(v, s) assert.NoError(err) diff --git a/enc/read_value.go b/enc/read_value.go index 69d7651265..06241c2455 100644 --- a/enc/read_value.go +++ b/enc/read_value.go @@ -5,14 +5,14 @@ import ( "bytes" "fmt" + "github.com/attic-labs/noms/chunks" . "github.com/attic-labs/noms/dbg" "github.com/attic-labs/noms/ref" - "github.com/attic-labs/noms/store" "github.com/attic-labs/noms/types" ) // Reads and decodes a value from a chunk source. -func ReadValue(ref ref.Ref, cs store.ChunkSource) (types.Value, error) { +func ReadValue(ref ref.Ref, cs chunks.ChunkSource) (types.Value, error) { reader, err := cs.Get(ref) if err != nil { return nil, err @@ -36,7 +36,7 @@ func ReadValue(ref ref.Ref, cs store.ChunkSource) (types.Value, error) { return nil, fmt.Errorf("Unsupported chunk tag: %+v", prefix) } -func MustReadValue(ref ref.Ref, cs store.ChunkSource) types.Value { +func MustReadValue(ref ref.Ref, cs chunks.ChunkSource) types.Value { val, err := ReadValue(ref, cs) Chk.NoError(err) return val diff --git a/enc/reffer_impl.go b/enc/reffer_impl.go index e15515adeb..952789c217 100644 --- a/enc/reffer_impl.go +++ b/enc/reffer_impl.go @@ -1,9 +1,9 @@ package enc import ( + "github.com/attic-labs/noms/chunks" . "github.com/attic-labs/noms/dbg" "github.com/attic-labs/noms/ref" - "github.com/attic-labs/noms/store" "github.com/attic-labs/noms/types" ) @@ -12,7 +12,7 @@ func init() { } func refferImpl(v types.Value) ref.Ref { - r, err := WriteValue(v, store.NopSink{}) + r, err := WriteValue(v, chunks.NopSink{}) // This can never fail because NopSink doesn't write anywhere. Chk.Nil(err) return r diff --git a/enc/write_value.go b/enc/write_value.go index 8269594194..b9ccdbd14e 100644 --- a/enc/write_value.go +++ b/enc/write_value.go @@ -1,12 +1,12 @@ package enc import ( + "github.com/attic-labs/noms/chunks" "github.com/attic-labs/noms/ref" - "github.com/attic-labs/noms/store" "github.com/attic-labs/noms/types" ) -func WriteValue(v types.Value, cs store.ChunkSink) (ref.Ref, error) { +func WriteValue(v types.Value, cs chunks.ChunkSink) (ref.Ref, error) { switch v := v.(type) { case types.Blob: return blobEncode(v, cs) diff --git a/enc/write_value_test.go b/enc/write_value_test.go index ee3b39d11f..2ab6d6cb9e 100644 --- a/enc/write_value_test.go +++ b/enc/write_value_test.go @@ -4,8 +4,8 @@ import ( "crypto/sha1" "testing" + "github.com/attic-labs/noms/chunks" "github.com/attic-labs/noms/ref" - "github.com/attic-labs/noms/store" "github.com/attic-labs/noms/types" "github.com/stretchr/testify/assert" ) @@ -13,10 +13,10 @@ import ( func TestWriteValue(t *testing.T) { assert := assert.New(t) - var s *store.MemoryStore + var s *chunks.MemoryStore testEncode := func(expected string, v types.Value) ref.Ref { - s = &store.MemoryStore{} + s = &chunks.MemoryStore{} r, err := WriteValue(v, s) assert.NoError(err)