storage

package
v0.0.0-...-dc8f43e Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	ReadObject(hash string) ([]byte, error)
	WriteObject(hash string, data []byte) error
	HasObject(hash string) bool
	ListObjects() ([]string, error)
}

type Error

type Error struct {
	Type    string // "not_found", "invalid_object", "io_error", etc.
	Message string
	Cause   error
}

Errors for storage operations

func IOError

func IOError(message string, cause error) *Error

func InvalidObjectError

func InvalidObjectError(message string) *Error

func NotFoundError

func NotFoundError(message string) *Error

Common error constructors

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type FileBackend

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

func NewFileBackend

func NewFileBackend(path string) *FileBackend

func (*FileBackend) HasObject

func (f *FileBackend) HasObject(hash string) bool

func (*FileBackend) ListObjects

func (f *FileBackend) ListObjects() ([]string, error)

func (*FileBackend) ReadObject

func (f *FileBackend) ReadObject(hash string) ([]byte, error)

func (*FileBackend) WriteObject

func (f *FileBackend) WriteObject(hash string, data []byte) error

type HybridObjectStore

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

HybridObjectStore implements memory-first storage with disk backup Objects are kept in memory for speed but also persisted to disk

func NewHybridObjectStore

func NewHybridObjectStore(diskPath string, maxMemory int64) (*HybridObjectStore, error)

NewHybridObjectStore creates a memory-first object store with disk backup

func (*HybridObjectStore) Close

func (s *HybridObjectStore) Close() error

func (*HybridObjectStore) Exists

func (s *HybridObjectStore) Exists(hash string) bool

func (*HybridObjectStore) Get

func (s *HybridObjectStore) Get(hash string) (object.Object, error)

func (*HybridObjectStore) List

func (s *HybridObjectStore) List() ([]string, error)

func (*HybridObjectStore) Put

func (s *HybridObjectStore) Put(obj object.Object) (string, error)

func (*HybridObjectStore) Size

func (s *HybridObjectStore) Size() (int64, error)

type HybridStorageFactory

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

HybridStorageFactory creates hybrid storage instances

func NewHybridStorageFactory

func NewHybridStorageFactory(basePath string) *HybridStorageFactory

NewHybridStorageFactory creates a new hybrid storage factory

func (*HybridStorageFactory) CreateObjectStore

func (f *HybridStorageFactory) CreateObjectStore(config ObjectStoreConfig) (ObjectStore, error)

func (*HybridStorageFactory) CreateRefStore

func (f *HybridStorageFactory) CreateRefStore(config RefStoreConfig) (RefStore, error)

func (*HybridStorageFactory) CreateWorkingStorage

func (f *HybridStorageFactory) CreateWorkingStorage(config WorkingStorageConfig) (WorkingStorage, error)

type MemoryBackend

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

MemoryBackend stores all Git objects in memory. This is the foundation of govc's memory-first approach - no disk I/O means operations complete in microseconds instead of milliseconds. Creating 1000 branches? That's just creating 1000 pointers in a map.

func NewMemoryBackend

func NewMemoryBackend() *MemoryBackend

func (*MemoryBackend) HasObject

func (m *MemoryBackend) HasObject(hash string) bool

func (*MemoryBackend) ListObjects

func (m *MemoryBackend) ListObjects() ([]string, error)

func (*MemoryBackend) ReadObject

func (m *MemoryBackend) ReadObject(hash string) ([]byte, error)

func (*MemoryBackend) WriteObject

func (m *MemoryBackend) WriteObject(hash string, data []byte) error

type MemoryObjectStore

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

MemoryObjectStore implements ObjectStore in memory

func NewMemoryObjectStore

func NewMemoryObjectStore() *MemoryObjectStore

NewMemoryObjectStore creates a new in-memory object store

func (*MemoryObjectStore) Close

func (s *MemoryObjectStore) Close() error

func (*MemoryObjectStore) Exists

func (s *MemoryObjectStore) Exists(hash string) bool

func (*MemoryObjectStore) Get

func (s *MemoryObjectStore) Get(hash string) (object.Object, error)

func (*MemoryObjectStore) List

func (s *MemoryObjectStore) List() ([]string, error)

func (*MemoryObjectStore) Put

func (s *MemoryObjectStore) Put(obj object.Object) (string, error)

