Help us shape the future of Go! Take the 2026 Go Developer Survey

gitstore

package
v0.2.52 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package gitstore is the index behind the chassis `git` personality and the txco://repo/* ops: which repositories a tenant has, which objects each holds (an object id → the content-addressed store's key, with the object's type and size), and where its refs point. The bytes are not here: a git object's content lives in the chassis's content-addressed store (chassis/filecas) under the sha256 of that content, so a blob's key is the file's own hash and the store deduplicates across everything else the chassis keeps. This index is the tenant fence over that shared store: an object is served only when the repository's row names it, never by probing the store on a client's behalf.

Refs move by compare-and-swap, all of a push's refs or none, in one write transaction; every move leaves a log row saying who moved what from where to where (the audit the design asks for: the principal and credential of a push, the stack of an op). There is no garbage collection: objects a ref no longer reaches stay indexed, as the blob plane's do (docs/advanced/blobs.md).

Storage is dialect-aware (registry.Dialect, the seam the drive, calendar and contacts indexes use); the bundled backend is a SQLite file of its own, never the runtime DB (a runtime-DB write reloads the whole dbcache mirror). A fleet overlay registers a shared Postgres backend the same way so the head on any node serves what an op on any node wrote.

Index

Constants

View Source
const ZeroOID = "0000000000000000000000000000000000000000"

ZeroOID is git's "no object": the Old of a ref being created, the New of one being deleted.

Variables

View Source
var (
	// ErrNotFound is a missing repository.
	ErrNotFound = errors.New("gitstore: not found")
)

Functions

func Register

func Register(name string, c Constructor)

Register adds a backend constructor. Called from a backend package's init(): the bundled sqlite one here, an overlay's Postgres one in the service binary.

Types

type Actor

type Actor struct {
	Principal  string
	Credential string
	// Source is "push" or "op".
	Source string
	// Stack is the stack whose op moved the ref ("" for a push).
	Stack string
}

Actor is who moved refs, for the log.

type Config

type Config struct {
	// DBPath is the bundled SQLite backend's file path (--git-db-path).
	DBPath string
}

