Skip to main content

repo/
worktree_status_options.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Worktree status configuration and execution options.
3
4use serde::{Deserialize, Serialize};
5
6/// Optional fsmonitor backend selection for worktree status hot paths.
7#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "lowercase")]
9pub enum FsMonitorMode {
10    /// Disable fsmonitor integration.
11    #[default]
12    Off,
13    /// Auto-detect a supported backend at runtime.
14    Auto,
15    /// Use Heddle's local native backend.
16    Native,
17    /// Use the Watchman CLI backend when available.
18    Watchman,
19}
20
21impl FsMonitorMode {
22    /// Parse an environment override value.
23    pub fn parse(value: &str) -> Option<Self> {
24        match value.trim().to_ascii_lowercase().as_str() {
25            "0" | "off" | "false" | "disabled" => Some(Self::Off),
26            "1" | "auto" | "true" | "enabled" => Some(Self::Auto),
27            "native" | "local" => Some(Self::Native),
28            "watchman" => Some(Self::Watchman),
29            _ => None,
30        }
31    }
32}
33
34/// Serializable fsmonitor configuration stored in user or repo config.
35#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
36pub struct FsMonitorConfig {
37    /// Backend selection mode.
38    #[serde(default)]
39    pub mode: FsMonitorMode,
40}
41
42/// Resolved runtime fsmonitor settings.
43#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
44pub struct FsMonitorSettings {
45    /// Backend selection mode.
46    pub mode: FsMonitorMode,
47}
48
49impl From<FsMonitorConfig> for FsMonitorSettings {
50    fn from(config: FsMonitorConfig) -> Self {
51        Self { mode: config.mode }
52    }
53}
54
55/// Resolved options for worktree status operations.
56#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
57pub struct WorktreeStatusOptions {
58    /// Fsmonitor integration settings.
59    pub fsmonitor: FsMonitorSettings,
60}