Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/repo.rs @ 52042:28a0eb21ff04
rust-cpython: add a util to get a `Repo` from a python path
I suspect this will not be the last time we need to do something like this.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 01 Oct 2024 13:45:18 +0200 |
parents | d7bc6e482033 |
children | e1fe336c007a |
line wrap: on
line diff
--- a/rust/hg-core/src/repo.rs Tue Oct 01 13:20:40 2024 +0200 +++ b/rust/hg-core/src/repo.rs Tue Oct 01 13:45:18 2024 +0200 @@ -20,7 +20,7 @@ use crate::utils::SliceExt; use crate::vfs::{is_dir, is_file, VfsImpl}; use crate::{ - requirements, NodePrefix, RevlogDataConfig, RevlogDeltaConfig, + exit_codes, requirements, NodePrefix, RevlogDataConfig, RevlogDeltaConfig, RevlogFeatureConfig, RevlogType, RevlogVersionOptions, UncheckedRevision, }; use crate::{DirstateError, RevlogOpenOptions}; @@ -68,6 +68,32 @@ } } +impl From<RepoError> for HgError { + fn from(value: RepoError) -> Self { + match value { + RepoError::NotFound { at } => HgError::abort( + format!( + "abort: no repository found in '{}' (.hg not found)!", + at.display() + ), + exit_codes::ABORT, + None, + ), + RepoError::ConfigParseError(config_parse_error) => { + HgError::Abort { + message: String::from_utf8_lossy( + &config_parse_error.message, + ) + .to_string(), + detailed_exit_code: exit_codes::CONFIG_PARSE_ERROR_ABORT, + hint: None, + } + } + RepoError::Other(hg_error) => hg_error, + } + } +} + impl Repo { /// tries to find nearest repository root in current working directory or /// its ancestors