Config carries the backend-selecting options resolved from chassis config. The bundled "sqlite" backend uses DBPath; a shared backend (the fleet's Postgres overlay) reads its DSN from the environment.

type Constructor

type Constructor func(Config) (*Store, error)

Constructor builds a Store from resolved config. It opens its backing DB and calls Store.EnsureSchema before returning.

type ErrRefMoved

type ErrRefMoved struct {
	Name    string
	Current string
}

ErrRefMoved is the compare-and-swap failure: the ref is not at the Old the writer named. Current is ZeroOID for a ref that does not exist.

func (*ErrRefMoved) Error

func (e *ErrRefMoved) Error() string

type Object

type Object struct {
	OID    string
	Type   string // blob | tree | commit | tag
	Size   int64
	SHA256 string
	// Inline holds the content itself for a small object, when a backend
	// chooses to keep it in the row (nil: the content is in the store).
	Inline []byte
}

Object is one indexed git object: the id, what it is, how big, and where its content is.

type Quotas

type Quotas struct {
	MaxObjectBytes int64
	MaxPackBytes   int64
	MaxRepoBytes   int64
	MaxObjects     int64
}

Quotas are a repository's own caps; zero means "the head's default".

type Ref

type Ref struct {
	Name       string
	OID        string
	UpdatedAt  time.Time
	UpdatedBy  string
	Credential string
}

Ref is one ref.

type RefLogEntry

type RefLogEntry struct {
	ID         string
	Name       string
	Old        string
	New        string
	Principal  string
	Credential string
	Source     string
	Stack      string
	At         time.Time
}

RefLogEntry is one row of the audit log.

type RefUpdate

type RefUpdate struct {
	Name string
	Old  string
	New  string
}

RefUpdate is one move: Old must be the current value (ZeroOID when the ref must not exist), New the value to set (ZeroOID to delete).

type Repo

type Repo struct {
	// ID is `rp_<hxid>`, minted at create.
	ID string
	// Tenant is the tenant slug (the one the hostname resolves to and the
	// ops run as).
	Tenant string
	// Name is the repository's name: the path segment a client clones
	// (`/git/<name>.git`) and the instance of its `git:<name>:*` scopes.
	Name string
	// Principal owns the repository: the identity whose credentials the
	// application issues for it. Recorded for the administrative ops; a
	// push is authorized by its credential's scopes, not by this.
	Principal string
	// CreatedBy is the stack that made the repository: the one that may
	// remove it.
	CreatedBy string
	// PolicyPush is "stack" (a push is accepted only when the tenant's
	// `_git` stack answers ok) or "open" (no lane).
	PolicyPush string
	// Head is the ref HEAD names (refs/heads/main).
	Head      string
	Quotas    Quotas
	CreatedAt time.Time
}

Repo is one repository's row.

type Store

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

Store is the façade over the index tables.

func NewStore

func NewStore(db *sql.DB, d registry.Dialect) *Store

NewStore builds a Store over the opened DB and its dialect. A nil dialect defaults to SQLite.

func Open

func Open(name string, cfg Config) (*Store, error)

Open constructs the named backend. An unknown name is a startup error listing what is available (so a misconfigured --git-store fails loudly).

func OpenSQLiteFile

func OpenSQLiteFile(path string) (*Store, error)

OpenSQLiteFile opens the bundled backend at path (tests and tools).

func (*Store) Close

func (s *Store) Close() error

Close releases the DB handle.

func (*Store) CompareAndSetRefs

func (s *Store) CompareAndSetRefs(ctx context.Context, repoID string, updates []RefUpdate, by Actor) error

CompareAndSetRefs moves refs, all or none: every update's Old must equal the ref's current value (ZeroOID for one that does not exist), or the first mismatch is returned as *ErrRefMoved and nothing changes. A ZeroOID New deletes the ref. Each move leaves a log row naming the actor.

func (*Store) CreateRepo

func (s *Store) CreateRepo(ctx context.Context, r Repo) (Repo, bool, error)

CreateRepo makes the repository, or returns the existing one of that tenant and name (created = false): the create is idempotent so an application may "ensure" a repository. The id is minted here; Head defaults to refs/heads/main, PolicyPush to "stack".

func (*Store) DB

func (s *Store) DB() *sql.DB

DB exposes the handle for tests and backends. Not for request paths.

func (*Store) EnsureSchema

func (s *Store) EnsureSchema(ctx context.Context) error

EnsureSchema creates the tables and indexes if absent. Portable DDL: TEXT ids, TEXT RFC3339 timestamps, BIGINT counters, BYTEA for the one binary column — one DDL serves SQLite and Postgres. Additive-only.

func (*Store) GetObject

func (s *Store) GetObject(ctx context.Context, repoID, oid string) (Object, bool, error)

GetObject finds one object of the repository.

func (*Store) GetRef

func (s *Store) GetRef(ctx context.Context, repoID, name string) (Ref, bool, error)

GetRef finds one ref.

func (*Store) GetRepo

func (s *Store) GetRepo(ctx context.Context, tenant, name string) (Repo, bool, error)

GetRepo finds a tenant's repository by name.

func (*Store) GetRepoByID

func (s *Store) GetRepoByID(ctx context.Context, id string) (Repo, bool, error)

GetRepoByID finds a repository by id.

func (*Store) ListObjects

func (s *Store) ListObjects(ctx context.Context, repoID, typ string) ([]Object, error)

ListObjects lists the repository's objects, of one type or all (""). Metadata only (no inline content).

func (*Store) ListRefs

func (s *Store) ListRefs(ctx context.Context, repoID string) ([]Ref, error)

ListRefs lists the repository's refs by name.

func (*Store) ListRepos

func (s *Store) ListRepos(ctx context.Context, tenant string) ([]Repo, error)

ListRepos lists a tenant's repositories by name.

func (*Store) ObjectStats

func (s *Store) ObjectStats(ctx context.Context, repoID string) (count, bytes int64, err error)

ObjectStats reports how many objects the repository indexes and their total size (the repository's size for the quota).

func (*Store) PutObjects

func (s *Store) PutObjects(ctx context.Context, repoID string, objs []Object) error

PutObjects indexes objects; one already indexed is left alone (the same id is the same content).

func (*Store) RefLog

func (s *Store) RefLog(ctx context.Context, repoID string, limit int) ([]RefLogEntry, error)

RefLog lists the newest moves of a repository's refs, newest first.

func (*Store) RemoveRepo

func (s *Store) RemoveRepo(ctx context.Context, id string) error

RemoveRepo deletes a repository and its index rows (refs, objects, log). The objects' content stays in the content-addressed store. ErrNotFound when there is no such repository.

func (*Store) SetClock

func (s *Store) SetClock(now func() time.Time)

SetClock pins the store's clock (tests).

Jump to

Keyboard shortcuts

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