From c49e4128060b381dfcfa4a4af23eea35cc93d12b Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Wed, 5 Aug 2026 02:29:59 +0200 Subject: [PATCH 1/5] Update RUST_VERSION --- app/src/main/rust/RUST_VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/rust/RUST_VERSION b/app/src/main/rust/RUST_VERSION index 6506fb3d..0c818f53 100644 --- a/app/src/main/rust/RUST_VERSION +++ b/app/src/main/rust/RUST_VERSION @@ -1 +1 @@ -1.91.1 \ No newline at end of file +1.97.1 \ No newline at end of file From 014d69c4ec567f54e32d6be2f4a2ee7e6303b25f Mon Sep 17 00:00:00 2001 From: wiiznokes <78230769+wiiznokes@users.noreply.github.com> Date: Wed, 5 Aug 2026 02:30:23 +0200 Subject: [PATCH 2/5] opti: don't create the hashmap in rust --- app/src/main/rust/src/lib.rs | 98 ++++++++++++++++------------ app/src/main/rust/src/libgit2/mod.rs | 29 ++++---- 2 files changed, 74 insertions(+), 53 deletions(-) diff --git a/app/src/main/rust/src/lib.rs b/app/src/main/rust/src/lib.rs index f4d79cce..0f3f6bba 100644 --- a/app/src/main/rust/src/lib.rs +++ b/app/src/main/rust/src/lib.rs @@ -26,7 +26,14 @@ const OK: jint = 0; #[derive(Debug)] enum Error { - Git2 { error: git2::Error, msg: String }, + Git2 { + error: git2::Error, + msg: String, + }, + Jni { + error: jni::errors::Error, + msg: String, + }, } impl From for Error { @@ -35,6 +42,12 @@ impl From for Error { } } +impl From for Error { + fn from(value: jni::errors::Error) -> Self { + Self::jni(value, "") + } +} + impl Error { fn git2(error: git2::Error, msg: &str) -> Self { Self::Git2 { @@ -43,12 +56,23 @@ impl Error { } } + fn jni(error: jni::errors::Error, msg: &str) -> Self { + Self::Jni { + error, + msg: msg.into(), + } + } + fn add_message(self, msg1: &str) -> Self { match self { Error::Git2 { error, msg } => Error::Git2 { error, msg: format!("{}: {}", msg1, msg), }, + Error::Jni { error, msg } => Error::Jni { + error, + msg: format!("{}: {}", msg1, msg), + }, } } } @@ -57,6 +81,7 @@ impl From for jint { fn from(value: Error) -> Self { match value { Error::Git2 { error, .. } => error.raw_code(), + Error::Jni { .. } => -1, } } } @@ -64,9 +89,8 @@ impl From for jint { impl Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Error::Git2 { error, msg } => { - write!(f, "{msg}: {error}") - } + Error::Git2 { error, msg } => write!(f, "{msg}: {error}"), + Error::Jni { error, msg } => write!(f, "{msg}: {error}"), } } } @@ -513,22 +537,7 @@ fn get_timestamps_lib<'local>( _class: JClass<'local>, j_map: JObject<'local>, ) -> Result { - let timestamps = unwrap_or_log!(libgit2::get_timestamps(), "get_timestamps"); - - if let Err(e) = get_timestamps_jni(env, &j_map, timestamps.iter()) { - error!("get_timestamps_jni: {e}"); - return Ok(-1); - } - - Ok(OK) -} - -fn get_timestamps_jni<'local, 'a>( - env: &mut Env<'local>, - j_map: &JObject<'local>, - timestamps: impl Iterator, -) -> Result<(), Box> { - let map_class = env.get_object_class(j_map)?; + let map_class = env.get_object_class(&j_map)?; let put_method = env.get_method_id( map_class, jni_str!("put"), @@ -538,29 +547,34 @@ fn get_timestamps_jni<'local, 'a>( let long_class = env.find_class(jni_str!("java/lang/Long"))?; let long_ctor = env.get_method_id(&long_class, jni_str!(""), jni_sig!((jlong)))?; - for (path, timestamp) in timestamps { - let j_key: JString = env.new_string(path)?; - - unsafe { - let j_value = env.new_object_unchecked( - &long_class, - long_ctor, - &[JValue::Long(*timestamp).as_jni()], - )?; - - env.call_method_unchecked( - j_map, - put_method, - jni::signature::ReturnType::Object, - &[ - JValue::Object(&JObject::from(j_key)).as_jni(), - JValue::Object(&j_value).as_jni(), - ], - )?; - } - } + unwrap_or_log!( + libgit2::get_timestamps(|path, timestamp| { + let j_key: JString = env.new_string(path)?; + + unsafe { + let j_value = env.new_object_unchecked( + &long_class, + long_ctor, + &[JValue::Long(timestamp).as_jni()], + )?; + + env.call_method_unchecked( + &j_map, + put_method, + jni::signature::ReturnType::Object, + &[ + JValue::Object(&JObject::from(j_key)).as_jni(), + JValue::Object(&j_value).as_jni(), + ], + )?; + } - Ok(()) + Ok(()) + }), + "get_timestamps" + ); + + Ok(OK) } fn generate_ssh_keys_lib<'local>( diff --git a/app/src/main/rust/src/libgit2/mod.rs b/app/src/main/rust/src/libgit2/mod.rs index e56c97e3..f83e7a24 100644 --- a/app/src/main/rust/src/libgit2/mod.rs +++ b/app/src/main/rust/src/libgit2/mod.rs @@ -1,5 +1,4 @@ use std::{ - collections::HashMap, fs, path::Path, str::FromStr, @@ -376,7 +375,7 @@ pub fn is_change() -> Result { Ok(count > 0) } -fn find_timestamp(repo: &Repository, file_path: String) -> anyhow::Result> { +fn find_timestamp(repo: &Repository, file_path: &str) -> anyhow::Result> { // Use revwalk to find the last commit that touched this path let mut revwalk = repo.revwalk()?; revwalk.push_head()?; @@ -389,7 +388,7 @@ fn find_timestamp(repo: &Repository, file_path: String) -> anyhow::Result