| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (c) 2026 UtopiaIA |
| 3 | |
| 4 | //! The semantic core of elffuss-braid: what a change list means, and what |
| 5 | //! committing, admitting and landing a changeset do. |
| 6 | //! |
| 7 | //! Everything here reads and writes through the [`Objects`] trait and does no |
| 8 | //! I/O of its own, so the same code runs over the local store, a remote one, or |
| 9 | //! memory. |
| 10 | //! |
| 11 | //! - [`read_tree`], [`write_tree`], [`read_changeset`], [`read_changes`]: |
| 12 | //! typed access to stored objects. |
| 13 | //! - [`apply`] and [`diff`]: a change list, and the two trees it connects. |
| 14 | //! - [`commit`] and [`admit`]: creating a changeset, and the check a store |
| 15 | //! runs before it accepts one. |
| 16 | //! - [`first_parent_chain_contains`], [`is_ancestor`] and [`merge_base`]: |
| 17 | //! ancestry, walking history. |
| 18 | //! - [`History`]: the same ancestry queries with generation numbers and skip |
| 19 | //! pointers, the history of a path ([`History::path_log`]) with |
| 20 | //! changed-path filters, and [`History::blame`], all answered with derived |
| 21 | //! data ([`DerivedKey`], [`DerivedIndex`]) computed when missing. |
| 22 | //! - [`merge3`]: three-way merges of file contents. |
| 23 | //! - [`land`]: landing a change on a branch, with conflicts reported as data. |
| 24 | //! - [`merge`]: merging two changesets into a merge changeset, with the same |
| 25 | //! rules and conflicts as landing. |
| 26 | //! |
| 27 | //! # Files and directories |
| 28 | //! |
| 29 | //! A change list is per file: each change sets one path to a file, an |
| 30 | //! executable, a symlink or a gitlink, or deletes it. Directories follow from |
| 31 | //! the files: a change below a missing directory creates it, and a directory |
| 32 | //! left without entries by a change is removed, as git has no empty |
| 33 | //! directories. Braid trees never hold an empty subdirectory: no change list |
| 34 | //! makes one, and the git bridge drops them when it converts git trees. |
| 35 | //! |
| 36 | //! A path has at most [`MAX_PATH_DEPTH`] names. This is a store policy, not |
| 37 | //! part of the hashed format: [`apply`] and [`admit`] refuse deeper paths, so |
| 38 | //! no stored tree is deeper, and every walk over a tree stops with |
| 39 | //! [`Error::TooDeep`] beyond it. The walks keep their own stacks rather than |
| 40 | //! recursing, so the limit does not depend on the size of the thread's stack. |
| 41 | //! |
| 42 | //! # Costs |
| 43 | //! |
| 44 | //! [`apply`], [`diff`], [`admit`], [`land`] and [`merge`] read only the |
| 45 | //! directories on the changed paths, so their cost follows the size of the |
| 46 | //! change times the depth of the tree, plus the size of each directory they |
| 47 | //! touch. A large directory is split into nodes, and [`apply`], [`admit`], |
| 48 | //! [`entry_at`] and the lookups of [`land`] and [`merge`] read and write |
| 49 | //! only the nodes on the way to the names they need, so its size counts |
| 50 | //! only through its depth; [`diff`] reads both versions of each directory |
| 51 | //! that differs whole. The free ancestry functions walk history and are |
| 52 | //! proportional to the distance they cover; [`History`] reads derived data |
| 53 | //! instead, so its queries cost what they visit once that data exists. |
| 54 | //! |
| 55 | //! [`Objects`]: braid_format::Objects |
| 56 | |
| 57 | #![forbid(unsafe_code)] |
| 58 | |
| 59 | mod access; |
| 60 | mod ancestry; |
| 61 | mod apply; |
| 62 | mod blame; |
| 63 | mod bloom; |
| 64 | mod commit; |
| 65 | mod derived; |
| 66 | mod diff; |
| 67 | mod error; |
| 68 | mod history; |
| 69 | mod land; |
| 70 | mod merge; |
| 71 | mod path; |
| 72 | mod reach; |
| 73 | mod tree_merge; |
| 74 | |
| 75 | #[cfg(test)] |
| 76 | mod testing; |
| 77 | |
| 78 | pub use access::{ |
| 79 | EMPTY_TREE, entry_at, read_blob, read_changes, read_changeset, read_object, read_tree, |
| 80 | stat_object, write_tree, |
| 81 | }; |
| 82 | pub use ancestry::{ |
| 83 | GraphNode, first_parent_chain_contains, is_ancestor, merge_base, merge_bases, skip_height, |
| 84 | }; |
| 85 | pub use apply::apply; |
| 86 | pub use blame::{Blame, LineChange, line_diff}; |
| 87 | pub use commit::{admit, commit}; |
| 88 | pub use derived::{DerivedIndex, DerivedKey, MemoryIndex}; |
| 89 | pub use diff::diff; |
| 90 | pub use error::{ApplyProblem, Error, StoreError}; |
| 91 | pub use history::{DeriveReport, History}; |
| 92 | pub use land::{AGENT, Conflict, ConflictKind, LandOutcome, REBASED_FROM, REVERTS, land}; |
| 93 | pub use merge::{BINARY_SNIFF_BYTES, ConflictHunk, HunkSide, MergeResult, is_binary, merge3}; |
| 94 | pub use path::MAX_PATH_DEPTH; |
| 95 | pub use reach::{Reach, Reached, reachable}; |
| 96 | pub use tree_merge::{MergeOutcome, merge}; |