memory

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemoryStorage

type MemoryStorage struct {
	// contains filtered or unexported fields
}

MemoryStorage implements storage.Storer entirely in memory. All methods are safe for concurrent use: a sync.RWMutex protects every map and pointer field. Read operations acquire a read lock; write operations acquire a write lock.

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a new in-memory storage.

func (*MemoryStorage) Close

func (ms *MemoryStorage) Close() error

Close releases any resources held by the memory storage. It is a no-op.

func (*MemoryStorage) DeleteChunk

func (ms *MemoryStorage) DeleteChunk(ctx context.Context, hash core.Hash) error

DeleteChunk removes a chunk. It is idempotent.

func (*MemoryStorage) DeleteRef

func (ms *MemoryStorage) DeleteRef(ctx context.Context, name string) error

DeleteRef removes a reference.

func (*MemoryStorage) DeleteSnapshot

func (ms *MemoryStorage) DeleteSnapshot(ctx context.Context, id core.SnapshotID) error

DeleteSnapshot removes a snapshot and its manifest. It is idempotent.

func (*MemoryStorage) GetChunk

func (ms *MemoryStorage) GetChunk(ctx context.Context, hash core.Hash) (*core.Chunk, error)

GetChunk retrieves a chunk.

func (*MemoryStorage) GetConfig

func (ms *MemoryStorage) GetConfig(ctx context.Context) (*core.Config, error)

GetConfig returns the stored configuration, cloned and normalized to match the filesystem backend's invariants (chunk size clamping and field normalization).

func (*MemoryStorage) GetIndex

func (ms *MemoryStorage) GetIndex(ctx context.Context) (*core.Index, error)

GetIndex retrieves the staging index.

func (*MemoryStorage) GetPreview

func (ms *MemoryStorage) GetPreview(ctx context.Context, hash core.Hash, size int) ([]byte, error)

GetPreview is a noop stub (Phase 1).

func (*MemoryStorage) GetRef

func (ms *MemoryStorage) GetRef(ctx context.Context, name string) (*core.Reference, error)

GetRef reads a reference. If the reference is a symbolic reference, Target is resolved by recursively reading the referenced ref.

func (*MemoryStorage) GetSnapshot

func (ms *MemoryStorage) GetSnapshot(ctx context.Context, id core.SnapshotID) (*core.Snapshot, error)

GetSnapshot retrieves a snapshot and verifies its integrity by recomputing the BLAKE3 hash of its marshaled proto (with IdHash omitted), mirroring the filesystem backend. A mismatch indicates corruption and returns storage.ErrCorrupted so callers can handle it uniformly.

func (*MemoryStorage) HasChunk

func (ms *MemoryStorage) HasChunk(ctx context.Context, hash core.Hash) (bool, error)

HasChunk returns whether a chunk exists.

func (*MemoryStorage) ListChunks

func (ms *MemoryStorage) ListChunks(ctx context.Context) ([]core.Hash, error)

ListChunks returns the hashes of all stored chunks. The order of the returned slice is not guaranteed.

func (*MemoryStorage) ListRefs

func (ms *MemoryStorage) ListRefs(ctx context.Context, prefix string) ([]*core.Reference, error)

ListRefs lists all references matching the given prefix. HEAD is excluded to match the filesystem backend, which only walks the refs/ directory (HEAD lives at the repository root, outside refs/). Each ref is resolved via getRefRecursiveLocked so symrefs have their Target populated and Type derived from the name, matching the filesystem backend.

Only ErrNotFound errors from resolution are skipped (e.g. dangling symref); other errors are propagated so callers can distinguish I/O failures from missing refs.

func (*MemoryStorage) ListSnapshots

func (ms *MemoryStorage) ListSnapshots(ctx context.Context, opts *storage.ListOptions) ([]*core.SnapshotSummary, error)

ListSnapshots lists all snapshots via lightweight manifests, sorted by timestamp descending, with optional limit/offset pagination. Returns snapshot summaries without file lists — call GetSnapshot for full details.

func (*MemoryStorage) PutChunk

func (ms *MemoryStorage) PutChunk(ctx context.Context, chunk *core.Chunk) error

PutChunk stores a chunk. The chunk data is verified against its declared hash before storing, consistent with the filesystem backend, so a caller-supplied mismatch can never reach the store.

func (*MemoryStorage) PutPreview

func (ms *MemoryStorage) PutPreview(ctx context.Context, hash core.Hash, size int, data []byte) error

PutPreview is a noop stub (Phase 1).

func (*MemoryStorage) PutSnapshot

func (ms *MemoryStorage) PutSnapshot(ctx context.Context, snapshot *core.Snapshot) error

PutSnapshot stores a snapshot and caches its lightweight manifest.

func (*MemoryStorage) SetCompressionConfig

func (ms *MemoryStorage) SetCompressionConfig(enabled bool, level int) error

SetCompressionConfig is a no-op for the in-memory backend, which does not compress chunks. Implementing it satisfies storage.ConfigStorer so porcelain can apply config uniformly across backends without type-asserting to a concrete implementation.

func (*MemoryStorage) SetConfig

func (ms *MemoryStorage) SetConfig(ctx context.Context, config *core.Config) error

SetConfig stores the configuration.

func (*MemoryStorage) SetIndex

func (ms *MemoryStorage) SetIndex(ctx context.Context, index *core.Index) error

SetIndex stores the staging index.

func (*MemoryStorage) SetRef

func (ms *MemoryStorage) SetRef(ctx context.Context, name string, ref *core.Reference) error

SetRef writes a reference.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL