git

package
v0.59.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

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

View Source
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:

  1. Call OpenOrCreate to get a worktree.
  2. Write files into Path (using WriteFile or directly).
  3. Call CommitAndPush to commit and push all changes.
  4. 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).

func (*StateWorktree) WriteFile

func (w *StateWorktree) WriteFile(relPath string, data []byte) error

WriteFile writes data to the given relative path inside the worktree, creating intermediate directories as needed.

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

func NewStore(opts Options) (*Store, error)

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) Delete

func (s *Store) Delete(ctx context.Context, key persistence.Key) error

Delete removes the file for key and commits the deletion.

func (*Store) List

func (s *Store) List(ctx context.Context, namespace string) ([]persistence.Key, error)

List returns keys present on the branch under namespace. An empty namespace lists every key on the branch.

func (*Store) Load

Load returns the graph previously stored under key, or persistence.ErrNotFound.

func (*Store) Save

Save commits graph to the configured orphan branch under constructPathForKey(key).

Jump to

Keyboard shortcuts

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