From 06a9d5d0d483ccf09706b35e7267558b91cbdb27 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Wed, 6 May 2026 05:22:45 +0200 Subject: [PATCH] Refactor hash resolution logic to ensure correct chronological ordering of commits --- src-tauri/src/main.rs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 106fb29..ffd19f9 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -877,17 +877,7 @@ fn reword_commits_sequentially( let all_raw = run_git(repo_path, &["log", "--format=%H"])?; let all_commits: Vec = all_raw.lines().map(|s| s.to_string()).collect(); - let mut full_hashes: Vec = hashes - .iter() - .filter_map(|h| all_commits.iter().find(|full| full.starts_with(h)).cloned()) - .collect(); - full_hashes.sort_by_key(|h| { - all_commits - .iter() - .position(|full| full == h) - .unwrap_or(usize::MAX) - }); - full_hashes.reverse(); + let full_hashes = resolve_reword_hashes_newest_first(&all_commits, hashes); let temp_dir = TempDir::new().map_err(|e| e.to_string())?; let sequence_path = temp_dir.path().join(if cfg!(windows) { @@ -970,6 +960,20 @@ fn reword_commits_sequentially( Ok(()) } +fn resolve_reword_hashes_newest_first(all_commits: &[String], hashes: &[String]) -> Vec { + let mut full_hashes: Vec = hashes + .iter() + .filter_map(|h| all_commits.iter().find(|full| full.starts_with(h)).cloned()) + .collect(); + full_hashes.sort_by_key(|h| { + all_commits + .iter() + .position(|full| full == h) + .unwrap_or(usize::MAX) + }); + full_hashes +} + #[cfg(unix)] fn set_executable(path: &Path) -> CommandResult<()> { use std::os::unix::fs::PermissionsExt;