func (*MemoryObjectStore) Size

func (s *MemoryObjectStore) Size() (int64, error)

type MemoryRefStore

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

MemoryRefStore implements RefStore in memory

func NewMemoryRefStore

func NewMemoryRefStore() *MemoryRefStore

NewMemoryRefStore creates a new in-memory reference store

func (*MemoryRefStore) Close

func (s *MemoryRefStore) Close() error

func (*MemoryRefStore) DeleteRef

func (s *MemoryRefStore) DeleteRef(name string) error

func (*MemoryRefStore) GetHEAD

func (s *MemoryRefStore) GetHEAD() (string, error)

func (*MemoryRefStore) GetRef

func (s *MemoryRefStore) GetRef(name string) (string, error)

func (*MemoryRefStore) ListRefs

func (s *MemoryRefStore) ListRefs() (map[string]string, error)

func (*MemoryRefStore) SetHEAD

func (s *MemoryRefStore) SetHEAD(target string) error

func (*MemoryRefStore) UpdateRef

func (s *MemoryRefStore) UpdateRef(name string, hash string) error

type MemoryStorageFactory

type MemoryStorageFactory struct{}

MemoryStorageFactory creates memory-based storage instances

func NewMemoryStorageFactory

func NewMemoryStorageFactory() *MemoryStorageFactory

NewMemoryStorageFactory creates a new memory storage factory

func (*MemoryStorageFactory) CreateObjectStore

func (f *MemoryStorageFactory) CreateObjectStore(config ObjectStoreConfig) (ObjectStore, error)

func (*MemoryStorageFactory) CreateRefStore

func (f *MemoryStorageFactory) CreateRefStore(config RefStoreConfig) (RefStore, error)

func (*MemoryStorageFactory) CreateWorkingStorage

func (f *MemoryStorageFactory) CreateWorkingStorage(config WorkingStorageConfig) (WorkingStorage, error)

type MemoryWorkingStorage

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

MemoryWorkingStorage implements WorkingStorage in memory

func NewMemoryWorkingStorage

func NewMemoryWorkingStorage() *MemoryWorkingStorage

NewMemoryWorkingStorage creates a new in-memory working storage

func (*MemoryWorkingStorage) Clear

func (s *MemoryWorkingStorage) Clear() error

func (*MemoryWorkingStorage) Close

func (s *MemoryWorkingStorage) Close() error

func (*MemoryWorkingStorage) Delete

func (s *MemoryWorkingStorage) Delete(path string) error

func (*MemoryWorkingStorage) Exists

func (s *MemoryWorkingStorage) Exists(path string) bool

func (*MemoryWorkingStorage) List

func (s *MemoryWorkingStorage) List() ([]string, error)

func (*MemoryWorkingStorage) Read

func (s *MemoryWorkingStorage) Read(path string) ([]byte, error)

func (*MemoryWorkingStorage) Write

func (s *MemoryWorkingStorage) Write(path string, data []byte) error

type ObjectStore

type ObjectStore interface {
	// Get retrieves an object by its hash
	Get(hash string) (object.Object, error)

	// Put stores an object and returns its hash
	Put(obj object.Object) (string, error)

	// Exists checks if an object exists without retrieving it
	Exists(hash string) bool

	// List returns all object hashes (for debugging/maintenance)
	List() ([]string, error)

	// Size returns the storage size metrics
	Size() (int64, error)

	// Close releases any resources held by the store
	Close() error
}

ObjectStore handles immutable Git objects (commits, trees, blobs) This is the core of Git's content-addressable storage

func NewFileObjectStore

func NewFileObjectStore(path string) ObjectStore

NewFileObjectStore creates a file-backed ObjectStore

func NewMemoryObjectStoreFromStore

func NewMemoryObjectStoreFromStore() ObjectStore

NewMemoryObjectStoreFromStore creates a memory-only ObjectStore

func NewObjectStoreFromBackend

func NewObjectStoreFromBackend(backend Backend) ObjectStore

NewObjectStoreFromBackend creates an ObjectStore from a Backend

type ObjectStoreConfig

type ObjectStoreConfig struct {
	Type      string                 // "memory", "disk", "hybrid"
	Path      string                 // For disk storage
	MaxMemory int64                  // For hybrid storage
	Options   map[string]interface{} // Backend-specific options
}

type PackFile

