diff --git a/signal-gateway-code-tool/src/cached.rs b/signal-gateway-code-tool/src/cached.rs index 54cd039..cdfc129 100644 --- a/signal-gateway-code-tool/src/cached.rs +++ b/signal-gateway-code-tool/src/cached.rs @@ -2,7 +2,7 @@ use flate2::read::GzDecoder; use globset::GlobSet; -use std::{collections::HashMap, io::Read}; +use std::{collections::BTreeMap, io::Read}; use tar::Archive; use tracing::info; @@ -27,8 +27,8 @@ impl CachedFile { pub struct CachedTarball { /// The git SHA this tarball corresponds to. pub sha: String, - /// Map from file path to file contents. - pub files: HashMap, + /// Map from file path to file contents (sorted by path). + pub files: BTreeMap, } impl CachedTarball { @@ -58,11 +58,11 @@ fn extract_files( tarball: &[u8], glob_filter: Option<&GlobSet>, include_non_utf8: bool, -) -> Result, String> { +) -> Result, String> { let decoder = GzDecoder::new(tarball); let mut archive = Archive::new(decoder); - let mut files = HashMap::new(); + let mut files = BTreeMap::new(); for entry in archive .entries() diff --git a/signal-gateway-code-tool/src/lib.rs b/signal-gateway-code-tool/src/lib.rs index f8014fd..9fa4577 100644 --- a/signal-gateway-code-tool/src/lib.rs +++ b/signal-gateway-code-tool/src/lib.rs @@ -291,15 +291,13 @@ impl CodeTool { .map_err(|e| format!("Invalid glob pattern: {e}"))? .compile_matcher(); - let mut matches: Vec<&str> = cached + let matches: Vec<&str> = cached .files .keys() .filter(|path| glob.is_match(path)) .map(|s| s.as_str()) .collect(); - matches.sort(); - if matches.is_empty() { Ok(format!("No files matching '{}'", pattern)) } else { @@ -371,10 +369,7 @@ impl CodeTool { let mut file_count = 0; const MAX_MATCHES: usize = 100; - let mut sorted_files: Vec<_> = cached.files.iter().collect(); - sorted_files.sort_by_key(|(path, _)| *path); - - 'outer: for (path, file) in sorted_files { + 'outer: for (path, file) in &cached.files { // Skip if path doesn't match prefix if let Some(prefix) = prefix && !path.starts_with(prefix)