Replace HashSet with IndexSet to preserve order

Also clean up some match arms.
This commit is contained in:
2026-04-27 20:46:04 +02:00
parent 44d917c264
commit d196662ac6
3 changed files with 40 additions and 16 deletions

23
Cargo.lock generated
View File

@@ -154,12 +154,24 @@ version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]] [[package]]
name = "find-msvc-tools" name = "find-msvc-tools"
version = "0.1.9" version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
[[package]]
name = "hashbrown"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51"
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.5.0" version = "0.5.0"
@@ -190,6 +202,16 @@ dependencies = [
"cc", "cc",
] ]
[[package]]
name = "indexmap"
version = "2.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]] [[package]]
name = "is_terminal_polyfill" name = "is_terminal_polyfill"
version = "1.70.2" version = "1.70.2"
@@ -417,4 +439,5 @@ version = "0.2.3"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap", "clap",
"indexmap",
] ]

View File

@@ -7,3 +7,4 @@ publish = false
[dependencies] [dependencies]
chrono = "0.4.44" chrono = "0.4.44"
clap = { version = "4.6.1", features = ["derive"] } clap = { version = "4.6.1", features = ["derive"] }
indexmap = "2.14.0"

View File

@@ -2,12 +2,13 @@ use crate::command;
use crate::progress::BackupEvent; use crate::progress::BackupEvent;
use crate::progress::filter; use crate::progress::filter;
use chrono::{Local, NaiveDateTime}; use chrono::{Local, NaiveDateTime};
use indexmap::set::IndexSet;
use std::collections::HashSet; use std::collections::HashSet;
use std::fmt; use std::fmt;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
pub struct Job { pub struct Job {
datasets: HashSet<String>, datasets: IndexSet<String>,
target: String, target: String,
source_zfs_command: Vec<String>, source_zfs_command: Vec<String>,
target_zfs_command: Vec<String>, target_zfs_command: Vec<String>,
@@ -284,24 +285,23 @@ fn parse_command(commandstr: &str) -> Vec<String> {
for c in commandstr.chars() { for c in commandstr.chars() {
match c { match c {
'\'' => { '\'' if !in_double_quote => {
if !in_double_quote {
in_single_quote = !in_single_quote; in_single_quote = !in_single_quote;
} else { }
'\'' => {
arg.push(c); arg.push(c);
} }
'"' if !in_single_quote => {
in_double_quote = !in_double_quote;
} }
'"' => { '"' => {
if !in_single_quote {
in_double_quote = !in_double_quote;
} else {
arg.push(c); arg.push(c);
} }
' ' if in_single_quote || in_double_quote => {
arg.push(c);
} }
' ' => { ' ' => {
if in_single_quote || in_double_quote { if !arg.is_empty() {
arg.push(c);
} else if !arg.is_empty() {
command.push(arg.clone()); command.push(arg.clone());
arg.clear(); arg.clear();
} }
@@ -362,7 +362,7 @@ impl JobBuilder {
} }
pub fn build(self) -> Result<Job, String> { pub fn build(self) -> Result<Job, String> {
let mut datasets: HashSet<String> = HashSet::new(); let mut datasets: IndexSet<String> = IndexSet::new();
for source in &self.sources { for source in &self.sources {
let recurse = source.ends_with("/..."); let recurse = source.ends_with("/...");
let source = source.trim_end_matches("/..."); let source = source.trim_end_matches("/...");
@@ -382,7 +382,7 @@ impl JobBuilder {
return Err(String::from("no matching source datasets found")); return Err(String::from("no matching source datasets found"));
} }
Ok(Job { Ok(Job {
datasets: datasets, datasets,
target: self.target, target: self.target,
source_zfs_command: self.source_zfs_command, source_zfs_command: self.source_zfs_command,
target_zfs_command: self.target_zfs_command, target_zfs_command: self.target_zfs_command,