mirror of
https://github.com/facebook/sapling.git
synced 2024-12-26 06:21:48 +03:00
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
This commit is contained in:
parent
990926cbc6
commit
2c7f30d0c4
@ -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<String>,
|
||||
whitelist: Vec<(String, String)>
|
||||
allow_list: Vec<(String, String)>
|
||||
) -> PyResult<Vec<(Str, Str, Option<Str>, Option<Str>)>> {
|
||||
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![]);
|
||||
}
|
||||
|
@ -426,7 +426,7 @@ impl ConfigSet {
|
||||
&mut self,
|
||||
superset_location: String,
|
||||
subset_locations: Vec<String>,
|
||||
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<Text>,
|
||||
@ -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(
|
||||
|
@ -39,9 +39,9 @@ pub trait OptionsHgExt {
|
||||
fn remap_sections<K: Eq + Hash + Into<Text>, V: Into<Text>>(self, remap: HashMap<K, V>)
|
||||
-> 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<B: Clone + Into<Text>>(self, sections: Vec<B>) -> Self;
|
||||
fn filter_sections<B: Clone + Into<Text>>(self, include_sections: Vec<B>) -> 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<String> = 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<Text> =
|
||||
// [defaults] and [commands] are always excluded.
|
||||
let mut section_exclude_list: HashSet<Text> =
|
||||
["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<Text> = [
|
||||
// These configs under [ui] are always excluded.
|
||||
let mut ui_exclude_list: HashSet<Text> = [
|
||||
"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<Text>| {
|
||||
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<B: Clone + Into<Text>>(self, sections: Vec<B>) -> Self {
|
||||
let whitelist: HashSet<Text> = sections
|
||||
fn filter_sections<B: Clone + Into<Text>>(self, include_sections: Vec<B>) -> Self {
|
||||
let include_list: HashSet<Text> = include_sections
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|section| section.into())
|
||||
.collect();
|
||||
|
||||
let filter = move |section: Text, name: Text, value: Option<Text>| {
|
||||
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\
|
||||
|
@ -83,7 +83,7 @@ class ConfigParserTests(unittest.TestCase):
|
||||
)
|
||||
eq(cfg.sources("c", "x"), [("1", ("<builtin>", 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")
|
||||
|
Loading…
Reference in New Issue
Block a user