Documentation
¶
Overview ¶
Package pail reads and writes pail repositories in an object store, in the formats the Rust pail writes (src/hash.rs, enc.rs, pack.rs, manifest.rs, objects.rs): a Go program and the pail CLI can share one bucket.
Index ¶
- Constants
- Variables
- func BuildTree(entries []Entry) (Hash, []BuiltPage, error)
- func BuildUpper(children []Child) (Hash, []BuiltPage, error)
- func ChunkKey(h Hash) string
- func ChunkSpans(data []byte) [][2]int
- func CommitKey(h Hash) string
- func DecodeBlob(stored []byte, rawLen uint64) ([]byte, error)
- func EncodeBlob(raw []byte) []byte
- func EncodeChanges(changes map[string]FileChange) (json.RawMessage, error)
- func EncodePage(p *Page) ([]byte, error)
- func NowDate() string
- func PackKey(h Hash) string
- func PageKey(h Hash) string
- func ParseChanges(raw json.RawMessage) (map[string]FileChange, error)
- func RefKey(branch string) string
- func ReflogKey(branch, id string) string
- func ValidateBranch(name string) error
- type BuiltPage
- type Change
- type Child
- type ChunkRef
- type Commit
- type Entry
- type FileChange
- type FileState
- type Hash
- type Kind
- type Landed
- type Lineage
- type Loc
- type LocKind
- type LogEntry
- type PackBlob
- type PackBuilder
- type Page
- type Ref
- type RefValue
- type Repo
- func (r *Repo) Commit(ctx context.Context, id Hash) (*Commit, error)
- func (r *Repo) DefaultBranch(ctx context.Context) (string, error)
- func (r *Repo) Diff(ctx context.Context, a, b Hash) ([]Change, error)
- func (r *Repo) Entries(ctx context.Context, root Hash) ([]Entry, error)
- func (r *Repo) Entry(ctx context.Context, root Hash, path string) (Entry, bool, error)
- func (r *Repo) LeafRefs(ctx context.Context, root Hash) ([]Child, error)
- func (r *Repo) ListRefs(ctx context.Context) ([]Ref, error)
- func (r *Repo) Log(ctx context.Context, start Hash, n int) ([]LogEntry, error)
- func (r *Repo) Page(ctx context.Context, h Hash) (*Page, error)
- func (r *Repo) ReadFile(ctx context.Context, e Entry) ([]byte, error)
- func (r *Repo) ReadRef(ctx context.Context, branch string) (ref *RefValue, v store.Version, ok bool, err error)
- type Rewrite
Constants ¶
const ( // InlineMax is the largest file stored inside its manifest entry. InlineMax = 64 // ChunkThreshold is the smallest file split into chunks instead of packed. ChunkThreshold = 1 << 20 // PackMax is the size at which a pack is closed. PackMax = 64 << 20 )
const MaintenanceMeta = "pail.maintenance"
MaintenanceMeta marks a commit that changes how files are stored, not what they are.
Variables ¶
var ( // ErrNotFound: an object, ref or path that does not exist. ErrNotFound = errors.New("pail: not found") // ErrCorrupt: an object that does not decode, or does not match its hash. ErrCorrupt = errors.New("pail: corrupt object") // ErrLimit: an object larger than the reader allows. ErrLimit = errors.New("pail: limit exceeded") )
var EmptyRoot = func() Hash { b, _ := BuildPage(&Page{}) return b.Hash }()
EmptyRoot is the root of the empty tree: a leaf with no entries. It is never stored.
Functions ¶
func BuildTree ¶
BuildTree builds every page of a tree holding entries, sorted by path, and returns its root.
func BuildUpper ¶
BuildUpper builds the internal levels above an ordered, complete list of leaves and returns the root with every internal page built.
func ChunkSpans ¶
ChunkSpans splits data into (offset, length) chunks.
func DecodeBlob ¶
DecodeBlob is EncodeBlob's inverse; rawLen is the file's size, which bounds the output.
func EncodeBlob ¶
EncodeBlob stores raw: zstd when that saves at least 5%, raw otherwise.
func EncodeChanges ¶
func EncodeChanges(changes map[string]FileChange) (json.RawMessage, error)
EncodeChanges is a change list as a commit stores it (objects.rs Changes::new).
func EncodePage ¶
EncodePage is a page's canonical encoding, the bytes its hash covers. It refuses what the Rust pail could not read back: keys that are not UTF-8 or not in order, unknown kinds.
func NowDate ¶
func NowDate() string
NowDate is the current time as a Git-style date, "<unix seconds> +0000". PAIL_DATE ("<unix seconds> [<+zone>]") stands in for it, as in the Rust pail.
func ParseChanges ¶
func ParseChanges(raw json.RawMessage) (map[string]FileChange, error)
ParseChanges reads a commit's change list.
func ValidateBranch ¶
ValidateBranch checks a branch name as pail does: ASCII letters, digits and -_./, no empty, . or .. segment.
Types ¶
type BuiltPage ¶
type BuiltPage struct {
Hash Hash
// Data is the zstd-compressed encoding, as stored at pages/<hash>.
Data []byte
Page *Page
}
BuiltPage is a page ready to upload.
func BuildLeaves ¶
BuildLeaves builds the leaf pages of a sorted run of entries that starts on a boundary.
type Change ¶
Change is one path's change between two trees.
func DiffSorted ¶
DiffSorted merge-joins two sorted entry lists into the changes from a to b.
type Child ¶
type Child struct {
// Key is the largest path in the child's subtree.
Key string
Hash Hash
Files uint64
Bytes uint64
}
Child is an internal page's reference to a child page.
type Commit ¶
type Commit struct {
Parent *Hash `json:"parent"`
// Root is the manifest's root page.
Root Hash `json:"root"`
// Generation is the depth in history; a root commit is 0.
Generation uint64 `json:"generation"`
Files uint64 `json:"files"`
Bytes uint64 `json:"bytes"`
// Author and Committer are "Name <email>"; dates are "<unix seconds> <+hhmm>".
Author string `json:"author"`
AuthorDate string `json:"author_date"`
Committer string `json:"committer"`
CommitterDate string `json:"committer_date"`
Message string `json:"message"`
Meta map[string]string `json:"meta,omitempty"`
// Changes lists every path the commit changed against its parent, kept as the JSON it
// was stored as; nil in commits written before change lists.
Changes json.RawMessage `json:"changes,omitempty"`
}
Commit is one commit. Linear history: at most one parent.
func DecodeCommit ¶
DecodeCommit checks data against the commit's id and decodes it.
func (*Commit) ChangeList ¶
ChangeList is the commit's changes in path order, or nil if it records none.
func (*Commit) Encode ¶
Encode is the commit's stored bytes and id, the bytes serde_json writes for it.
func (*Commit) IsMaintenance ¶
IsMaintenance reports whether the commit is maintenance (a repack), not work.
type Entry ¶
Entry is one file in a manifest.
func (Entry) SameContent ¶
SameContent reports whether two entries are the same file to a user: kind and content.
type FileChange ¶
type FileChange struct {
Old, New *FileState
}
FileChange is one path's change: nil Old is an add, nil New a delete.
type FileState ¶
type FileState struct {
Kind Kind
Size uint64
Hash Hash
// Loc is where its bytes live; Unresolved for an old side, which carries none.
Loc Loc
}
FileState is one version of a file in a change list.
type Hash ¶
type Hash [32]byte
Hash is a BLAKE3 content hash: the identity of every immutable object and of file content.
func (Hash) MarshalText ¶
MarshalText writes the hash as hex, so JSON carries it as a string.
func (*Hash) UnmarshalText ¶
UnmarshalText reads a hex hash.
type Lineage ¶
type Lineage struct {
Epoch uint64 `json:"epoch,omitempty"`
Rewrite *string `json:"rewrite,omitempty"`
}
Lineage says which version of a branch's history a ref holds: a rewrite bumps Epoch and names its reflog record.
type Loc ¶
type Loc struct {
Kind LocKind
// Inline bytes.
Data []byte
// A pack, and the range of it holding the stored blob (codec byte included).
Pack Hash
Off, Len uint64
// Chunks, in order.
Chunks []ChunkRef
}
Loc is where a file's bytes live.
type LocKind ¶
type LocKind uint8
LocKind says where a file's bytes live.
const ( // Inline: in the entry itself (files of InlineMax bytes or fewer, and symlinks). Inline LocKind = 0 // Packed: a range of a pack object. Packed LocKind = 1 // Chunked: content-defined chunks, each its own object. Chunked LocKind = 2 // Unresolved: an old version named by a change list; never stored in a page. Unresolved LocKind = 3 )
type PackBuilder ¶
type PackBuilder struct {
// contains filtered or unexported fields
}
PackBuilder builds one pack: blobs back to back, then a footer index for gc and fsck.
func (*PackBuilder) Add ¶
func (p *PackBuilder) Add(hash Hash, raw []byte) (off, length uint64)
Add appends a file's bytes under their content hash and returns where they are stored.
func (*PackBuilder) AddStored ¶
func (p *PackBuilder) AddStored(hash Hash, stored []byte, rawLen uint64) (off, length uint64)
AddStored appends a blob already encoded ([codec][data]), copied verbatim.
func (*PackBuilder) Empty ¶
func (p *PackBuilder) Empty() bool
Empty reports whether no blob was added.
func (*PackBuilder) Finish ¶
func (p *PackBuilder) Finish() (Hash, []byte)
Finish appends the footer and returns the pack's hash and bytes.
type Page ¶
Page is a decoded manifest page: a leaf (Level 0) of entries or a node of children.
func DecodePage ¶
DecodePage reads EncodePage's output. It checks what a hostile page could abuse: counts against the bytes left, sorted keys, pack indexes, and no trailing bytes.
type RefValue ¶
type RefValue struct {
Commit Hash `json:"commit"`
// Root and Generation are the commit's, so a writer can build on the head without
// fetching it.
Root *Hash `json:"root,omitempty"`
Generation *uint64 `json:"generation,omitempty"`
// Recent lists the intents landed most recently, newest last.
Recent []Landed `json:"recent,omitempty"`
Lineage
}
RefValue is a ref's body.
type Repo ¶
type Repo struct {
Store *store.Store
// MaxObject, when positive, bounds every object the repository reads (a commit, a page,
// a pack range, a chunk), for a host that reads repositories it does not trust.
MaxObject int64
// contains filtered or unexported fields
}
Repo reads a pail repository in a store (src/repo.rs). Immutable objects it reads are checked against their hashes and cached in memory. It is safe for concurrent use.
func (*Repo) DefaultBranch ¶
DefaultBranch is the branch the store's HEAD names, or "" if it names none.
func (*Repo) Diff ¶
Diff is the changes from tree a to tree b. Leaves the trees share are never read.
type Rewrite ¶
type Rewrite struct {
Old Hash `json:"old"`
New Hash `json:"new"`
Epoch uint64 `json:"epoch"`
Prev *string `json:"prev,omitempty"`
// Op is what rewrote it: rebase, undo or reset.
Op string `json:"op,omitempty"`
By string `json:"by,omitempty"`
Date string `json:"date,omitempty"`
// Map takes each rewritten commit of the old history to its successor (nil: dropped).
Map map[Hash]*Hash `json:"map,omitempty"`
}
Rewrite is a rewrite of a branch, kept at reflog/<branch>/<id>.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package policy is pail's branch policy (src/policy.rs): who may read a repository, write each branch, set its default branch and collect its garbage.
|
Package policy is pail's branch policy (src/policy.rs): who may read a repository, write each branch, set its default branch and collect its garbage. |
|
Package store is pail's bucket (src/store.rs): immutable content-addressed objects plus compare-and-swap on mutable ones, over GCS, S3, a local directory or memory.
|
Package store is pail's bucket (src/store.rs): immutable content-addressed objects plus compare-and-swap on mutable ones, over GCS, S3, a local directory or memory. |