lcpfs 2026.1.102

LCP File System - A ZFS-inspired copy-on-write filesystem for Rust
// Copyright 2025 LunaOS Contributors
// SPDX-License-Identifier: Apache-2.0

//! Git-style branching for LCPFS.
//!
//! This module provides git-like branching capabilities for LCPFS datasets,
//! leveraging the copy-on-write (COW) nature of the filesystem to enable
//! zero-copy branch creation and efficient merging.
//!
//! # Overview
//!
//! The branching system provides:
//!
//! - **Zero-copy branch creation**: Due to COW semantics, creating a branch is
//!   nearly instantaneous regardless of dataset size
//! - **Three-way merge**: Full merge support with conflict detection
//! - **Commit tracking**: Git-style commits with BLAKE3 hashes
//! - **Cherry-pick**: Apply commits from one branch to another
//! - **History viewing**: Log, file history, and branch statistics
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │                       BranchManager                              │
//! │  (Unified API combining all branching operations)               │
//! └─────────────────────────────────────────────────────────────────┘
//!//!          ┌──────────────────────┼──────────────────────┐
//!          ▼                      ▼                      ▼
//! ┌─────────────────┐   ┌─────────────────┐   ┌─────────────────┐
//! │  BranchRegistry │   │   CommitStore   │   │    MergeEngine  │
//! │  (Branch meta)  │   │  (Commit hash)  │   │   (3-way merge) │
//! └─────────────────┘   └─────────────────┘   └─────────────────┘
//!          │                      │                      │
//!          └──────────────────────┼──────────────────────┘
//!//!                    ┌─────────────────────┐
//!                    │  DatasetProvider    │
//!                    │  (COW filesystem)   │
//!                    └─────────────────────┘
//! ```
//!
//! # Usage
//!
//! ```rust,ignore
//! use lcpfs::branch::BranchManager;
//!
//! // Create a branch manager with a dataset provider
//! let mut manager = BranchManager::new(provider, "user@example.com");
//!
//! // Create and checkout a new branch
//! manager.checkout_new("feature-xyz")?;
//!
//! // Make changes and commit
//! manager.commit("Add new feature", changes)?;
//!
//! // Switch back to main
//! manager.checkout("main")?;
//!
//! // Merge the feature branch
//! let result = manager.merge("feature-xyz")?;
//! if result.has_conflicts() {
//!     // Handle conflicts...
//! }
//! ```
//!
//! # Modules
//!
//! - `types`: Core types (Branch, Commit, FileChange, MergeResult, etc.)
//! - `registry`: Branch registry for tracking branch metadata
//! - `ops`: Branch operations (create, checkout, delete)
//! - `commit`: Commit tracking with BLAKE3 hashes
//! - `merge`: Three-way merge with conflict detection
//! - `cherrypick`: Cherry-pick commits across branches
//! - `log`: History viewing and statistics
//! - `manager`: Unified BranchManager API

pub mod cherrypick;
pub mod commit;
pub mod log;
pub mod manager;
pub mod merge;
pub mod ops;
pub mod registry;
pub mod types;

// Re-export main types
pub use cherrypick::{
    CherryPickOptions, CherryPickResult, CherryPickStatus, CherryPicker, ConflictStrategy,
};
pub use commit::{CommitBuilder, CommitStore, CommitValidator};
pub use log::{BranchStats, LogEntry, LogFormat, LogOptions, LogViewer};
pub use manager::BranchManager;
pub use merge::{
    DiffEntry, FileInfo, FileStateProvider, MergeAnalysis, MergeExecutor, ThreeWayMerge,
};
pub use ops::{BranchOps, BranchStatus, DatasetProvider};
pub use registry::BranchRegistry;
pub use types::{
    Branch, BranchError, ChangeType, Commit, ConflictType, FileChange, FileVersion, MergeConflict,
    MergeResult, MergeStrategy,
};

#[cfg(test)]
mod tests {
    use super::*;
    use alloc::string::ToString;

    #[test]
    fn test_module_exports() {
        // Verify all public types are accessible
        let _branch = Branch::main(1, 0, 0);
        let _registry = BranchRegistry::new(0, 0);
        let _store = CommitStore::new();
        let _strategy = MergeStrategy::default();
        let _error = BranchError::BranchNotFound("test".to_string());
    }
}