Mercurial > public > mercurial-scm > hg-stable
diff rust/rhg/src/error.rs @ 49499:ffd4b1f1c9cb
rhg: add sparse support
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 19 Jul 2022 15:37:45 +0200 |
parents | 3f86ee422095 |
children | 9f14126cfc4c |
line wrap: on
line diff
--- a/rust/rhg/src/error.rs Tue Jul 19 15:37:09 2022 +0200 +++ b/rust/rhg/src/error.rs Tue Jul 19 15:37:45 2022 +0200 @@ -8,6 +8,7 @@ use hg::exit_codes; use hg::repo::RepoError; use hg::revlog::revlog::RevlogError; +use hg::sparse::SparseConfigError; use hg::utils::files::get_bytes_from_path; use hg::{DirstateError, DirstateMapError, StatusError}; use std::convert::From; @@ -52,6 +53,18 @@ } } + pub fn abort_with_exit_code_bytes( + message: impl AsRef<[u8]>, + detailed_exit_code: exit_codes::ExitCode, + ) -> Self { + // TODO: use this everywhere it makes sense instead of the string + // version. + CommandError::Abort { + message: message.as_ref().into(), + detailed_exit_code, + } + } + pub fn unsupported(message: impl AsRef<str>) -> Self { CommandError::UnsupportedFeature { message: utf8_to_local(message.as_ref()).into(), @@ -212,3 +225,33 @@ HgError::from(error).into() } } + +impl From<SparseConfigError> for CommandError { + fn from(e: SparseConfigError) -> Self { + match e { + SparseConfigError::IncludesAfterExcludes { context } => { + Self::abort_with_exit_code_bytes( + format_bytes!( + b"{} config cannot have includes after excludes", + context + ), + exit_codes::CONFIG_PARSE_ERROR_ABORT, + ) + } + SparseConfigError::EntryOutsideSection { context, line } => { + Self::abort_with_exit_code_bytes( + format_bytes!( + b"{} config entry outside of section: {}", + context, + &line, + ), + exit_codes::CONFIG_PARSE_ERROR_ABORT, + ) + } + SparseConfigError::HgError(e) => Self::from(e), + SparseConfigError::PatternError(e) => { + Self::unsupported(format!("{}", e)) + } + } + } +}