Elffuss BraidHub

utopia-ia/elffuss-braid public

2da7deeea818 · 4.2 KiBRawPermalink
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 UtopiaIA
3
4//! Workspaces of elffuss-braid: working copies that many agents use at once
5//! on one repository, each landing on a branch without waiting for the
6//! others.
7//!
8//! # Layout
9//!
10//! A workspace is any directory holding a `.braid` file. The file is local
11//! and never tracked; it names the repository and the workspace (see
12//! [`braid_repo::WorkspaceLink`]). Next to it, a `.git` file whose
13//! `gitdir:` line points nowhere ([`GIT_GUARD`]) makes git stop with "not a
14//! git repository" inside the workspace, instead of finding the repository
15//! of a checkout around it and acting on that. The walk skips both. A
16//! workspace goes in `.braid/work/<name>` of the repository unless told
17//! otherwise ([`Workspace::default_dir`]). Its state lives in the
18//! repository, in `.braid/ws/<name>/`:
19//!
20//! ```text
21//! state the base changeset, the branch, the directory, the file system's
22//! name rules, marks made by `braid track`, a rebase in progress
23//! stat the stat cache
24//! lock locked while a command changes the workspace
25//! ```
26//!
27//! # Operations
28//!
29//! - [`Workspace::create`] writes a tree into a new directory.
30//! - [`Workspace::status`] compares the working copy with the base, using
31//! the stat cache so that unchanged files are not read again, and
32//! directories that did not change are neither listed nor compared with
33//! their trees again.
34//! - [`Workspace::commit`] records the working copy as a changeset on the
35//! base. There is no staging area; given paths, it reads only what lies at
36//! or below them.
37//! - [`Workspace::land`] puts the workspace's changesets on its branch in
38//! one short op log transaction, fast-forwarding or rebasing them with the
39//! engine; conflicts come back as data and the branch does not move.
40//! - [`Workspace::update`] brings the workspace onto the branch's head,
41//! rebasing its own changesets; conflicts are written with markers.
42//! - [`create_change`] and [`land_change`] make and land a changeset
43//! without any working copy; [`create_revert`] makes one that undoes
44//! another; [`land_stack`] lands a stack of them made elsewhere, as a hub
45//! does.
46//! - [`materialize`] writes a changeset's files into a plain directory,
47//! with the same safe checkout, for a command that only needs the files.
48//! - [`Workspace::stack`] and [`Workspace::adopt`] split a landing in two,
49//! for a repository whose branches live on a hub: what to land there,
50//! and moving onto the head that holds it afterwards.
51//!
52//! # Safety of checkouts
53//!
54//! Every write into a working copy goes through directory handles that
55//! never follow a symlink (see the `safe` module), through a scratch file
56//! and a rename, with modes 0644 or 0755 only. Names this platform cannot
57//! hold, and names that would collide on the workspace's file system, are
58//! refused before anything is written. Nothing found in the repository is
59//! ever run: there are no hooks, filters or attributes.
60//!
61//! New files that look like secrets (`.env*`, `*.pem`, `id_*`) or are
62//! larger than 1 MiB are not committed until [`Workspace::track`] marks
63//! them: [`Workspace::commit`] refuses while they wait, listing them with
64//! the other reasons it has (see [`Blocker`]), unless it is forced, and then
65//! leaves them out.
66
67#![forbid(unsafe_code)]
68
69mod blocker;
70mod cache;
71mod change;
72mod checkout;
73mod error;
74mod fsprobe;
75mod identity;
76mod ignores;
77mod markers;
78mod materialize;
79mod paths;
80mod rebase;
81mod safe;
82mod scan;
83mod stack;
84mod state;
85mod status;
86mod tree;
87mod workspace;
88
89pub use blocker::Blocker;
90pub use change::{ChangeRequest, Expect, RevertRequest, create_change, create_revert, land_change};
91pub use error::Error;
92pub use fsprobe::FileSystem;
93pub use identity::Identity;
94pub use materialize::materialize;
95pub use paths::workspace_path;
96pub use stack::{StackMode, land_stack};
97pub use state::{Checkout, Rebase, RecordedConflict, State};
98pub use status::{ChangeKind, GUARD_SIZE, PathChange, Status, is_guarded};
99pub use workspace::{
100 BEHIND_LIMIT, CommitOutcome, CommitRequest, GIT_GUARD, GIT_GUARD_TEXT, LandReport, Landed,
101 Placed, RebaseProgress, Stack, StatusReport, UpdateReport, Updated, Workspace,
102};