state

package
v0.1.0-alpha3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package state defines and sores the state for gs.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotExist = errors.New("does not exist in store")

ErrNotExist indicates that a key that was expected to exist does not exist.

View Source
var ErrUninitialized = errors.New("store not initialized")

ErrUninitialized indicates that the store is not initialized.

Functions

This section is empty.

Types

type GitRepository

type GitRepository interface {
	PeelToCommit(ctx context.Context, ref string) (git.Hash, error)
	PeelToTree(ctx context.Context, ref string) (git.Hash, error)
	BlobAt(ctx context.Context, treeish, path string) (git.Hash, error)
	TreeAt(ctx context.Context, commitish, path string) (git.Hash, error)

	ReadObject(ctx context.Context, typ git.Type, hash git.Hash, dst io.Writer) error
	WriteObject(ctx context.Context, typ git.Type, src io.Reader) (git.Hash, error)

	ListTree(ctx context.Context, tree git.Hash, opts git.ListTreeOptions) ([]git.TreeEntry, error)
	CommitTree(ctx context.Context, req git.CommitTreeRequest) (git.Hash, error)
	UpdateTree(ctx context.Context, req git.UpdateTreeRequest) (git.Hash, error)
	MakeTree(ctx context.Context, ents []git.TreeEntry) (git.Hash, error)

	SetRef(ctx context.Context, req git.SetRefRequest) error
}

GitRepository is the subset of the git.Repository API used by the state package.

type InitStoreRequest

type InitStoreRequest struct {
	// Repository is the Git repository being initialized.
	// State will be stored in a ref in this repository.
	Repository GitRepository

	// Trunk is the name of the trunk branch,
	// e.g. "main" or "master".
	Trunk string

	// Remote is the name of the remote to use for pushing and pulling.
	// e.g. "origin" or "upstream".
	//
	// If empty, a remote will not be configured and push/pull
	// operations will not be available.
	Remote string

	// Reset indicates that the store's state should be nuked
	// if it's already initialized.
	Reset bool

	// Log is the logger to use for logging.
	Log *log.Logger
}

InitStoreRequest is a request to initialize the store in a Git repository.

type LookupResponse

type LookupResponse struct {
	// Base is the base branch configured
	// for the requested branch.
	Base string

	// BaseHash is the last known hash of the base branch.
	// This may not match the current hash of the base branch.
	BaseHash git.Hash

	// PR is the number of the pull request associated with the branch,
	// or zero if the branch is not associated with a PR.
	PR int

	// UpstreamBranch is the name of the upstream branch
	// or an empty string if the branch is not tracking an upstream branch.
	UpstreamBranch string
}

LookupResponse is the response to a Lookup request.

type Store

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

Store implements storage for state tracked by gs.

func InitStore

func InitStore(ctx context.Context, req InitStoreRequest) (*Store, error)

InitStore initializes the store in the given Git repository. If the repository is already initialized, it will be re-initialized, while retaining existing tracked branches. If Reset is true, existing tracked branches will be cleared.

func OpenStore

func OpenStore(ctx context.Context, repo GitRepository, logger *log.Logger) (*Store, error)

OpenStore opens the Store for the given Git repository.

It returns ErrUninitialized if the repository is not initialized.

func (*Store) List

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

List reports the names of all tracked branches. The list is sorted in lexicographic order.

func (*Store) Lookup

func (s *Store) Lookup(ctx context.Context, name string) (*LookupResponse, error)

Lookup returns information about a tracked branch. If the branch is not found, ErrNotExist will be returned.

func (*Store) Remote

func (s *Store) Remote() (string, error)

Remote returns the remote configured for the repository. Returns ErrNotExist if no remote is configured.

func (*Store) SetRemote

func (s *Store) SetRemote(ctx context.Context, remote string) error

SetRemote changes teh remote name configured for the repository.

func (*Store) Trunk

func (s *Store) Trunk() string

Trunk reports the trunk branch configured for the repository.

func (*Store) Update

func (s *Store) Update(ctx context.Context, req *UpdateRequest) error

Update upates the store with the parameters in the request.

type UpdateRequest

type UpdateRequest struct {
	// Upserts are requests to add or update information about branches.
	Upserts []UpsertRequest

	// Deletes are requests to delete information about branches.
	Deletes []string

	// Message is a message specifying the reason for the update.
	// This will be persisted in the Git commit message.
	Message string
}

UpdateRequest is a request to add, update, or delete information about branches.

type UpsertRequest

type UpsertRequest struct {
	// Name is the name of the branch.
	Name string

	// Base branch to update to.
	//
	// Leave empty to keep the current base.
	Base string

	// BaseHash is the last known hash of the base branch.
	// This is used to detect if the base branch has been updated.
	//
	// Leave empty to keep the current base hash.
	BaseHash git.Hash

	// PR is the number of the pull request associated with the branch.
	// Leave zero to keep the current PR.
	PR int

	// UpstreamBranch is the name of the upstream branch to track.
	// Leave empty to stop tracking an upstream branch.
	UpstreamBranch string
}

UpsertRequest is a request to add or update information about a branch.

Jump to

Keyboard shortcuts

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