Elffuss BraidHub

utopia-ia/elffuss-braid public

main · 4.5 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, and [`create_revert_with_message`] the same with a message of
45//! the caller's; [`land_stack`] lands a stack of them made elsewhere, as a
46//! hub does.
47//! - `materialize` writes a changeset's files into a plain directory, with
48//! the same safe checkout, for a command that only needs the files. It
49//! comes with the `materialize` feature, on by default; a build that never
50//! writes files outside a workspace, such as a server's, can leave it out.
51//! - [`Workspace::stack`] and [`Workspace::adopt`] split a landing in two,
52//! for a repository whose branches live on a hub: what to land there,
53//! and moving onto the head that holds it afterwards.
54//!
55//! # Safety of checkouts
56//!
57//! Every write into a working copy goes through directory handles that
58//! never follow a symlink (see the `safe` module), through a scratch file
59//! and a rename, with modes 0644 or 0755 only. Names this platform cannot
60//! hold, and names that would collide on the workspace's file system, are
61//! refused before anything is written. Nothing found in the repository is
62//! ever run: there are no hooks, filters or attributes.
63//!
64//! New files that look like secrets (`.env*`, `*.pem`, `id_*`) or are
65//! larger than 1 MiB are not committed until [`Workspace::track`] marks
66//! them: [`Workspace::commit`] refuses while they wait, listing them with
67//! the other reasons it has (see [`Blocker`]), unless it is forced, and then
68//! leaves them out.
69
70#![forbid(unsafe_code)]
71
72mod blocker;
73mod cache;
74mod change;
75mod checkout;
76mod error;
77mod fsprobe;
78mod identity;
79mod ignores;
80mod markers;
81#[cfg(feature = "materialize")]
82mod materialize;
83mod paths;
84mod rebase;
85mod safe;
86mod scan;
87mod stack;
88mod state;
89mod status;
90mod tree;
91mod workspace;
92
93pub use blocker::Blocker;
94pub use change::{
95 ChangeRequest, Expect, RevertRequest, create_change, create_revert, create_revert_with_message,
96 land_change,
97};
98pub use error::Error;
99pub use fsprobe::FileSystem;
100pub use identity::Identity;
101#[cfg(feature = "materialize")]
102pub use materialize::materialize;
103pub use paths::workspace_path;
104pub use stack::{StackMode, land_stack};
105pub use state::{Checkout, Rebase, RecordedConflict, State};
106pub use status::{ChangeKind, GUARD_SIZE, PathChange, Status, is_guarded};
107pub use workspace::{
108 BEHIND_LIMIT, CommitOutcome, CommitRequest, GIT_GUARD, GIT_GUARD_TEXT, LandReport, Landed,
109 Placed, RebaseProgress, Stack, StatusReport, UpdateReport, Updated, Workspace,
110};