aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ts
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/ts')
-rw-r--r--pkgs/by-name/ts/tskm/src/interface/input/mod.rs32
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)