diff rust/hg-core/src/config/config.rs @ 47950:6961eca0b3ee

rhg: Port Python’s `ui.configlist` as `Config::get_list` This new method is not used yet outside of its own unit tests, so this changeset should make no observable change. The Rust parser implementation attempts to exactly replicate the behavior of the Python one, even in edge cases where that behavior is… surprising. New unit tests capture some of these edge cases. This started as a line-by-line port. The main changes are: * Pass around a parser mode enum instead of parser functions * Inline the whole parser into one function * Use `[u8]::get` which returns an `Option`, instead of indexing after explicitly checking the length. Differential Revision: https://phab.mercurial-scm.org/D11389
author Simon Sapin <simon.sapin@octobus.net>
date Wed, 17 Feb 2021 20:49:53 +0100
parents 3237ed4dcda4
children cff41e168c25
line wrap: on
line diff
--- a/rust/hg-core/src/config/config.rs	Fri Sep 03 16:37:20 2021 +0200
+++ b/rust/hg-core/src/config/config.rs	Wed Feb 17 20:49:53 2021 +0100
@@ -388,6 +388,16 @@
         })
     }
 
+    /// If there is an `item` value in `section`, parse and return a list of
+    /// byte strings.
+    pub fn get_list(
+        &self,
+        section: &[u8],
+        item: &[u8],
+    ) -> Option<Vec<Vec<u8>>> {
+        self.get(section, item).map(values::parse_list)
+    }
+
     /// Returns the raw value bytes of the first one found, or `None`.
     pub fn get(&self, section: &[u8], item: &[u8]) -> Option<&[u8]> {
         self.get_inner(section, item)