refs

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeadRef          = "HEAD"
	BranchPrefix     = "refs/heads/"
	TagPrefix        = "refs/tags/"
	ZoneMarkerPrefix = "refs/zonegit/zones/"

	// LegacyZoneNameRef is the v0.3 single-zone marker. v0.4 detects it
	// on Open and refuses to proceed without migration. Kept as a constant
	// for that detection path.
	LegacyZoneNameRef = "refs/zonegit/zone"
)

Well-known ref prefixes.

v0.4 introduces multi-zone repos. Every branch and tag is scoped under its zone:

refs/heads/<zone>/<branch>     # branch tips
refs/tags/<zone>/<tag>         # tags
refs/zonegit/zones/<zone>      # presence marker for zone enumeration
HEAD                           # symbolic ref, encodes "<zone>/<branch>"

Zone names are canonical FQDNs with trailing dot (e.g. "foo.com."). They participate verbatim in ref paths; the trailing dot makes a zone segment unambiguous against a branch named like the zone.

Variables

This section is empty.

Functions

func BranchRef added in v0.4.0

func BranchRef(zone, branch string) string

BranchRef builds the full ref path for (zone, branch).

func ParseBranchRef added in v0.4.0

func ParseBranchRef(ref string) (zone, branch string, ok bool)

ParseBranchRef returns (zone, branch, true) if ref is a refs/heads/<zone>/<branch> path, or ("","",false) otherwise.

func TagRef added in v0.4.0

func TagRef(zone, tag string) string

TagRef builds the full ref path for (zone, tag).

Types

type DB

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

DB wraps a store.Storage and provides higher-level ref operations: zones, 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, zone, name string, commit store.Hash) error

CreateBranch creates a new branch pointing at commit.

func (*DB) CreateTag

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

CreateTag creates a lightweight tag.

func (*DB) DeleteBranch

func (db *DB) DeleteBranch(ctx context.Context, zone, 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, zone, 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, zone, name string) (store.Hash, error)

GetBranch returns the hash a branch points to.

func (*DB) GetTag

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

GetTag returns the hash a tag points to.

func (*DB) IsLegacyV03 added in v0.4.0

func (db *DB) IsLegacyV03(ctx context.Context) (bool, string, error)

IsLegacyV03 reports whether this repo was created by zonegit v0.3 or earlier (single-zone layout) and has not yet been migrated. Used by pkg/repo.Open to emit a clear, actionable error.

func (*DB) IsZoneRegistered added in v0.4.0

func (db *DB) IsZoneRegistered(ctx context.Context, zone string) (bool, error)

IsZoneRegistered reports whether zone has been registered.

func (*DB) ListBranches

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

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

func (*DB) ListTags

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

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

func (*DB) ListZones added in v0.4.0

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

ListZones returns all registered zones, sorted.

func (*DB) MigrateLegacyV03 added in v0.4.0

func (db *DB) MigrateLegacyV03(ctx context.Context) (bool, string, error)

MigrateLegacyV03 converts a v0.3 single-zone repo to the v0.4 multi-zone layout in place.

What changes:

  • refs/heads/<branch> → refs/heads/<zone>/<branch>
  • refs/tags/<tag> → refs/tags/<zone>/<tag>
  • HEAD (length-prefix legacy slot) → KindSymref object pointing at the new branch path
  • refs/zonegit/zones/<zone> created (zone registration)
  • refs/zonegit/zone deleted (legacy marker)

The function is idempotent: if no migration is needed, it returns (migrated=false, zone="") with no error.

Ordering matters for crash safety: each refs.* entry is copied to the new location first, then the old name is deleted. If we crash partway, the worst case is some orphan legacy refs alongside the new refs — both are reachable, the daemon only consults the new ones, and a future migration run cleans them up.

func (*DB) ReadHEAD

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

ReadHEAD returns (zone, branch, commit). commit may be ZeroHash for an orphan branch (branch exists symbolically but has no commits yet).

Returns store.ErrNotFound if HEAD is not set.

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) RegisterZone added in v0.4.0

func (db *DB) RegisterZone(ctx context.Context, zone string) error

RegisterZone records the existence of a zone in this repo. Idempotent.

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)
  • "HEAD" / "HEAD~N"
  • Bare branch name "main" — resolved within the active zone
  • Zone-qualified branch "foo.com./main" — explicit zone
  • Tag name "v1" — within the active zone
  • Full ref path "refs/heads/foo.com./main" or "refs/tags/foo.com./v1"

Multi-zone-aware: bare names use the active zone derived from HEAD. Pass ResolveInZone for cross-zone resolution.

func (*DB) ResolveInZone added in v0.4.0

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

ResolveInZone is like Resolve but pins bare branch / tag lookups to the given zone instead of reading HEAD. Useful for the CLI's --zone override.

func (*DB) SetHEAD

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

SetHEAD points HEAD at refs/heads/<zone>/<branch>. No length limit.

func (*DB) UnregisterZone added in v0.4.0

func (db *DB) UnregisterZone(ctx context.Context, zone string, force bool) error

UnregisterZone removes a zone marker. Refuses if any branches or tags still exist under that zone unless force is true.

func (*DB) UpdateBranch

func (db *DB) UpdateBranch(ctx context.Context, zone, 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