reposync

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package reposync diffs a local model's identity-carrying RDF graph against a repository-side graph of the same project scope, keyed by effective element id, so a rename or a move is an update to the existing element rather than a delete plus a create.

Index

Constants

This section is empty.

Variables

View Source
var ErrIncompleteApply = errors.New("the apply did not complete, so the last-seen commit stays where it was")

ErrIncompleteApply refuses to advance the state past an apply that left changes unapplied: no single commit then describes what the branch holds.

View Source
var ErrTwoBranches = errors.New("one document cannot sync against two branches at once")

ErrTwoBranches reports elements of one document naming two branches at once: a branch selects one version, so one sync reads from exactly one.

View Source
var ErrUnnamedCommit = errors.New("the repository accepted the commit but did not name it")

ErrUnnamedCommit is a commit the repository accepted but did not name, so the sync state cannot advance to it.

Functions

func MintUUID

func MintUUID() (string, error)

MintUUID returns a random RFC 4122 version 4 UUID, the id minted for an element that needs addressing but declares none.

func StatePath

func StatePath(modelPath string) string

StatePath is the default state file for a model: its path with .sync.json appended, so two models beside each other keep separate sync state.

func WriteBack

func WriteBack(g *rdf.Graph, mints map[string]string) (*rdf.Graph, error)

WriteBack rewrites a local graph so each minted element declares its minted id: subjects and references move to the minted IRI, satellites re-derive, and the declaredId marker is set so converting the graph back to notation re-materializes the @ElementId annotation. It never runs implicitly: the caller asked to write annotations back into the model. Each collection annotation is restated from its minted typed triples, so the two agree.

Types

type ApplyError added in v0.5.0

type ApplyError struct {
	Batch   int // 1-based index of the refused batch
	Batches int
	Result  *Result
	Err     error
}

ApplyError reports a batch the repository refused, with the result so far: what did reach the repository is committed and stays there.

func (*ApplyError) Error added in v0.5.0

func (e *ApplyError) Error() string

func (*ApplyError) Unwrap added in v0.5.0

func (e *ApplyError) Unwrap() error

type ApplyOptions added in v0.5.0

type ApplyOptions struct {
	// BatchSize splits a set over several commits; 0 writes one commit.
	BatchSize int
	// Message is recorded on each commit.
	Message string
}

ApplyOptions steer an apply.

type Carrier added in v0.5.0

type Carrier interface {
	// Carry maps a triple onto the form the repository stores: ok false when it
	// has no place for the predicate, err when it cannot represent the value.
	Carry(triple rdf.Triple) (carried rdf.Triple, ok bool, err error)
}

Carrier is what a repository can hold of a graph; both sides compare under it, so a successful apply leaves nothing to diff.

type Change

type Change struct {
	Kind          Kind
	ID            string // effective id: the subject IRI's local name
	Subject       string // full subject IRI
	QualifiedName string
	Metaclass     string
	Declared      bool   // the id was declared by an @ElementId annotation
	Normative     bool   // the id is the one the norm fixes for a standard-library element
	MintedID      string // UUID minted for an unannotated create, when minting is on
	Deltas        []PropertyDelta
	Conflict      ConflictKind
	// RequiresConfirmation marks a delete the options did not confirm.
	RequiresConfirmation bool
	// Content is the element as the local graph states it, in the repository's
	// representation: what a create or an update writes. Nil for a delete.
	Content []rdf.Triple
}

Change is one entry of a change set, keyed by the subject's effective id.

type ChangeSet

type ChangeSet struct {
	Scope     Scope
	Changes   []Change
	Uncarried []UncarriedProperty
}

ChangeSet is what a diff produced for one project scope.

func Diff

func Diff(local, repository *rdf.Graph, opts Options) (*ChangeSet, error)

Diff compares the local graph against the repository graph of the same project scope and returns the change set keyed by effective element id.

func (*ChangeSet) Appliable

func (cs *ChangeSet) Appliable() error

Appliable reports whether the set can be applied as computed: conflicts and unconfirmed deletes refuse an apply, as a *NotAppliableError, until a person decides them.

func (*ChangeSet) Conflicts

func (cs *ChangeSet) Conflicts() int

Conflicts counts the entries the sync refuses to resolve on its own.

func (*ChangeSet) Mints

func (cs *ChangeSet) Mints() map[string]string

Mints returns the minted ids of a change set, keyed by the derived id each one replaces.

func (*ChangeSet) Text

func (cs *ChangeSet) Text() string

Text renders the change set for a dry run: one line per entry, deltas indented under updates and conflicts, and a closing summary.

func (*ChangeSet) UnconfirmedDeletes

func (cs *ChangeSet) UnconfirmedDeletes() int

UnconfirmedDeletes counts the deletes the options did not confirm.

type Committer added in v0.5.0

type Committer interface {
	// Commit writes one batch as a single commit and returns the id the
	// repository gave it. A refused batch must leave the branch as it was.
	Commit(ctx context.Context, changes []ElementChange, message string) (string, error)
}

Committer is the write side of one live repository branch as an apply sees it: a fake in tests, the Flexo adapter for real.

type ConflictKind

type ConflictKind string

ConflictKind says what a conflict entry disagrees about.

const (
	// ConflictMissingID: the annotation names an id the repository branch no
	// longer has.
	ConflictMissingID ConflictKind = "missing-id"
	// ConflictRepositoryChanged: the repository element changed since the
	// last-seen commit, so writing over it would lose someone else's change.
	ConflictRepositoryChanged ConflictKind = "repository-changed"
)

