| 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. |
| 18 | //! - [`merge3`]: three-way merges of file contents. |
| 19 | //! - [`land`]: landing a change on a branch, with conflicts reported as data. |
| 20 | //! - [`merge`]: merging two changesets into a merge changeset, with the same |
| 21 | //! rules and conflicts as landing. |
| 22 | //! |
| 23 | //! # Files and directories |
| 24 | //! |
| 25 | //! A change list is per file: each change sets one path to a file, an |
| 26 | //! executable, a symlink or a gitlink, or deletes it. Directories follow from |
| 27 | //! the files: a change below a missing directory creates it, and a directory |
| 28 | //! left without entries by a change is removed, as git has no empty |
| 29 | //! directories. Braid trees never hold an empty subdirectory: no change list |
| 30 | //! makes one, and the git bridge drops them when it converts git trees. |
| 31 | //! |
| 32 | //! A path has at most [`MAX_PATH_DEPTH`] names. This is a store policy, not |
| 33 | //! part of the hashed format: [`apply`] and [`admit`] refuse deeper paths, so |
| 34 | //! no stored tree is deeper, and every walk over a tree stops with |
| 35 | //! [`Error::TooDeep`] beyond it. The walks keep their own stacks rather than |
| 36 | //! recursing, so the limit does not depend on the size of the thread's stack. |
| 37 | //! |
| 38 | //! # Costs |
| 39 | //! |
| 40 | //! [`apply`], [`diff`], [`admit`], [`land`] and [`merge`] read only the |
| 41 | //! directories on the changed paths, so their cost follows the size of the |
| 42 | //! change times the depth of the tree, plus the size of each directory they |
| 43 | //! touch. Ancestry queries walk history and are proportional to the distance |
| 44 | //! they cover. |
| 45 | //! |
| 46 | //! [`Objects`]: braid_format::Objects |
| 47 | |
| 48 | #![forbid(unsafe_code)] |
| 49 | |
| 50 | mod access; |
| 51 | mod ancestry; |
| 52 | mod apply; |
| 53 | mod commit; |
| 54 | mod diff; |
| 55 | mod error; |
| 56 | mod land; |
| 57 | mod merge; |
| 58 | mod path; |
| 59 | mod tree_merge; |
| 60 | |
| 61 | #[cfg(test)] |
| 62 | mod testing; |
| 63 | |
| 64 | pub use access::{ |
| 65 | EMPTY_TREE, entry_at, read_blob, read_changes, read_changeset, read_object, read_tree, |
| 66 | stat_object, write_tree, |
| 67 | }; |
| 68 | pub use ancestry::{first_parent_chain_contains, is_ancestor, merge_base, merge_bases}; |
| 69 | pub use apply::apply; |
| 70 | pub use commit::{admit, commit}; |
| 71 | pub use diff::diff; |
| 72 | pub use error::{ApplyProblem, Error, StoreError}; |
| 73 | pub use land::{AGENT, Conflict, ConflictKind, LandOutcome, REBASED_FROM, land}; |
| 74 | pub use merge::{BINARY_SNIFF_BYTES, ConflictHunk, HunkSide, MergeResult, is_binary, merge3}; |
| 75 | pub use path::MAX_PATH_DEPTH; |
| 76 | pub use tree_merge::{MergeOutcome, merge}; |