refs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeadRef      = "HEAD"
	BranchPrefix = "refs/heads/"
	TagPrefix    = "refs/tags/"
)

Well-known ref prefixes.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB wraps a store.Storage and provides higher-level ref operations: branches, HEAD, tags, reflog, and ref-ish resolution.

func New

func New(s store.Storage) *DB

New returns a DB backed by s.

func (*DB) AppendReflog

func (db *DB) AppendReflog(ctx context.Context, ref string, old, new store.Hash, who string, op, msg string) error

AppendReflog records a ref movement.

func (*DB) CreateBranch

func (db *DB) CreateBranch(ctx context.Context, name string, commit store.Hash) error

CreateBranch creates a new branch pointing at commit.

func (*DB) CreateTag

func (db *DB) CreateTag(ctx context.Context, name string, target store.Hash) error

CreateTag creates a lightweight tag (name -> commit hash).

func (*DB) DeleteBranch

func (db *DB) DeleteBranch(ctx context.Context, name string, expected store.Hash) error

DeleteBranch deletes a branch if it points at expected.

func (*DB) DeleteTag

func (db *DB) DeleteTag(ctx context.Context, name string, expected store.Hash) error

DeleteTag deletes a tag if it points at expected.

func (*DB) GetBranch

func (db *DB) GetBranch(ctx context.Context, name string) (store.Hash, error)

GetBranch returns the hash a branch points to.

func (*DB) GetTag

func (db *DB) GetTag(ctx context.Context, name string) (store.Hash, error)

GetTag returns the hash a tag points to.

func (*DB) ListBranches

func (db *DB) ListBranches(ctx context.Context) ([]string, error)

ListBranches returns all branch names (without the prefix), sorted.

func (*DB) ListTags

func (db *DB) ListTags(ctx context.Context) ([]string, error)

ListTags returns all tag names (without the prefix), sorted.

func (*DB) ReadHEAD

func (db *DB) ReadHEAD(ctx context.Context) (branch string, commit store.Hash, err error)

ReadHEAD returns the current HEAD. HEAD is stored as a symbolic ref whose value is a branch name (e.g. "refs/heads/main"). We store it as a special ref whose "hash" is actually the branch ref name encoded. For v0, we store the branch name in a ref called "HEAD".

Returns the branch name (e.g. "refs/heads/main") and the commit hash that branch points to.

func (*DB) ReadReflog

func (db *DB) ReadReflog(ctx context.Context, ref string) ([]store.ReflogEntry, error)

ReadReflog returns the reflog for a given ref.

func (*DB) Resolve

func (db *DB) Resolve(ctx context.Context, refish string) (store.Hash, error)

Resolve parses a ref-ish string and returns the commit hash it points to.

Supported forms:

  • Full hex hash (64 chars)
  • Branch name: "main" -> looks up refs/heads/main
  • Tag name: "v1.0" -> looks up refs/tags/v1.0
  • "HEAD" -> dereferences HEAD
  • Ancestor: "main~3" or "HEAD~1" -> walks N parents
  • Raw ref path: "refs/heads/main" or "refs/tags/v1.0"

func (*DB) SetHEAD

func (db *DB) SetHEAD(ctx context.Context, branch string) error

SetHEAD points HEAD at the given branch (must include BranchPrefix).

func (*DB) UpdateBranch

func (db *DB) UpdateBranch(ctx context.Context, name string, expected, next store.Hash) error

UpdateBranch moves branch from expected to next (atomic CAS).

Jump to

Keyboard shortcuts

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