reposync

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 8 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 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.

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

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.

Types

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
	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
}

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

type ChangeSet

type ChangeSet struct {
	Scope   Scope
	Changes []Change
}

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 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 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 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 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)
}

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 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) 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.

Jump to

Keyboard shortcuts

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