transfer

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package transfer implements the wire-format for moving repository state between two stores. A Bundle carries everything needed to reproduce part of a repository: content-addressed objects (global, deduplicated), per-repo snapshots, changes, and refs. It is used both for export/import to a file and for the EasyVCS smart protocol between the CLI and the server.

Index

Constants

View Source
const Version = 1

Version is the bundle format version.

Variables

This section is empty.

Functions

func Apply

func Apply(repo *store.Repo, b *Bundle) (int, error)

Apply writes the contents of a bundle into a repository atomically: objects, snapshots, revisions, and refs all land in a single transaction or none do. It returns the number of changes written.

func ApplyTx

func ApplyTx(repo *store.Repo, b *Bundle) (int, error)

ApplyTx writes the contents of a bundle into a repository within a single transaction: objects, snapshots, revisions, and refs either all land or none do. On error the transaction is rolled back. It returns the number of changes written.

func CheckNonFastForward

func CheckNonFastForward(repo *store.Repo, expected []*store.Ref, incoming []*store.Ref, bundle *Bundle) []*store.Ref

CheckNonFastForward compares the refs the client expects on the server (expected) against the refs the client is about to push (incoming). For each incoming branch that would make an existing server branch move non-fast forward (i.e. the incoming target is not a descendant of the expected target), it is recorded in the returned conflict list. A nil/empty conflict list means the update is a pure fast-forward (or the branch is new/unchanged).

The incoming target revision may not be stored in repo yet (it is coming in the bundle), so we additionally accept the incoming bundle's snapshots to resolve the incoming tip's ancestry. reachable uses repo's snapshot graph for revisions it already knows and the bundle's snapshots for new ones.

func CompressBundle

func CompressBundle(b *Bundle) ([]byte, error)

CompressBundle encodes a bundle to its binary frame and gzip-compresses it.

func EnumerateObjectIDs

func EnumerateObjectIDs(repo *store.Repo) ([]object.ID, error)

EnumerateObjectIDs returns every content-addressed object id in a repository. It is used by a client to advertise "have" objects so a peer can compute a delta (send only objects it does not already have).

func IsAncestor

func IsAncestor(repo *store.Repo, a string, b string) (bool, error)

IsAncestor reports whether revision `a` is an ancestor of (or equal to) revision `b` by walking the snapshot graph in the given repo (all parent edges, breadth-first). It is the store-level building block for fast-forward checks and does not depend on a workspace. This lets both the client (pre-check) and a server (authoritative check) use the same logic with no network.

func PutRefTx

func PutRefTx(tx *gorm.DB, r *store.Ref, repo *store.Repo) error

PutRefTx upserts a ref within an open transaction, scoped to repo.

Types

type Bundle

type Bundle struct {
	Version   int               `json:"version"`
	Repo      store.RepoRef     `json:"repo"`
	Revisions []*store.Revision `json:"changes"`
	Snapshots []*store.Snapshot `json:"snapshots"`
	Refs      []*store.Ref      `json:"refs"`
	Objects   []ObjectRecord    `json:"objects"`
	// ExpectedRefs, when set on a push, carries the client's assumption of the
	// server's current branch targets. The server uses it to reject a
	// non-fast-forward update (see CheckNonFastForward). Omit-empty keeps the
	// wire format backward compatible.
	ExpectedRefs []*store.Ref `json:"expected_refs,omitempty"`
}

Bundle is a serializable slice of a repository.

func Collect

func Collect(repo *store.Repo, have []string, hasObject func(id object.ID) bool) (*Bundle, error)

Collect produces a Bundle containing every revision, snapshot, ref, and any object referenced by those snapshots. When `have` is non-nil, objects that already exist in the destination (per hasObject) are skipped; this yields a delta rather than the full bundle.

hasObject, if non-nil, reports whether a given content id already exists at the destination. When nil, all reachable objects are included.

func CollectAll

func CollectAll(repo *store.Repo) (*Bundle, error)

CollectAll returns a full bundle (no delta skipping).

func FilterBundleWant

func FilterBundleWant(b *Bundle, wanted map[string]bool) *Bundle

FilterBundleWant returns a new Bundle that keeps only the revisions whose id is in `wanted` (and their snapshots). It is used by server-side selective fetch when a client requests specific revisions. A nil/empty wanted set is a no-op (returns the bundle unchanged).

func UnmarshalBinary

func UnmarshalBinary(data []byte) (*Bundle, error)

UnmarshalBinary decodes a bundle produced by MarshalBinary. If data is a gzip stream (starts with the gzip magic 0x1f 0x8b), it is decompressed first.

func (*Bundle) MarshalBinary

func (b *Bundle) MarshalBinary() ([]byte, error)

MarshalBinary encodes a bundle into a self-describing binary frame: a JSON metadata header (repo, changes, snapshots, refs, object descriptors) followed by the raw object contents. This avoids the ~33% base64 overhead of putting object content in JSON. It is optionally gzip-compressed by the caller.

type Collector

type Collector interface {
	Repo() *store.Repo
}

Collector collects reachable objects from a repository.

type NonFastForwardError

type NonFastForwardError struct {
	// ConflictingRefs are the branch refs that would be non-fast-forwarded.
	ConflictingRefs []*store.Ref
	// LocalRefs are the refs the client was pushing (for the message).
	LocalRefs []*store.Ref
}

NonFastForwardError describes a push that would move a branch backwards or rewrite history, and is therefore rejected. It carries the conflicting refs so the client can pull/merge before retrying.

func (*NonFastForwardError) Error

func (e *NonFastForwardError) Error() string

type ObjectRecord

type ObjectRecord struct {
	Kind    object.Kind `json:"kind"`
	Content []byte      `json:"content"`
}

ObjectRecord is an encoded content-addressed object.

func CollectObjectsWhere

func CollectObjectsWhere(repo *store.Repo, root object.ID, hasObject func(id object.ID) bool) ([]ObjectRecord, error)

CollectObjectsWhere collects only the objects reachable from a snapshot tree that are NOT already present (per hasObject), returning them as records. This is a low-level helper used by server-side fetch to skip known objects.

Jump to

Keyboard shortcuts

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