type ElementChange added in v0.5.0

type ElementChange struct {
	Kind    Kind
	ID      string       // id the repository addresses the element by, minted when one was
	Content []rdf.Triple // subject, type and carried properties; nil for a delete
}

ElementChange is one element as the repository is to hold it after the commit: whole content for a create or update, nothing for a delete.

type Kind

type Kind string

Kind classifies one entry of a change set.

const (
	// KindCreate is an element the repository does not have yet.
	KindCreate Kind = "create"
	// KindUpdate is an element both sides have, with differing properties.
	KindUpdate Kind = "update"
	// KindDelete is an element only the repository has. Applying it needs
	// explicit confirmation; the diff reports it either way.
	KindDelete Kind = "delete"
	// KindConflict is a disagreement the sync must not resolve on its own.
	KindConflict Kind = "conflict"
)

type NotAppliableError added in v0.5.0

type NotAppliableError struct {
	Conflicts          int
	UnconfirmedDeletes int
}

NotAppliableError refuses an apply: the set holds conflicts, unconfirmed deletes, or both, and a person has to decide them first.

func (*NotAppliableError) Error added in v0.5.0

func (e *NotAppliableError) Error() string

type Options

type Options struct {
	// Base is the repository graph at the last-seen commit. With it, an element
	// the repository changed since then surfaces as a conflict rather than
	// being written over, and a declared id the branch never had is a create
	// rather than a missing-id conflict.
	Base *rdf.Graph
	// ConfirmDeletes confirms repository-side deletes; off, the diff still
	// reports them but Appliable refuses.
	ConfirmDeletes bool
	// MintIDs mints a UUID for each unannotated element being created, so the
	// repository can address it stably.
	MintIDs bool
	// NewID overrides the UUID source, for deterministic tests.
	NewID func() (string, error)
	// Representation is the repository's; nil compares the graphs as written.
	Representation Carrier
}

Options steer a diff. Deletes and id minting are explicit opt-ins; neither ever happens silently.

type PropertyDelta

type PropertyDelta struct {
	Property   string
	Local      []string
	Repository []string
}

PropertyDelta is one property whose values differ between the two sides.

type Result added in v0.5.0

type Result struct {
	Commits []string
	Applied []Change
	Failed  []Change
	Pending []Change
}

Result is what an apply did: its commits, and the fate of each change. Failed changes were in a refused batch; Pending ones were never sent.

func Apply added in v0.5.0

func Apply(ctx context.Context, repo Committer, set *ChangeSet, opts ApplyOptions) (*Result, error)

Apply pushes a change set to the repository. An unappliable set is refused before any write; a rejected batch is reported as an *ApplyError.

func (*Result) Complete added in v0.5.0

func (r *Result) Complete() bool

Complete reports whether every change reached the repository.

func (*Result) LastCommit added in v0.5.0

func (r *Result) LastCommit() string

LastCommit is the newest commit made, the one the sync state advances to.

type Scope

type Scope struct {
	Org       string
	ProjectID string
	Branch    string
}

Scope is the project a graph belongs to. Org and project identify it; branch selects the version being synced against, not a different identity space.

func GraphScope

func GraphScope(g *rdf.Graph) (Scope, error)

GraphScope reads a graph's provenance triples into the single scope it syncs under. Two projects or two branches in one graph is an error, never a guess.

func (Scope) IsZero

func (s Scope) IsZero() bool

IsZero reports whether the scope carries no project at all.

func (Scope) String

func (s Scope) String() string

String renders the scope for reports and error messages.

type State

type State struct {
	Org            string `json:"org,omitempty"`
	ProjectID      string `json:"projectId"`
	Branch         string `json:"branch,omitempty"`
	LastSeenCommit string `json:"lastSeenCommit,omitempty"`
}

State is the sync tool's record of what a sync last saw. Commit ids are tool state, never model content: they live in this JSON file — <model>.sync.json beside the model by default — and are never written into the notation.

func LoadState

func LoadState(path string) (*State, error)

LoadState reads a state file, returning nil without error when the file does not exist yet: a first sync has no last-seen commit.

func (*State) Advance added in v0.5.0

func (s *State) Advance(result *Result) error

Advance records a completed apply's last commit as last seen; an apply that wrote nothing leaves the state as it was.

func (*State) Check

func (s *State) Check(scope Scope) error

Check refuses a state that pins the sync to a different project or branch than the document's own scope: that would sync one element against two branches at once.

func (*State) Save

func (s *State) Save(path string) error

Save writes the state file.

func (*State) Scope

func (s *State) Scope() Scope

Scope returns the scope the state pins the sync to.

type UncarriedProperty added in v0.5.0

type UncarriedProperty struct {
	Property string // rendered as in a delta
	Triples  int
}

UncarriedProperty is a property of the local graph the repository has no place for: left out of the comparison, since no apply could ever settle it.

type UnsupportedKindError added in v0.5.0

type UnsupportedKindError struct {
	Kind Kind
	ID   string
}

UnsupportedKindError is a change of a kind no repository write exists for, such as a conflict that slipped past Appliable.

func (*UnsupportedKindError) Error added in v0.5.0

func (e *UnsupportedKindError) Error() string

type UnwritableChangeError added in v0.5.0

type UnwritableChangeError struct {
	Kind Kind
	ID   string
}

UnwritableChangeError is a create or update the diff carried no content for, so there is nothing the repository could be asked to hold.

func (*UnwritableChangeError) Error added in v0.5.0

func (e *UnwritableChangeError) Error() string

Jump to

Keyboard shortcuts

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