##// END OF EJS Templates
rust: implement `From<SparseConfigWarning>` for `HgError`...
Raphaël Gomès -
r52936:ae1ab6d7 default
parent child Browse files
Show More
@@ -24,7 +24,7 const DIRSTATE_FILENAME: &str = "narrows
24 /// as part of wire protocol commands. That means that changes to this
24 /// as part of wire protocol commands. That means that changes to this
25 /// data structure influence the wire protocol and should not be taken
25 /// data structure influence the wire protocol and should not be taken
26 /// lightly - especially removals.
26 /// lightly - especially removals.
27 const VALID_PREFIXES: [&str; 2] = ["path:", "rootfilesin:"];
27 pub const VALID_PREFIXES: [&str; 2] = ["path:", "rootfilesin:"];
28
28
29 /// Return the matcher for the current narrow spec, and all configuration
29 /// Return the matcher for the current narrow spec, and all configuration
30 /// warnings to display.
30 /// warnings to display.
@@ -1,14 +1,16
1 use std::{collections::HashSet, path::Path};
1 use std::{collections::HashSet, fmt::Display, path::Path};
2
2
3 use format_bytes::{write_bytes, DisplayBytes};
3 use format_bytes::{format_bytes, write_bytes, DisplayBytes};
4
4
5 use crate::{
5 use crate::{
6 errors::HgError,
6 errors::HgError,
7 exit_codes::STATE_ERROR,
7 filepatterns::parse_pattern_file_contents,
8 filepatterns::parse_pattern_file_contents,
8 matchers::{
9 matchers::{
9 AlwaysMatcher, DifferenceMatcher, IncludeMatcher, Matcher,
10 AlwaysMatcher, DifferenceMatcher, IncludeMatcher, Matcher,
10 UnionMatcher,
11 UnionMatcher,
11 },
12 },
13 narrow::VALID_PREFIXES,
12 operations::cat,
14 operations::cat,
13 repo::Repo,
15 repo::Repo,
14 requirements::SPARSE_REQUIREMENT,
16 requirements::SPARSE_REQUIREMENT,
@@ -36,6 +38,15 impl DisplayBytes for SparseConfigContex
36 }
38 }
37 }
39 }
38
40
41 impl Display for SparseConfigContext {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 match self {
44 SparseConfigContext::Sparse => write!(f, "sparse"),
45 SparseConfigContext::Narrow => write!(f, "narrow"),
46 }
47 }
48 }
49
39 /// Possible warnings when reading sparse configuration
50 /// Possible warnings when reading sparse configuration
40 #[derive(Debug, derive_more::From)]
51 #[derive(Debug, derive_more::From)]
41 pub enum SparseWarning {
52 pub enum SparseWarning {
@@ -82,6 +93,59 pub enum SparseConfigError {
82 PatternError(PatternError),
93 PatternError(PatternError),
83 }
94 }
84
95
96 impl From<SparseConfigError> for HgError {
97 fn from(value: SparseConfigError) -> Self {
98 match value {
99 SparseConfigError::IncludesAfterExcludes { context } => {
100 HgError::Abort {
101 message: format!(
102 "{} config cannot have includes after excludes",
103 context,
104 ),
105 detailed_exit_code: STATE_ERROR,
106 hint: None,
107 }
108 }
109 SparseConfigError::EntryOutsideSection { context, line } => {
110 HgError::Abort {
111 message: format!(
112 "{} config entry outside of section: {}",
113 context,
114 String::from_utf8_lossy(&line)
115 ),
116 detailed_exit_code: STATE_ERROR,
117 hint: None,
118 }
119 }
120 SparseConfigError::IncludesInNarrow => HgError::Abort {
121 message: "including other spec files using '%include' is not \
122 supported in narrowspec"
123 .to_string(),
124 detailed_exit_code: STATE_ERROR,
125 hint: None,
126 },
127 SparseConfigError::InvalidNarrowPrefix(vec) => HgError::Abort {
128 message: String::from_utf8_lossy(&format_bytes!(
129 b"invalid prefix on narrow pattern: {}",
130 vec
131 ))
132 .to_string(),
133 detailed_exit_code: STATE_ERROR,
134 hint: Some(format!(
135 "narrow patterns must begin with one of the following: {}",
136 VALID_PREFIXES.join(", ")
137 )),
138 },
139 SparseConfigError::HgError(hg_error) => hg_error,
140 SparseConfigError::PatternError(pattern_error) => HgError::Abort {
141 message: pattern_error.to_string(),
142 detailed_exit_code: STATE_ERROR,
143 hint: None,
144 },
145 }
146 }
147 }
148
85 /// Parse sparse config file content.
149 /// Parse sparse config file content.
86 pub(crate) fn parse_config(
150 pub(crate) fn parse_config(
87 raw: &[u8],
151 raw: &[u8],
General Comments 0
You need to be logged in to leave comments. Login now