rhg: support "!" syntax for disabling extensions
authorRaphaël Gomès <rgomes@octobus.net>
Mon, 11 Jul 2022 17:27:39 +0200
changeset 49477 f3cd2d6eeef9
parent 49476 5846bc8a2855
child 49478 d8ce883ff1f4
rhg: support "!" syntax for disabling extensions This makes it so that calls in test-log.t do not fall back immediately because of the disabled extension, instead going through the CLI parsing code, which breaks because of invalid UTF-8 in a flag. I *think* clap 3.x+ supports this? I'm not sure, and we have to upgrade the minimum Rust version to use clap 3.x anyway which is out of scope for this series, so let's just kick that can down the road a little bit.
rust/rhg/src/main.rs
tests/test-log.t
--- a/rust/rhg/src/main.rs	Fri May 20 11:02:52 2022 +0100
+++ b/rust/rhg/src/main.rs	Mon Jul 11 17:27:39 2022 +0200
@@ -687,13 +687,18 @@
     }
 
     let enabled: HashSet<&[u8]> = config
-        .get_section_keys(b"extensions")
-        .into_iter()
-        .map(|extension| {
+        .iter_section(b"extensions")
+        .filter_map(|(extension, value)| {
+            if value == b"!" {
+                // Filter out disabled extensions
+                return None;
+            }
             // Ignore extension suboptions. Only `required` exists for now.
             // `rhg` either supports an extension or doesn't, so it doesn't
             // make sense to consider the loading of an extension.
-            extension.split_2(b':').unwrap_or((extension, b"")).0
+            let actual_extension =
+                extension.split_2(b':').unwrap_or((extension, b"")).0;
+            Some(actual_extension)
         })
         .collect();
 
--- a/tests/test-log.t	Fri May 20 11:02:52 2022 +0100
+++ b/tests/test-log.t	Mon Jul 11 17:27:39 2022 +0200
@@ -2157,6 +2157,8 @@
   ... '''.encode('utf-8')) and None
   $ sh < setup.sh
 
+#if no-rhg
+
 test in problematic encoding
   >>> with open('test.sh', 'wb') as f:
   ...     f.write(u'''
@@ -2179,6 +2181,8 @@
   3
   1
 
+#endif
+
   $ cd ..
 
 test hg log on non-existent files and on directories