From b4883123b2ca6d8f956094380924c55d9b602c4b Mon Sep 17 00:00:00 2001 From: Detlev Casanova <detlev.casanova@collabora.com> Date: Wed, 7 Jun 2023 10:20:19 -0400 Subject: [PATCH] d/patches: tsort: Switch to BTreeMap and BTreeSet This patch makes sure that tsort behaves the same way as in the C version. Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com> --- ...ort-Switch-to-BTreeHash-and-BTreeSet.patch | 51 +++++++++++++++++++ debian/patches/series | 1 + 2 files changed, 52 insertions(+) create mode 100644 debian/patches/apertis/tsort-Switch-to-BTreeHash-and-BTreeSet.patch diff --git a/debian/patches/apertis/tsort-Switch-to-BTreeHash-and-BTreeSet.patch b/debian/patches/apertis/tsort-Switch-to-BTreeHash-and-BTreeSet.patch new file mode 100644 index 0000000..323a519 --- /dev/null +++ b/debian/patches/apertis/tsort-Switch-to-BTreeHash-and-BTreeSet.patch @@ -0,0 +1,51 @@ +From: Detlev Casanova <detlev.casanova@collabora.com> +Date: Fri, 2 Jun 2023 14:42:47 -0400 +Subject: tsort: Switch to BTreeHash and BTreeSet + +Using HashMap and HashSet give a valid topological sort, but the output +will change randomly at each run. + +BTree based structures will guarantee that the output is always ordered +in the same way. + +This also makes the ouptut similar to the output of the C version of the +tools, on which some applications rely. + +Forwarded: https://github.com/uutils/coreutils/pull/4931 +--- + src/uu/tsort/src/tsort.rs | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs +index 1ef8537..a0c149f 100644 +--- a/src/uu/tsort/src/tsort.rs ++++ b/src/uu/tsort/src/tsort.rs +@@ -6,7 +6,7 @@ + // * For the full copyright and license information, please view the LICENSE + // * file that was distributed with this source code. + use clap::{crate_version, Arg, Command}; +-use std::collections::{HashMap, HashSet}; ++use std::collections::{BTreeMap, BTreeSet}; + use std::fs::File; + use std::io::{stdin, BufRead, BufReader, Read}; + use std::path::Path; +@@ -105,8 +105,8 @@ pub fn uu_app() -> Command { + // but using integer may improve performance. + #[derive(Default)] + struct Graph { +- in_edges: HashMap<String, HashSet<String>>, +- out_edges: HashMap<String, Vec<String>>, ++ in_edges: BTreeMap<String, BTreeSet<String>>, ++ out_edges: BTreeMap<String, Vec<String>>, + result: Vec<String>, + } + +@@ -124,7 +124,7 @@ impl Graph { + } + + fn init_node(&mut self, n: &str) { +- self.in_edges.insert(n.to_string(), HashSet::new()); ++ self.in_edges.insert(n.to_string(), BTreeSet::new()); + self.out_edges.insert(n.to_string(), vec![]); + } + diff --git a/debian/patches/series b/debian/patches/series index a00f9b9..88aadf7 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -34,3 +34,4 @@ unbreak-s390x.patch # Apertis patches apertis/HACK-cp-mv-add-dummy-missing-arguments.patch apertis/Add-hack-for-missing-argument-to-mkdir.patch +apertis/tsort-Switch-to-BTreeHash-and-BTreeSet.patch -- GitLab