syncstate

package
v0.22.0 Latest Latest
Warning

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

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

Documentation

Overview

Package syncstate keeps a repo folder's sync state with its orgs: the org revision its files last matched (the base), and a pull that isn't finished (the pending record). docs/designs/publish.md#the-sync-state is its design.

The state lives in the repo, in .anfra/publish/, not in ANFRA_HOME with anfra's other state: it stays true with the folder's files wherever they are, so it moves with them, and a copy carries the base its files match. The folder ignores itself (its own .gitignore holds "*"), so nothing in it is committed, whatever the repo's .gitignore says.

Index

Constants

View Source
const DirName = "publish"

DirName is the sync state's folder, in a repo's .anfra/.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conflict

type Conflict struct {
	Kind  string `json:"kind"`
	Files []File `json:"files"`
	// MarkerSize is the size of the markers written into the file; 0 when it
	// has none, and is resolved only by taking a side.
	MarkerSize int `json:"marker_size,omitempty"`
	// Resolved is set when a side was taken. A conflict with markers is
	// resolved by its file's content, which is checked each time.
	Resolved bool `json:"resolved,omitempty"`
}

Conflict is one of a pull's conflicts, as treemerge reported it.

type File

type File struct {
	Path  string `json:"path"`
	Base  string `json:"base,omitempty"`
	Local string `json:"local,omitempty"`
	Org   string `json:"org,omitempty"`
}

File is one path a conflict covers, with its three versions as blob ids: the base's, this folder's (local) and the org's. "" is absent.

type Folder

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

Folder is a repo folder's sync state, on disk.

func For

func For(repoDir string) Folder

For is the sync state of the repo at repoDir.

func (Folder) BackupDir

func (f Folder) BackupDir() string

BackupDir is where an unfinished pull keeps the files it changed, for undoing it, each named by its blob id (Pending.Before).

func (Folder) Load

func (f Folder) Load() (State, error)

Load reads the sync state. A folder with none has an empty one, or, the first time, the revisions ANFRA_HOME's published.json recorded, as each org's base. Save moves them in.

func (Folder) Lock

func (f Folder) Lock() (release func(), err error)

Lock takes the folder's lock, so two pulls, or a pull and a publish, in one folder don't interleave. It doesn't wait: another one running fails it. The lock goes with the process, so a crash never leaves it held.

func (Folder) Save

func (f Folder) Save(s State) error

Save writes the sync state, replacing what's there in one step, and removes ANFRA_HOME's published.json, whose revisions it now holds.

type Org

type Org struct {
	// Base is the org's revision these files last matched: the one last
	// published, or pulled with no conflicts left.
	Base string `json:"base,omitempty"`
	// Pending is a pull that isn't finished; nil when there's none.
	Pending *Pending `json:"pending,omitempty"`
}

Org is a folder's sync state with one org.

type Pending

type Pending struct {
	// Revision is the org's revision the pull merged: the base once every
	// conflict is resolved.
	Revision  string     `json:"revision"`
	Stage     Stage      `json:"state"`
	Conflicts []Conflict `json:"conflicts,omitempty"`
	// Before is each path the pull wrote or deleted, with its blob id before
	// the pull: its content in the backup, named by that id. "" is a path the
	// pull created. Undoing the pull, or taking the folder's side, puts these
	// back.
	Before map[string]string `json:"before,omitempty"`
}

Pending is a pull that isn't finished.

type Stage

type Stage string

Stage is where an unfinished pull stands.

const (
	// Writing: the pull is writing files. Found later, the pull was stopped
	// partway, and only undoing it gets out.
	Writing Stage = "writing"
	// Conflicted: the pull's files are written, and conflicts are left to
	// resolve.
	Conflicted Stage = "conflicted"
)

type State

type State map[string]*Org

State is a folder's sync state, per org, by the org's address.

Jump to

Keyboard shortcuts

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