heroforge_core/
lib.rs

1//! # heroforge
2//!
3//! A pure Rust client library for reading and writing Heroforge SCM repositories.
4//!
5//! ## Overview
6//!
7//! `heroforge` provides a complete API for interacting with Heroforge repositories without
8//! requiring the Heroforge CLI. It supports both reading from existing repositories and
9//! creating new ones from scratch.
10//!
11//! ## Quick Start (Builder API)
12//!
13//! ```no_run
14//! use heroforge_core::Repository;
15//!
16//! fn main() -> heroforge_core::Result<()> {
17//!     // Create a new repository
18//!     let repo = Repository::init("project.forge")?;
19//!
20//!     // Create initial commit using builder
21//!     let init = repo.commit_builder()
22//!         .message("Initial commit")
23//!         .author("admin")
24//!         .initial()
25//!         .execute()?;
26//!
27//!     // Add files using builder
28//!     let v1 = repo.commit_builder()
29//!         .message("Add project files")
30//!         .author("developer")
31//!         .parent(&init)
32//!         .file("README.md", b"# My Project\n")
33//!         .file("src/main.rs", b"fn main() {}\n")
34//!         .execute()?;
35//!
36//!     // Tag the release
37//!     repo.tags()
38//!         .create("v1.0.0")
39//!         .at_commit(&v1)
40//!         .author("developer")
41//!         .execute()?;
42//!
43//!     // Read files using builder
44//!     let readme = repo.files().on_trunk().read_string("README.md")?;
45//!     let rust_files = repo.files().at_tag("v1.0.0").find("**/*.rs")?;
46//!
47//!     // Sync to remote
48//!     repo.sync()
49//!         .to("quic://backup.example.com:4443/project")
50//!         .push()?;
51//!
52//!     Ok(())
53//! }
54//! ```
55//!
56//! ## Features
57//!
58//! ### File Operations
59//! ```no_run
60//! # use heroforge_core::Repository;
61//! # let repo = Repository::open("project.forge")?;
62//! // List files on trunk
63//! let files = repo.files().on_trunk().list()?;
64//!
65//! // Read file from a branch
66//! let content = repo.files().on_branch("feature").read("config.json")?;
67//!
68//! // Find files at a tag
69//! let rust = repo.files().at_tag("v1.0").find("**/*.rs")?;
70//! # Ok::<(), heroforge_core::FossilError>(())
71//! ```
72//!
73//! ### Commit Operations
74//! ```no_run
75//! # use heroforge_core::Repository;
76//! # let repo = Repository::open_rw("project.forge")?;
77//! let hash = repo.commit_builder()
78//!     .message("Add feature")
79//!     .author("developer")
80//!     .parent("abc123")
81//!     .file("src/feature.rs", b"// new feature")
82//!     .execute()?;
83//! # Ok::<(), heroforge_core::FossilError>(())
84//! ```
85//!
86//! ### Branch/Tag Operations
87//! ```no_run
88//! # use heroforge_core::Repository;
89//! # let repo = Repository::open_rw("project.forge")?;
90//! // Create branch
91//! repo.branches()
92//!     .create("feature-x")
93//!     .from_branch("trunk")
94//!     .author("developer")
95//!     .execute()?;
96//!
97//! // Create tag
98//! repo.tags()
99//!     .create("v1.0.0")
100//!     .at_branch("trunk")
101//!     .author("developer")
102//!     .execute()?;
103//! # Ok::<(), heroforge_core::FossilError>(())
104//! ```
105//!
106//! ### Filesystem Operations (Copy, Move, Delete, Find, Symlinks)
107//! ```no_run
108//! # use heroforge_core::Repository;
109//! use heroforge_core::fs::{Find, Modify};
110//! # let repo = Repository::open_rw("project.forge")?;
111//!
112//! // Copy, move, delete files and directories
113//! Modify::new(&repo)
114//!     .message("Reorganize project structure")
115//!     .author("developer")
116//!     .copy_file("README.md", "docs/README.md")
117//!     .copy_dir("src", "backup/src")
118//!     .move_file("old.txt", "archive/old.txt")
119//!     .move_dir("scripts", "tools")
120//!     .delete_file("temp.log")
121//!     .delete_dir("cache")
122//!     .execute()?;
123//!
124//! // Find files with patterns and ignore rules
125//! let rust_files = Find::new(&repo)
126//!     .pattern("**/*.rs")
127//!     .ignore("target/**")
128//!     .ignore_hidden()
129//!     .paths()?;
130//!
131//! // Change permissions
132//! Modify::new(&repo)
133//!     .message("Make scripts executable")
134//!     .author("developer")
135//!     .make_executable("scripts/deploy.sh")
136//!     .chmod_dir("bin", 0o755)
137//!     .execute()?;
138//!
139//! // Create symlinks
140//! Modify::new(&repo)
141//!     .message("Add symlinks")
142//!     .author("developer")
143//!     .symlink("lib/latest", "lib/v2.0")
144//!     .execute()?;
145//!
146//! // Utility functions
147//! use heroforge_core::fs::{exists, is_dir, du, count};
148//! let file_exists = exists(&repo, "README.md")?;
149//! let is_directory = is_dir(&repo, "src")?;
150//! let size = du(&repo, "src/**/*")?;
151//! let num_files = count(&repo, "**/*.rs")?;
152//! # Ok::<(), heroforge_core::FossilError>(())
153//! ```
154//!
155//! ### Sync Operations (QUIC)
156//! ```no_run
157//! # use heroforge_core::Repository;
158//! # let repo = Repository::open("project.forge")?;
159//! // Push over QUIC
160//! repo.sync()
161//!     .to("quic://server:4443/repo")
162//!     .push()?;
163//!
164//! // Pull from remote
165//! repo.sync()
166//!     .from("quic://server:4443/repo")
167//!     .auth("user", "password")
168//!     .pull()?;
169//! # Ok::<(), heroforge_core::FossilError>(())
170//! ```
171
172pub mod artifact;
173pub mod error;
174pub mod fs;
175pub mod hash;
176pub mod repo;
177pub mod server;
178pub mod sync;
179#[cfg(feature = "git-import")]
180pub mod tools;
181
182// Rhai scripting API (requires rhai feature)
183#[cfg(feature = "rhai")]
184pub mod rhai_api;
185
186pub use error::{FossilError, Result};
187pub use repo::{CheckIn, FileInfo, Repository};
188pub use server::Server;
189pub use sync::{SyncBuilder, SyncProtocol, SyncResult};
190
191// Filesystem storage backend
192pub use fs::{
193    DirectoryEntry, FileHandle, FileKind, FileMetadata, FilePermissions, FileSystem,
194    FileSystemStatus, FindResults, FsError, FsOperation, FsResult, OperationSummary, SavePoint,
195    Transaction, TransactionMode, TransactionState,
196};
197
198// New staging-based filesystem interface
199pub use fs::{
200    CommitConfig, CommitWorker, DEFAULT_COMMIT_INTERVAL, FsInterface, FsInterfaceStatus,
201    MAX_FILE_SIZE, StagedFile, Staging, StagingState,
202};
203
204// Re-export builders for convenience
205pub use repo::{
206    BranchBuilder, BranchesBuilder, CommitBuilder, FileEntry, FileQuery, FileType, FilesBuilder,
207    FindBuilder, FindResult, FsBuilder, FsOperation as RepoFsOperation, FsOpsBuilder, FsPreview,
208    HistoryBuilder, Permissions, TagBuilder, TagsBuilder, UserBuilder, UsersBuilder,
209};
210
211// Git import tool (requires git-import feature)
212#[cfg(feature = "git-import")]
213pub use tools::{GitImportBuilder, GitImportResult};