type PackFile struct {
	Version    uint32
	NumObjects uint32
	Objects    []PackedObject
}

type PackedObject

type PackedObject struct {
	Type   object.Type
	Size   uint64
	Offset uint64
	Data   []byte
}

type RefManagerAdapter

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

RefManagerAdapter adapts the existing RefManager to implement storage.RefStore interface This provides backward compatibility while transitioning to the new architecture

func NewRefManagerAdapter

func NewRefManagerAdapter(manager *refs.RefManager) *RefManagerAdapter

NewRefManagerAdapter creates a RefStore adapter for the existing RefManager

func (*RefManagerAdapter) Close

func (a *RefManagerAdapter) Close() error

func (*RefManagerAdapter) DeleteRef

func (a *RefManagerAdapter) DeleteRef(name string) error

func (*RefManagerAdapter) GetHEAD

func (a *RefManagerAdapter) GetHEAD() (string, error)

func (*RefManagerAdapter) GetRef

func (a *RefManagerAdapter) GetRef(name string) (string, error)

func (*RefManagerAdapter) ListRefs

func (a *RefManagerAdapter) ListRefs() (map[string]string, error)

func (*RefManagerAdapter) SetHEAD

func (a *RefManagerAdapter) SetHEAD(target string) error

func (*RefManagerAdapter) UpdateRef

func (a *RefManagerAdapter) UpdateRef(name string, hash string) error

type RefStore

type RefStore interface {
	// GetRef returns the hash that a reference points to
	GetRef(name string) (string, error)

	// UpdateRef updates a reference to point to a new hash
	UpdateRef(name string, hash string) error

	// DeleteRef removes a reference
	DeleteRef(name string) error

	// ListRefs returns all references with their target hashes
	ListRefs() (map[string]string, error)

	// GetHEAD returns what HEAD points to (branch name or commit hash)
	GetHEAD() (string, error)

	// SetHEAD updates HEAD to point to a branch or commit
	SetHEAD(target string) error

	// Close releases any resources held by the store
	Close() error
}

RefStore handles mutable references (branches, tags, HEAD) These are pointers to commits in the object store

func NewFileRefStore

func NewFileRefStore(path string) RefStore

NewFileRefStore creates a file-backed RefStore using the refs package

func NewFileRefStoreAdapter

func NewFileRefStoreAdapter(path string) RefStore

NewFileRefStoreAdapter creates a file-backed RefStore using refs.FileRefStore

func NewMemoryRefStoreAdapter

func NewMemoryRefStoreAdapter() RefStore

NewMemoryRefStoreAdapter creates a memory-only RefStore using refs.MemoryRefStore

func NewMemoryRefStoreFromRefs

func NewMemoryRefStoreFromRefs() RefStore

NewMemoryRefStoreFromRefs creates a memory-only RefStore using the refs package

func NewRefStoreFromRefsStore

func NewRefStoreFromRefsStore(refStore refs.RefStore) RefStore

NewRefStoreFromRefsStore creates a storage.RefStore from a refs.RefStore

type RefStoreConfig

type RefStoreConfig struct {
	Type    string                 // "memory", "disk", "hybrid"
	Path    string                 // For disk storage
	Options map[string]interface{} // Backend-specific options
}

type RefsStoreAdapter

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

RefsStoreAdapter adapts refs.RefStore to implement storage.RefStore interface This provides a more direct bridge between the two interfaces

func NewRefsStoreAdapter

func NewRefsStoreAdapter(store refs.RefStore) *RefsStoreAdapter

NewRefsStoreAdapter creates a storage.RefStore adapter for refs.RefStore

func (*RefsStoreAdapter) Close

func (a *RefsStoreAdapter) Close() error

func (*RefsStoreAdapter) DeleteRef

func (a *RefsStoreAdapter) DeleteRef(name string) error

func (*RefsStoreAdapter) GetHEAD

func (a *RefsStoreAdapter) GetHEAD() (string, error)

func (*RefsStoreAdapter) GetRef

func (a *RefsStoreAdapter) GetRef(name string) (string, error)

func (*RefsStoreAdapter) ListRefs

func (a *RefsStoreAdapter) ListRefs() (map[string]string, error)

func (*RefsStoreAdapter) SetHEAD

func (a *RefsStoreAdapter) SetHEAD(target string) error

