Documentation
¶
Overview ¶
Package store defines the only persistence seam in zonegit.
Every zonegit storage backend (in-memory, Badger, Postgres, ...) implements the Storage interface. Nothing above this package knows or cares which backend is in use. See docs/ARCHITECTURE.md section 2 for the design rationale.
Index ¶
Constants ¶
const HashSize = 32
HashSize is the length of an object hash in bytes (SHA-256).
Variables ¶
var ( // ErrNotFound is returned by Get* when the object or ref does not exist. ErrNotFound = errors.New("not found") // ErrConflict is returned by CASRef when the expected value did not match. ErrConflict = errors.New("ref cas conflict") // ErrCorrupt is returned when a stored object's bytes do not match its hash. ErrCorrupt = errors.New("corrupt object") // ErrInvalidObject is returned when an object's kind or payload is malformed. ErrInvalidObject = errors.New("invalid object") )
Sentinel errors. Implementations MUST return these (wrapped with fmt.Errorf("...: %w", ...)) so callers can errors.Is against them.
Functions ¶
This section is empty.
Types ¶
type Hash ¶
Hash is the content address of an immutable object.
var ZeroHash Hash
ZeroHash is the all-zeros sentinel meaning "no object" / "create-if-absent".
func ParseHash ¶
ParseHash decodes a hex-encoded hash (full length only — short hashes are resolved at a higher layer where prefix matching against an index is possible).
type Object ¶
Object is the kind+payload of a content-addressable object.
Payload is the canonical bytes WITHOUT the "<kind> <length>\x00" header described in docs/OBJECT_MODEL.md section 3. The header is regenerated on the fly during hashing so the on-disk representation can be optimized per backend without changing the hash.
type ReflogEntry ¶
type ReflogEntry struct {
Old Hash
New Hash
Author string // "name <email>"
UnixTime int64
TZOffset int // minutes east of UTC
Op string // "commit" | "merge" | "revert" | "reset" | "branch" | ...
Message string
}
ReflogEntry records one ref movement for forensic recovery.
type Storage ¶
type Storage interface {
// Object CAS (immutable).
PutObject(ctx context.Context, h Hash, o Object) error
GetObject(ctx context.Context, h Hash) (Object, error)
HasObject(ctx context.Context, h Hash) (bool, error)
IterObjects(ctx context.Context, fn func(Hash, Object) error) error
// Refs (mutable, atomic).
GetRef(ctx context.Context, name string) (h Hash, ok bool, err error)
// CASRef updates name from expected to next iff the current value still
// equals expected. A zero expected Hash means "create only if absent".
CASRef(ctx context.Context, name string, expected, next Hash) error
DeleteRef(ctx context.Context, name string, expected Hash) error
ListRefs(ctx context.Context, prefix string) ([]RefEntry, error)
// Reflog (append-only).
AppendReflog(ctx context.Context, name string, e ReflogEntry) error
ReadReflog(ctx context.Context, name string) ([]ReflogEntry, error)
Close() error
}
Storage is the contract every backend implements.
Implementations MUST be safe for concurrent use. Object writes are idempotent: writing the same hash twice is not an error. Ref updates are atomic via CAS.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package memstore is an in-memory implementation of store.Storage used for tests, demos, and embedded scenarios where durability is not required.
|
Package memstore is an in-memory implementation of store.Storage used for tests, demos, and embedded scenarios where durability is not required. |