xbp 10.39.0

XBP is a zero-config build pack that can also interact with proxies, kafka, sockets, synthetic monitors.
//! Path / filesystem helpers for version scope resolution.

use std::path::{Path, PathBuf};

use super::git_ops::git_repository_root;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum ServiceScopeFilter {
    /// Services allowed for bumps / dirty-tree versioning.
    Versioning,
    /// Services allowed for full release publishing.
    Release,
}

pub(crate) const LAST_VERSION_SCOPE_FILE: &str = "last-version-scope";

pub(crate) fn normalized_relative_path(path: &Path) -> String {
    path.to_string_lossy().replace('\\', "/")
}

pub(crate) fn same_filesystem_path(left: &Path, right: &Path) -> bool {
    if left == right {
        return true;
    }

    match (left.canonicalize(), right.canonicalize()) {
        (Ok(left), Ok(right)) => left == right,
        _ => false,
    }
}

pub(crate) fn enclosing_git_root(dir: &Path) -> Option<PathBuf> {
    for ancestor in dir.ancestors() {
        if ancestor.join(".git").exists() {
            return Some(ancestor.to_path_buf());
        }
    }

    git_repository_root(dir)
}