func (*RefsStoreAdapter) UpdateRef

func (a *RefsStoreAdapter) UpdateRef(name string, hash string) error

type StorageFactory

type StorageFactory interface {
	// CreateObjectStore creates an object store with the given configuration
	CreateObjectStore(config ObjectStoreConfig) (ObjectStore, error)

	// CreateRefStore creates a reference store with the given configuration
	CreateRefStore(config RefStoreConfig) (RefStore, error)

	// CreateWorkingStorage creates working storage with the given configuration
	CreateWorkingStorage(config WorkingStorageConfig) (WorkingStorage, error)
}

StorageFactory creates storage instances This allows different storage backends (memory, disk, hybrid)

type Store

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

Store provides a unified interface to Git objects. The key innovation: cache isn't just for performance, it's the primary storage layer. The backend is optional - you can run entirely in memory. This enables use cases like testing infrastructure changes without ever touching disk.

func NewStore

func NewStore(backend Backend) *Store

func (*Store) GetAllObjects

func (s *Store) GetAllObjects() ([]object.Object, error)

GetAllObjects returns all objects in the store

func (*Store) GetBlob

func (s *Store) GetBlob(hash string) (*object.Blob, error)

func (*Store) GetCommit

func (s *Store) GetCommit(hash string) (*object.Commit, error)

func (*Store) GetObject

func (s *Store) GetObject(hash string) (object.Object, error)

func (*Store) GetTag

func (s *Store) GetTag(hash string) (*object.Tag, error)

func (*Store) GetTree

func (s *Store) GetTree(hash string) (*object.Tree, error)

func (*Store) HasObject

func (s *Store) HasObject(hash string) bool

func (*Store) ListObjects

func (s *Store) ListObjects() ([]string, error)

func (*Store) ReadPack

func (s *Store) ReadPack(r io.Reader) error

func (*Store) SetMemoryPool

func (s *Store) SetMemoryPool(pool interface{})

SetMemoryPool sets the memory pool for optimized allocations

func (*Store) StoreBlob

func (s *Store) StoreBlob(content []byte) (string, error)

func (*Store) StoreCommit

func (s *Store) StoreCommit(commit *object.Commit) (string, error)

func (*Store) StoreObject

func (s *Store) StoreObject(obj object.Object) (string, error)

func (*Store) StoreTag

func (s *Store) StoreTag(tag *object.Tag) (string, error)

func (*Store) StoreTree

func (s *Store) StoreTree(tree *object.Tree) (string, error)

func (*Store) WritePack

func (s *Store) WritePack(w io.Writer, hashes []string) error

type StoreAdapter

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

StoreAdapter adapts the existing Store to implement ObjectStore interface This provides backward compatibility while transitioning to the new architecture

func NewStoreAdapter

func NewStoreAdapter(store *Store) *StoreAdapter

NewStoreAdapter creates an ObjectStore adapter for the existing Store

func (*StoreAdapter) Close

func (a *StoreAdapter) Close() error

func (*StoreAdapter) Exists

func (a *StoreAdapter) Exists(hash string) bool

func (*StoreAdapter) Get

func (a *StoreAdapter) Get(hash string) (object.Object, error)

func (*StoreAdapter) List

func (a *StoreAdapter) List() ([]string, error)

func (*StoreAdapter) Put

func (a *StoreAdapter) Put(obj object.Object) (string, error)

func (*StoreAdapter) Size

func (a *StoreAdapter) Size() (int64, error)

type WorkingStorage

type WorkingStorage interface {
	// Read retrieves file content from the working directory
	Read(path string) ([]byte, error)

	// Write stores file content in the working directory
	Write(path string, data []byte) error

	// Delete removes a file from the working directory
	Delete(path string) error

	// List returns all files in the working directory
	List() ([]string, error)

	// Clear removes all files from the working directory
	Clear() error

	// Exists checks if a file exists
	Exists(path string) bool

	// Close releases any resources held by the storage
	Close() error
}

WorkingStorage handles mutable working directory content This is separate from Git objects and can be cleared/restored

type WorkingStorageConfig

type WorkingStorageConfig struct {
	Type    string                 // "memory", "disk", "hybrid"
	Path    string                 // For disk storage
	Options map[string]interface{} // Backend-specific options
}

Jump to

Keyboard shortcuts

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