diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-06-07 11:04:30 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-06-07 11:04:30 +0200 |
commit | 8d4f04b0da0f9aceab436d21c7cc959d7f935a96 (patch) | |
tree | 9b9898a5fd6835028264d86df469ffe4167048f3 | |
parent | pkgs/tskm: Use correct key for `default-features` in `md5` dep (diff) | |
download | nixos-config-8d4f04b0da0f9aceab436d21c7cc959d7f935a96.zip |
pkgs/tskm: Merge tags of inputs, which have to same url
-rw-r--r-- | pkgs/by-name/ts/tskm/src/interface/input/mod.rs | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/pkgs/by-name/ts/tskm/src/interface/input/mod.rs b/pkgs/by-name/ts/tskm/src/interface/input/mod.rs index 747ba349..1d1d67f4 100644 --- a/pkgs/by-name/ts/tskm/src/interface/input/mod.rs +++ b/pkgs/by-name/ts/tskm/src/interface/input/mod.rs @@ -9,7 +9,12 @@ // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. use std::{ - collections::HashSet, fmt::Display, fs, io::Write, path::PathBuf, process::Command, + collections::{HashMap, HashSet}, + fmt::Display, + fs, + io::Write, + path::PathBuf, + process::Command, str::FromStr, }; @@ -58,7 +63,7 @@ impl Tag { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Input { url: Url, tags: HashSet<Tag>, @@ -175,7 +180,7 @@ impl Input { Ok(()) } - /// Get all previously [`Self::commit`]ed inputs. + /// Get all previously [committed][`Self::commit`] inputs. /// /// # Errors /// When IO handling fails. @@ -203,13 +208,20 @@ impl Input { let url_values = fs::read_to_string(PathBuf::from(url_value_file))?; - output.extend( - url_values - .lines() - .map(Self::from_str) - .collect::<Result<Vec<Self>, _>>()? - .into_iter(), - ); + let mut inputs: HashMap<Url, Self> = HashMap::new(); + for input in url_values + .lines() + .map(Self::from_str) + .collect::<Result<Vec<Self>, _>>()? + { + if let Some(found) = inputs.get_mut(&input.url) { + found.tags = found.tags.union(&input.tags).cloned().collect(); + } else { + assert_eq!(inputs.insert(input.url.clone(), input), None); + } + } + + output.extend(inputs.drain().map(|(_, value)| value)); } Ok(output) |