Documentation
¶
Overview ¶
Package git provides a persistence.Store backed by an orphan branch in a git repository. State is written through a git worktree so that the orphan branch files never pollute the application working tree.
This package is composed of two layers:
- worktree.go : low-level StateWorktree primitive (OpenOrCreate / WriteFile / CommitAndPush / Remove). Adapted from the filesystem-state branch implementation.
- git_store.go: Store implementation that maps persistence.Key values to files on the orphan branch and uses StateWorktree for I/O.
Index ¶
- Constants
- type Options
- type StateWorktree
- func (w *StateWorktree) CommitAndPush(ctx context.Context, msg string) error
- func (w *StateWorktree) ReadFile(relPath string) ([]byte, error)
- func (w *StateWorktree) Remove(ctx context.Context)
- func (w *StateWorktree) RemoveFile(relPath string) error
- func (w *StateWorktree) WriteFile(relPath string, data []byte) error
- type Store
- func (s *Store) Delete(ctx context.Context, key persistence.Key) error
- func (s *Store) List(ctx context.Context, namespace string) ([]persistence.Key, error)
- func (s *Store) Load(ctx context.Context, key persistence.Key) (*corerpv20250801preview.ApplicationGraphResponse, error)
- func (s *Store) Save(ctx context.Context, key persistence.Key, ...) error
Constants ¶
const DefaultGraphBranch = "radius-graph"
DefaultGraphBranch is the default orphan branch name for graph artifacts.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Branch is the orphan branch used to persist graphs. If empty,
// DefaultGraphBranch is used.
Branch string
}
Options configures a Store.
type StateWorktree ¶
type StateWorktree struct {
// Path is the absolute path of the worktree directory.
Path string
// contains filtered or unexported fields
}
StateWorktree is a git worktree checked out to an orphan branch in a temporary directory that is completely isolated from the application working tree.
Lifecycle:
- Call OpenOrCreate to get a worktree.
- Write files into Path (using WriteFile or directly).
- Call CommitAndPush to commit and push all changes.
- Always defer Remove to release the worktree.
func OpenOrCreate ¶
func OpenOrCreate(ctx context.Context, branchName string) (*StateWorktree, error)
OpenOrCreate opens a git worktree for branchName, creating the orphan branch if it does not yet exist, and returns the worktree. The worktree is placed in a system temp directory.
The caller must always defer Remove to avoid stale worktree entries.
func (*StateWorktree) CommitAndPush ¶
func (w *StateWorktree) CommitAndPush(ctx context.Context, msg string) error
CommitAndPush stages all changes in the worktree, commits, and pushes.
func (*StateWorktree) ReadFile ¶
func (w *StateWorktree) ReadFile(relPath string) ([]byte, error)
ReadFile returns the contents of relPath inside the worktree.
func (*StateWorktree) Remove ¶
func (w *StateWorktree) Remove(ctx context.Context)
Remove tears down the worktree entry. Always defer this after a successful OpenOrCreate.
func (*StateWorktree) RemoveFile ¶
func (w *StateWorktree) RemoveFile(relPath string) error
RemoveFile deletes relPath from the worktree (without committing).
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a persistence.Store backed by a git orphan branch. Each saved graph is committed as a JSON file on the branch using a StateWorktree, so the application's working tree is never touched.
Key → path layout on the branch:
<namespace>/<name>.json
Concurrency: `git worktree add` refuses to add a second worktree for a branch that is already checked out, so concurrent Save/Load/List/Delete calls on the same Store would otherwise fail nondeterministically. The persistence.Store contract requires implementations to be safe for concurrent use, so all operations are serialized through mu.
func NewStore ¶
NewStore returns a git-backed Store. The repository is auto-detected via `git rev-parse --show-toplevel` at I/O time, so no path is required up front.
func (*Store) List ¶
List returns keys present on the branch under namespace. An empty namespace lists every key on the branch.
func (*Store) Load ¶
func (s *Store) Load(ctx context.Context, key persistence.Key) (*corerpv20250801preview.ApplicationGraphResponse, error)
Load returns the graph previously stored under key, or persistence.ErrNotFound.
func (*Store) Save ¶
func (s *Store) Save(ctx context.Context, key persistence.Key, graph *corerpv20250801preview.ApplicationGraphResponse, opts persistence.SaveOptions) error
Save commits graph to the configured orphan branch under constructPathForKey(key).