From 2c7f30d0c4a0b5a9dbf6761b5027f22d38aa3017 Mon Sep 17 00:00:00 2001 From: Carolyn Busch Date: Mon, 15 Jun 2020 12:45:26 -0700 Subject: [PATCH] configparser: replace whitelist/blacklist term Summary: Replace usages of whitelist/blacklist with include/exclude/filter/allow. These terms are more descriptive and less likely to contribute to racial stereotyping. More context: https://fb.workplace.com/groups/sourcecontrolteam/permalink/2926049127516414/ Reviewed By: kulshrax Differential Revision: D22039298 fbshipit-source-id: 255c7389ee5ce5e54bbccdfb05ffa4cafc6958e5 --- .../modules/pyconfigparser/src/lib.rs | 8 ++-- eden/scm/lib/configparser/src/config.rs | 8 ++-- eden/scm/lib/configparser/src/hg.rs | 40 +++++++++---------- eden/scm/tests/test-configparser-t.py | 4 +- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/eden/scm/edenscmnative/bindings/modules/pyconfigparser/src/lib.rs b/eden/scm/edenscmnative/bindings/modules/pyconfigparser/src/lib.rs index 876ba381f4..1c6440c052 100644 --- a/eden/scm/edenscmnative/bindings/modules/pyconfigparser/src/lib.rs +++ b/eden/scm/edenscmnative/bindings/modules/pyconfigparser/src/lib.rs @@ -49,7 +49,7 @@ py_class!(pub class config |py| { let mut opts = Options::new().source(source).process_hgplain(); if let Some(sections) = sections { - opts = opts.whitelist_sections(sections); + opts = opts.filter_sections(sections); } if let Some(remap) = remap { let map = remap.into_iter().collect(); @@ -147,11 +147,11 @@ py_class!(pub class config |py| { &self, superset_source: String, subset_sources: Vec, - whitelist: Vec<(String, String)> + allow_list: Vec<(String, String)> ) -> PyResult, Option)>> { - let whitelist = HashSet::from_iter(whitelist.iter().map(|v| (v.0.as_ref(), v.1.as_ref()))); + let allow_list = HashSet::from_iter(allow_list.iter().map(|v| (v.0.as_ref(), v.1.as_ref()))); - let results = self.cfg(py).borrow_mut().ensure_location_supersets(superset_source, subset_sources, whitelist); + let results = self.cfg(py).borrow_mut().ensure_location_supersets(superset_source, subset_sources, allow_list); if results.is_empty() { return Ok(vec![]); } diff --git a/eden/scm/lib/configparser/src/config.rs b/eden/scm/lib/configparser/src/config.rs index 9721f6ecb4..feafa48152 100644 --- a/eden/scm/lib/configparser/src/config.rs +++ b/eden/scm/lib/configparser/src/config.rs @@ -426,7 +426,7 @@ impl ConfigSet { &mut self, superset_location: String, subset_locations: Vec, - whitelist: HashSet<(&str, &str)>, + allow_list: HashSet<(&str, &str)>, ) -> SupersetVerification { let mut result = SupersetVerification::new(); @@ -435,7 +435,7 @@ impl ConfigSet { for (sname, section) in self.sections.iter_mut() { for (kname, values) in section.items.iter_mut() { - if whitelist.contains(&(sname.as_ref(), kname.as_ref())) { + if allow_list.contains(&(sname.as_ref(), kname.as_ref())) { continue; } @@ -916,7 +916,7 @@ pub(crate) mod tests { #[test] fn test_filters() { - fn blacklist_section_x( + fn exclude_list_section_x( section: Text, name: Text, value: Option, @@ -946,7 +946,7 @@ pub(crate) mod tests { let mut cfg = ConfigSet::new(); let opts = Options::new() - .append_filter(Box::new(blacklist_section_x)) + .append_filter(Box::new(exclude_list_section_x)) .append_filter(Box::new(swap_name_value)) .append_filter(Box::new(rename_section_to_z)); cfg.parse( diff --git a/eden/scm/lib/configparser/src/hg.rs b/eden/scm/lib/configparser/src/hg.rs index 83791be71f..699c148ba6 100644 --- a/eden/scm/lib/configparser/src/hg.rs +++ b/eden/scm/lib/configparser/src/hg.rs @@ -39,9 +39,9 @@ pub trait OptionsHgExt { fn remap_sections, V: Into>(self, remap: HashMap) -> Self; - /// Set section whitelist. Sections outside the whitelist won't be loaded. + /// Filter sections. Sections outside include_sections won't be loaded. /// This is implemented via `append_filter`. - fn whitelist_sections>(self, sections: Vec) -> Self; + fn filter_sections>(self, include_sections: Vec) -> Self; } pub trait ConfigSetHgExt { @@ -102,27 +102,27 @@ impl OptionsHgExt for Options { let plain_set = env::var(HGPLAIN).is_ok(); let plain_except = env::var(HGPLAINEXCEPT); if plain_set || plain_except.is_ok() { - let (section_blacklist, ui_blacklist) = { + let (section_exclude_list, ui_exclude_list) = { let plain_exceptions: HashSet = plain_except .unwrap_or_else(|_| "".to_string()) .split(',') .map(|s| s.to_string()) .collect(); - // [defaults] and [commands] are always blacklisted. - let mut section_blacklist: HashSet = + // [defaults] and [commands] are always excluded. + let mut section_exclude_list: HashSet = ["defaults", "commands"].iter().map(|&s| s.into()).collect(); - // [alias], [revsetalias], [templatealias] are blacklisted if they are outside + // [alias], [revsetalias], [templatealias] are excluded if they are outside // HGPLAINEXCEPT. for &name in ["alias", "revsetalias", "templatealias"].iter() { if !plain_exceptions.contains(name) { - section_blacklist.insert(Text::from(name)); + section_exclude_list.insert(Text::from(name)); } } - // These configs under [ui] are always blacklisted. - let mut ui_blacklist: HashSet = [ + // These configs under [ui] are always excluded. + let mut ui_exclude_list: HashSet = [ "debug", "fallbackencoding", "quiet", @@ -136,17 +136,17 @@ impl OptionsHgExt for Options { .iter() .map(|&s| s.into()) .collect(); - // exitcodemask is blacklisted if exitcode is outside HGPLAINEXCEPT. + // exitcodemask is excluded if exitcode is outside HGPLAINEXCEPT. if !plain_exceptions.contains("exitcode") { - ui_blacklist.insert("exitcodemask".into()); + ui_exclude_list.insert("exitcodemask".into()); } - (section_blacklist, ui_blacklist) + (section_exclude_list, ui_exclude_list) }; let filter = move |section: Text, name: Text, value: Option| { - if section_blacklist.contains(§ion) - || (section.as_ref() == "ui" && ui_blacklist.contains(&name)) + if section_exclude_list.contains(§ion) + || (section.as_ref() == "ui" && ui_exclude_list.contains(&name)) { None } else { @@ -160,17 +160,17 @@ impl OptionsHgExt for Options { } } - /// Set section whitelist. Sections outside the whitelist won't be loaded. + /// Filter sections. Sections outside of include_sections won't be loaded. /// This is implemented via `append_filter`. - fn whitelist_sections>(self, sections: Vec) -> Self { - let whitelist: HashSet = sections + fn filter_sections>(self, include_sections: Vec) -> Self { + let include_list: HashSet = include_sections .iter() .cloned() .map(|section| section.into()) .collect(); let filter = move |section: Text, name: Text, value: Option| { - if whitelist.contains(§ion) { + if include_list.contains(§ion) { Some((section, name, value)) } else { None @@ -837,8 +837,8 @@ mod tests { } #[test] - fn test_section_whitelist() { - let opts = Options::new().whitelist_sections(vec!["x", "y"]); + fn test_section_filter() { + let opts = Options::new().filter_sections(vec!["x", "y"]); let mut cfg = ConfigSet::new(); cfg.parse( "[x]\n\ diff --git a/eden/scm/tests/test-configparser-t.py b/eden/scm/tests/test-configparser-t.py index bbbae47971..40249f88b6 100644 --- a/eden/scm/tests/test-configparser-t.py +++ b/eden/scm/tests/test-configparser-t.py @@ -83,7 +83,7 @@ class ConfigParserTests(unittest.TestCase): ) eq(cfg.sources("c", "x"), [("1", ("", 6, 7, 2), "parse")]) - def testSectionWhitelist(self): + def testSectionIncludelist(self): cfg = createConfig() cfg.readpath("a.rc", "readpath", ["a"], None, None) eq(cfg.sections(), ["a"]) @@ -93,7 +93,7 @@ class ConfigParserTests(unittest.TestCase): cfg.readpath("a.rc", "readpath", None, [("a", "x")], None) eq(cfg.sections(), ["x", "b"]) - def testWhitelist(self): + def testIncludelist(self): cfg = createConfig() cfg.readpath("a.rc", "readpath", None, None, [("a", "y")]) eq(cfg.get("a", "x"), "1")