From 39fdfb5cace85227eaec2694f4064ac7d942e93b Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sun, 12 Jul 2026 11:22:20 +0200 Subject: [PATCH] Add utility functions for fetching, mapping, and reporting commit identities --- src-tauri/src/main.rs | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 2d2859a..6777626 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1070,6 +1070,84 @@ fn resolve_reword_hashes_newest_first(all_commits: &[String], hashes: &[String]) full_hashes } +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +struct CommitIdentity { + tree: String, + author_time: String, + author_name: String, + author_email: String, + subject: String, +} + +fn parse_commit_identity_line(line: &str) -> Option<(String, CommitIdentity)> { + let mut parts = line.splitn(6, '\x1f'); + let hash = parts.next()?.to_string(); + Some(( + hash, + CommitIdentity { + tree: parts.next()?.to_string(), + author_time: parts.next()?.to_string(), + author_name: parts.next()?.to_string(), + author_email: parts.next()?.to_string(), + subject: parts.next().unwrap_or_default().to_string(), + }, + )) +} + +fn current_commit_identities(repo_path: &str) -> HashMap { + let raw = run_git( + repo_path, + &["log", "--format=%H%x1f%T%x1f%at%x1f%an%x1f%ae%x1f%s"], + ) + .unwrap_or_default(); + raw.lines() + .filter_map(parse_commit_identity_line) + .map(|(hash, identity)| (identity, hash)) + .collect() +} + +fn identities_for_hashes(repo_path: &str, hashes: &[String]) -> HashMap { + let wanted: HashSet = hashes + .iter() + .filter_map(|hash| resolve_commit_hash(repo_path, hash)) + .collect(); + current_commit_identities(repo_path) + .into_iter() + .filter_map(|(identity, hash)| { + if wanted.contains(&hash) { + Some((hash, identity)) + } else { + None + } + }) + .collect() +} + +fn emit_rewrite_progress( + app: &AppHandle, + folder_path: &str, + scope: &str, + status: &str, + current: usize, + total: usize, + hash: Option<&str>, + error: Option<&str>, +) { + emit( + app, + "rewrite-progress", + json!({ + "folderPath": folder_path, + "scope": scope, + "status": status, + "current": current, + "total": total, + "hash": hash.map(short_hash), + "error": error, + }), + ); +} + #[cfg(unix)] fn set_executable(path: &Path) -> CommandResult<()> { use std::os::unix::fs::PermissionsExt;