Documentation
¶
Index ¶
- Constants
- func BranchRef(zone, branch string) string
- func ParseBranchRef(ref string) (zone, branch string, ok bool)
- func TagRef(zone, tag string) string
- type DB
- func (db *DB) AppendReflog(ctx context.Context, ref string, old, new store.Hash, who string, ...) error
- func (db *DB) CreateBranch(ctx context.Context, zone, name string, commit store.Hash) error
- func (db *DB) CreateTag(ctx context.Context, zone, name string, target store.Hash) error
- func (db *DB) DeleteBranch(ctx context.Context, zone, name string, expected store.Hash) error
- func (db *DB) DeleteTag(ctx context.Context, zone, name string, expected store.Hash) error
- func (db *DB) GetBranch(ctx context.Context, zone, name string) (store.Hash, error)
- func (db *DB) GetTag(ctx context.Context, zone, name string) (store.Hash, error)
- func (db *DB) IsLegacyV03(ctx context.Context) (bool, string, error)
- func (db *DB) IsZoneRegistered(ctx context.Context, zone string) (bool, error)
- func (db *DB) ListBranches(ctx context.Context, zone string) ([]string, error)
- func (db *DB) ListTags(ctx context.Context, zone string) ([]string, error)
- func (db *DB) ListZones(ctx context.Context) ([]string, error)
- func (db *DB) MigrateLegacyV03(ctx context.Context) (bool, string, error)
- func (db *DB) ReadHEAD(ctx context.Context) (zone, branch string, commit store.Hash, err error)
- func (db *DB) ReadReflog(ctx context.Context, ref string) ([]store.ReflogEntry, error)
- func (db *DB) RegisterZone(ctx context.Context, zone string) error
- func (db *DB) Resolve(ctx context.Context, refish string) (store.Hash, error)
- func (db *DB) ResolveInZone(ctx context.Context, zone, refish string) (store.Hash, error)
- func (db *DB) SetHEAD(ctx context.Context, zone, branch string) error
- func (db *DB) UnregisterZone(ctx context.Context, zone string, force bool) error
- func (db *DB) UpdateBranch(ctx context.Context, zone, name string, expected, next store.Hash) error
Constants ¶
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 ParseBranchRef ¶ added in v0.4.0
ParseBranchRef returns (zone, branch, true) if ref is a refs/heads/<zone>/<branch> path, or ("","",false) otherwise.
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 (*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 ¶
CreateBranch creates a new branch pointing at commit.
func (*DB) DeleteBranch ¶
DeleteBranch deletes a branch if it points at expected.
func (*DB) IsLegacyV03 ¶ added in v0.4.0
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
IsZoneRegistered reports whether zone has been registered.
func (*DB) ListBranches ¶
ListBranches returns all branch names in zone (without prefix), sorted.
func (*DB) MigrateLegacyV03 ¶ added in v0.4.0
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 ¶
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 ¶
ReadReflog returns the reflog for a given ref.
func (*DB) RegisterZone ¶ added in v0.4.0
RegisterZone records the existence of a zone in this repo. Idempotent.
func (*DB) Resolve ¶
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
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) UnregisterZone ¶ added in v0.4.0
UnregisterZone removes a zone marker. Refuses if any branches or tags still exist under that zone unless force is true.