Elffuss BraidHub

utopia-ia/elffuss-braid public

2dd40509e7e2 · 3.6 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.
44//!
45//! # Safety of checkouts
46//!
47//! Every write into a working copy goes through directory handles that
48//! never follow a symlink (see the `safe` module), through a scratch file
49//! and a rename, with modes 0644 or 0755 only. Names this platform cannot
50//! hold, and names that would collide on the workspace's file system, are
51//! refused before anything is written. Nothing found in the repository is
52//! ever run: there are no hooks, filters or attributes.
53//!
54//! New files that look like secrets (`.env*`, `*.pem`, `id_*`) or are
55//! larger than 1 MiB are not committed until [`Workspace::track`] marks
56//! them: [`Workspace::commit`] refuses while they wait, listing them with
57//! the other reasons it has (see [`Blocker`]), unless it is forced, and then
58//! leaves them out.
59
60#![forbid(unsafe_code)]
61
62mod blocker;
63mod cache;
64mod change;
65mod checkout;
66mod error;
67mod fsprobe;
68mod identity;
69mod ignores;
70mod markers;
71mod paths;
72mod rebase;
73mod safe;
74mod scan;
75mod state;
76mod status;
77mod tree;
78mod workspace;
79
80pub use blocker::Blocker;
81pub use change::{ChangeRequest, Expect, create_change, land_change};
82pub use error::Error;
83pub use fsprobe::FileSystem;
84pub use identity::Identity;
85pub use paths::workspace_path;
86pub use state::{Checkout, Rebase, RecordedConflict, State};
87pub use status::{ChangeKind, GUARD_SIZE, PathChange, Status, is_guarded};
88pub use workspace::{
89 BEHIND_LIMIT, CommitOutcome, CommitRequest, GIT_GUARD, GIT_GUARD_TEXT, LandReport, Landed,
90 Placed, RebaseProgress, StatusReport, UpdateReport, Updated, Workspace,
91};