##// END OF EJS Templates
rhg: Add an allow-list of ignored extensions...
Simon Sapin -
r47468:1a036d33 default
parent child Browse files
Show More
@@ -13,6 +13,7 b' use crate::config::layer::{'
13 ConfigError, ConfigLayer, ConfigOrigin, ConfigValue,
13 ConfigError, ConfigLayer, ConfigOrigin, ConfigValue,
14 };
14 };
15 use crate::utils::files::get_bytes_from_os_str;
15 use crate::utils::files::get_bytes_from_os_str;
16 use crate::utils::SliceExt;
16 use format_bytes::{write_bytes, DisplayBytes};
17 use format_bytes::{write_bytes, DisplayBytes};
17 use std::collections::HashSet;
18 use std::collections::HashSet;
18 use std::env;
19 use std::env;
@@ -339,6 +340,31 b' impl Config {'
339 Ok(self.get_option(section, item)?.unwrap_or(false))
340 Ok(self.get_option(section, item)?.unwrap_or(false))
340 }
341 }
341
342
343 /// Returns the corresponding list-value in the config if found, or `None`.
344 ///
345 /// This is appropriate for new configuration keys. The value syntax is
346 /// **not** the same as most existing list-valued config, which has Python
347 /// parsing implemented in `parselist()` in `mercurial/config.py`.
348 /// Faithfully porting that parsing algorithm to Rust (including behavior
349 /// that are arguably bugs) turned out to be non-trivial and hasn’t been
350 /// completed as of this writing.
351 ///
352 /// Instead, the "simple" syntax is: split on comma, then trim leading and
353 /// trailing whitespace of each component. Quotes or backslashes are not
354 /// interpreted in any way. Commas are mandatory between values. Values
355 /// that contain a comma are not supported.
356 pub fn get_simple_list(
357 &self,
358 section: &[u8],
359 item: &[u8],
360 ) -> Option<impl Iterator<Item = &[u8]>> {
361 self.get(section, item).map(|value| {
362 value
363 .split(|&byte| byte == b',')
364 .map(|component| component.trim())
365 })
366 }
367
342 /// Returns the raw value bytes of the first one found, or `None`.
368 /// Returns the raw value bytes of the first one found, or `None`.
343 pub fn get(&self, section: &[u8], item: &[u8]) -> Option<&[u8]> {
369 pub fn get(&self, section: &[u8], item: &[u8]) -> Option<&[u8]> {
344 self.get_inner(section, item)
370 self.get_inner(section, item)
@@ -365,12 +365,20 b' fn check_extensions(config: &Config) -> '
365 unsupported.remove(supported);
365 unsupported.remove(supported);
366 }
366 }
367
367
368 if let Some(ignored_list) =
369 config.get_simple_list(b"rhg", b"ignored-extensions")
370 {
371 for ignored in ignored_list {
372 unsupported.remove(ignored);
373 }
374 }
375
368 if unsupported.is_empty() {
376 if unsupported.is_empty() {
369 Ok(())
377 Ok(())
370 } else {
378 } else {
371 Err(CommandError::UnsupportedFeature {
379 Err(CommandError::UnsupportedFeature {
372 message: format_bytes!(
380 message: format_bytes!(
373 b"extensions: {}",
381 b"extensions: {} (consider adding them to 'rhg.ignored-extensions' config)",
374 join(unsupported, b", ")
382 join(unsupported, b", ")
375 ),
383 ),
376 })
384 })
General Comments 0
You need to be logged in to leave comments. Login now