comparison rust/hg-core/src/repo.rs @ 52070: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
comparison
equal deleted inserted replaced
52069:652149ed64f0 52070:28a0eb21ff04
18 use crate::utils::files::get_path_from_bytes; 18 use crate::utils::files::get_path_from_bytes;
19 use crate::utils::hg_path::HgPath; 19 use crate::utils::hg_path::HgPath;
20 use crate::utils::SliceExt; 20 use crate::utils::SliceExt;
21 use crate::vfs::{is_dir, is_file, VfsImpl}; 21 use crate::vfs::{is_dir, is_file, VfsImpl};
22 use crate::{ 22 use crate::{
23 requirements, NodePrefix, RevlogDataConfig, RevlogDeltaConfig, 23 exit_codes, requirements, NodePrefix, RevlogDataConfig, RevlogDeltaConfig,
24 RevlogFeatureConfig, RevlogType, RevlogVersionOptions, UncheckedRevision, 24 RevlogFeatureConfig, RevlogType, RevlogVersionOptions, UncheckedRevision,
25 }; 25 };
26 use crate::{DirstateError, RevlogOpenOptions}; 26 use crate::{DirstateError, RevlogOpenOptions};
27 use std::cell::{Ref, RefCell, RefMut}; 27 use std::cell::{Ref, RefCell, RefMut};
28 use std::collections::HashSet; 28 use std::collections::HashSet;
62 impl From<ConfigError> for RepoError { 62 impl From<ConfigError> for RepoError {
63 fn from(error: ConfigError) -> Self { 63 fn from(error: ConfigError) -> Self {
64 match error { 64 match error {
65 ConfigError::Parse(error) => error.into(), 65 ConfigError::Parse(error) => error.into(),
66 ConfigError::Other(error) => error.into(), 66 ConfigError::Other(error) => error.into(),
67 }
68 }
69 }
70
71 impl From<RepoError> for HgError {
72 fn from(value: RepoError) -> Self {
73 match value {
74 RepoError::NotFound { at } => HgError::abort(
75 format!(
76 "abort: no repository found in '{}' (.hg not found)!",
77 at.display()
78 ),
79 exit_codes::ABORT,
80 None,
81 ),
82 RepoError::ConfigParseError(config_parse_error) => {
83 HgError::Abort {
84 message: String::from_utf8_lossy(
85 &config_parse_error.message,
86 )
87 .to_string(),
88 detailed_exit_code: exit_codes::CONFIG_PARSE_ERROR_ABORT,
89 hint: None,
90 }
91 }
92 RepoError::Other(hg_error) => hg_error,
67 } 93 }
68 } 94 }
69 } 95 }
70 96
71 impl Repo { 97 impl Repo {