This document explains how Fossil’s repository schema underpins the version control core, with emphasis on document/version artifacts and their relationships. It maps key tables and indexes in schema.sql to the responsibilities in (source paths under src/):
src/checkin.c— commit operationssrc/checkout.c— checkout/update operationssrc/merge.c— three-way merge logicsrc/delta.c— delta compression algorithmsrc/manifest.c— manifest parsing and generationsrc/rebuild.c— repository rebuild operationssrc/sync.c— push/pull/sync operationssrc/xfer.c— network transfer protocol
Core Data Model
blob(rid, rcvid, size, uuid, content)- Stores all artifacts: manifests, file contents, wiki/forum posts, tickets, etc.
uuidis the immutable artifact hash;ridis the internal row id.rcvidties the artifact to a received bundle (remote sync session).
delta(rid, srcid)- Records that artifact
ridis stored as a delta against basesrcid. - Used for storage optimization; logical content still addressed by
blob.uuid.
- Records that artifact
filename(fnid, name)- Interns path names; referenced by
mlinkto avoid duplication.
- Interns path names; referenced by
mlink(mid, fid, pmid, pid, fnid, pfnid, mperm, isaux)- Per-file linkage within a manifest (
mid). - Maps file artifact (
fid) and its parent (pid) under a filename (fnid). - Encodes file-level perms and aux flags and parent filename (
pfnid) for renames.
- Per-file linkage within a manifest (
plink(pid, cid, isprim, mtime, baseid)- Parent/child relationships between check-in manifests (
pid→cid). isprimmarks primary parent (for merges, cherry-picks);baseidcan reference a baseline.
- Parent/child relationships between check-in manifests (
leaf(rid)- Tracks leaf check-ins for branch growth and tip resolution.
tag(tagid, tagname)andtagxref(tagid, tagtype, srcid, origid, value, mtime, rid)- Branch names, closes, propagating tags, user-defined tags.
ridusually refers to a check-in.
- Branch names, closes, propagating tags, user-defined tags.
event(type, mtime, objid, tagid, uid, ...)- Timeline events: check-ins, wiki edits, ticket changes.
artifactview (rid, rcvid, size, atype, srcid, hash, content)- Joins
blobwithdeltato present artifacts with delta ancestry.
- Joins
Support tables
rcvfrom(received bundles for sync)private(private artifacts)phantom,orphan,unclustered,unsent(stateful maintenance during sync/rebuild)cherrypick(parentid, childid, isExclude)(cherry-pick inclusion/exclusion)attachment,backlink(cross-object references)
Module Linkage
checkin.c (Commit Operations)
Cross-refs: src/checkin.c, src/manifest.c, src/tag.c, src/event.c.
- Inserts a new manifest into
blob(contentis manifest text;uuidis its hash). - Updates
plinkto connect the new check-in (cid) to its parent(s) (pid). - Populates
mlinkrows per file entry:mid= manifest rid,fid= file content rid,fnid= path fromfilename.pid/pfnidcapture parent file linkage for diffs/renames.
- Marks
leaffor the new tip and updates tags viatagxref(e.g., branch, closed). - Emits
event(type='ci', objid=rid, mtime, ...)for timeline.
checkout.c (Checkout/Update Operations)
Cross-refs: src/checkout.c, src/vfile.c, src/content.c.
- Resolves target
ridvia branch/tag selectors usingtag/tagxrefandplinkancestry. - Enumerates
mlinkfor the target manifest to materialize the working tree:- For each
fid, retrievesblob.content(followingdelta.srcidif needed). - Applies renames via
pfnidand permissionsmperm.
- For each
- Computes update plans by diffing
mlinkof current vs target manifests.
merge.c (Three-Way Merge Logic)
Cross-refs: src/merge.c, src/diff.c, src/plink.c (logical graph via plink), src/filename.c (path intern).
- Determines merge bases using
plinkgraph (common ancestor selection). - Per file path (
fnid), usesmlinktriplets (base, ours, theirs) to locatefidartifacts. - Obtains file contents from
blob(resolves deltas viadeltalineage when fetching). - Writes merged results as new
blobentries (for committing) and updatesmlinkon commit. - Records merge parents in
plink(isprimmay indicate primary parent) and optionallycherrypickfor selective inclusion/exclusion.
delta.c (Delta Compression Algorithm)
Cross-refs: src/delta.c, src/blob.c, src/content.c.
- Storage layer uses deltas for
blob.content:- When saving content as a delta against
srcid, inserts row indeltaand stores patch inblob.content. - Retrieval reconstructs fulltext using
artifactview to locate basesrcid.
- When saving content as a delta against
- The VC core modules call delta routines indirectly via blob I/O helpers.
manifest.c (Manifest Parsing and Generation)
Cross-refs: src/manifest.c, src/mlink.c (derived linkage), src/tag.c.
- Produces and parses manifest artifacts in
blob.content(M-records, F-lines, etc.). Flines map tomlinkrows: file hash →fid, filename →fnid, perms →mperm.Plines establish parents →plink(pid, cid).Rrename directives can be represented viapfnidlinkage inmlink.- Tags (
Tlines) becometag/tagxrefentries, including branch name.
rebuild.c (Repository Rebuild Operations)
Cross-refs: src/rebuild.c, src/tag.c, src/event.c, src/leaf.c.
- Recomputes derived tables from canonical artifacts in
blob:- Regenerates
plink,mlink,leaf,tagxref,event, indexes.
- Regenerates
- Clears and repopulates maintenance tables:
phantom,orphan,unclustered. - Validates
deltaintegrity and may rebase deltas for optimal chains.
sync.c (Push/Pull/Sync Operations)
Cross-refs: src/sync.c, src/xfer.c, src/shun.c, src/clone.c.
- Tracks received bundles in
rcvfrom(rcvid, uid, mtime, nonce, ipaddr). - Inserts remote artifacts into
bloband notesrcvidfor provenance. - Temporarily marks unknown references as
phantomand queuesunsentfor outgoing. - Updates graph (
plink) and per-file links (mlink) after manifests arrive. - Applies
shunrules to ignore certainuuids andprivatefor non-syncing artifacts.
xfer.c (Network Transfer Protocol)
Cross-refs: src/xfer.c, src/sync.c, src/http_*.c.
- Encodes/decodes artifact exchanges (content by
blob.uuid). - Handles delta transmission and application, populating
delta(rid, srcid)when storing. - Coordinates sequence numbers and bundle integrity, feeding
rcvfromandunsent.
Document Versioning Flow
Step 1: Authoring and Check-in
- New file contents stored in
blob(optionally as deltas indelta). - Manifest stored in
bloband parsed intomlink(F-lines) andplink(P-lines). - Cross-refs:
src/checkin.c,src/manifest.c.
Step 2: Branching and Tags
tag/tagxrefattach branch names and metadata to the manifestrid.leafmarks branch tips;eventrecords timeline entries.- Cross-refs:
src/tag.c,src/leaf.c,src/event.c.
Step 3: Checkout and Update
- Target manifest resolved via
tagxref/plink; files enumerated viamlink. - Contents materialized from
blob(reconstructing viadeltawhen needed). - Cross-refs:
src/checkout.c,src/content.c,src/delta.c.
Step 4: Merge
- Base selection via
plink; file triplets viamlinkperfnid. - Merged outputs prepared for
checkin.cto write as newblob/manifest, linking viamlink&plink. - Cross-refs:
src/merge.c,src/diff.c,src/checkin.c.
Step 5: Sync
- Artifacts exchanged by
xfer.c; recorded viablob.rcvid,rcvfrom. - Graph/linkage derived by
sync.c; maintenance tables reconcile missing refs. - Cross-refs:
src/xfer.c,src/sync.c,src/configure.c(sync settings).
Step 6: Rebuild
rebuild.cre-derives all secondary tables fromblobcontents if indexes are lost/corrupt.- Cross-refs:
src/rebuild.c.
Indexes and Performance
delta_i1(srcid)accelerates delta chain resolution.mlink_i*indexes speed per-manifest and per-file lookups for checkout/merge.plink_i2(cid,pid)accelerates ancestry scans for merge base and history.event_i1(mtime)optimizes timeline queries.tagxref_i1(tagid, mtime)improves tag history and branch tip resolution.- Cross-refs:
src/db.c(query helpers),src/graph.c(timeline visualization).
- Cross-refs:
Special States and Maintenance
phantom: referenced but not yet present artifacts during sync.orphan(baseline): artifacts lacking expected baselines or parents.unclustered: artifacts outside cluster boundaries, pending consolidation.unsent: local artifacts queued for transmission.private: artifacts excluded from sync.cherrypick: explicit include/exclude relationships between check-ins.- Cross-refs:
src/sync.c,src/xfer.c,src/rebuild.c.
- Cross-refs:
Traceability Map (Quick Reference)
- Schema → Module
blob→src/checkin.c,src/content.c,src/xfer.cdelta→src/delta.c,src/content.cfilename→src/checkout.c,src/merge.cmlink→src/manifest.c,src/checkout.c,src/merge.cplink→src/checkin.c,src/merge.c,src/rebuild.cleaf→src/checkin.c,src/rebuild.ctag/tagxref→src/tag.c,src/branch.cevent→src/event.crcvfrom,unsent,phantom→src/sync.c,src/xfer.c
Where function-level detail is needed, see module-specific comments and COMMAND:/WEBPAGE: indices generated by tools/mkindex.c.
Summary
Fossil’s VC core treats blob artifacts and manifest semantics as the single source of truth. Derived tables such as mlink, plink, leaf, and tagxref provide efficient views optimized for commit, checkout, merge, and sync operations. The schema’s indexes and maintenance tables ensure performance and robustness across local edits, merges, and distributed synchronization.