configs: return bytes for config parsers validation results

Summary:
Previously the return type was String which, in Python 2, could turn into bytes or
unicode depending on the contents of the string. We always want bytes in Python
2, so let's use the Str type instead.

Reviewed By: quark-zju

Differential Revision: D21794189

fbshipit-source-id: 6493fbacab354a78476f522fc3c41b7336dbbdb1
This commit is contained in:
Durham Goode 2020-06-01 09:43:16 -07:00 committed by Facebook GitHub Bot
parent 8bc207b768
commit 995a2852c1
3 changed files with 16 additions and 6 deletions

View File

@ -1601,7 +1601,7 @@ class ui(object):
)
outfile.write("\0")
if debug:
ui.write_err(
self.write_err(
"%s\n"
% pycompat.toutf8lossy(
json.dumps({"data": opts, "category": ref})

View File

@ -148,7 +148,7 @@ py_class!(pub class config |py| {
superset_source: String,
subset_sources: Vec<String>,
whitelist: Vec<(String, String)>
) -> PyResult<Vec<(String, String, Option<String>, Option<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 results = self.cfg(py).borrow_mut().ensure_location_supersets(superset_source, subset_sources, whitelist);
@ -156,17 +156,17 @@ py_class!(pub class config |py| {
return Ok(vec![]);
}
let mut output: Vec<(String, String, Option<String>, Option<String>)> = vec![];
let mut output: Vec<(Str, Str, Option<Str>, Option<Str>)> = vec![];
for ((section, key), value) in results.missing.iter() {
output.push((section.to_string(), key.to_string(), None, Some(value.to_string())));
output.push((section.to_string().into(), key.to_string().into(), None, Some(value.to_string().into())));
}
for ((section, key), value) in results.extra.iter() {
output.push((section.to_string(), key.to_string(), Some(value.to_string()), None));
output.push((section.to_string().into(), key.to_string().into(), Some(value.to_string().into()), None));
}
for ((section, key), super_value, sub_value) in results.mismatched.iter() {
output.push((section.to_string(), key.to_string(), Some(super_value.to_string()), Some(sub_value.to_string())));
output.push((section.to_string().into(), key.to_string().into(), Some(super_value.to_string().into()), Some(sub_value.to_string().into())));
}
Ok(output)

View File

@ -162,3 +162,13 @@ Verify we load and verify dynamicconfigs during clone
[hooks]
pretxnclose=printf "Hook ran!\n"
Verify unicode characters in configs can be logged to our sampling extension
$ unset SCM_SAMPLING_FILEPATH
$ cat >> good_hgrc <<EOF
> [foo]
> bar = Å
> EOF
$ hg -R client2 log -q -r . --configfile $TESTTMP/good_hgrc --config configs.validatedynamicconfig=True --config configs.mismatchsampling=1 --config extensions.sampling= --config sampling.filepath=$TESTTMP/sampling.log --config sampling.key.config_mismatch=mismatches --config configs.testdynamicconfigsubset=good_hgrc
-1:000000000000
$ cat $TESTTMP/sampling.log
{"category": "mismatches", "data": {"actual": null, "config": "foo.bar", "expected": "\\u00c5", "metrics_type": "config_mismatch", "msg": "Config mismatch: foo.bar has 'None' (dynamic) vs '\\u00c5' (file)\\n", "repo": "reponame-default"}}\x00{"category": "mismatches", "data": {"actual": null, "config": "foo.bar", "expected": "\\u00c5", "metrics_type": "config_mismatch", "msg": "Config mismatch: foo.bar has 'None' (dynamic) vs '\\u00c5' (file)\\n", "repo": "reponame-default"}}\x00 (no-eol) (esc)