diff --git a/Cargo.lock b/Cargo.lock index bced526ccb..b44241cc85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1119,9 +1119,9 @@ dependencies = [ [[package]] name = "git2" -version = "0.20.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fda788993cc341f69012feba8bf45c0ba4f3291fcc08e214b4d5a7332d88aff" +checksum = "5220b8ba44c68a9a7f7a7659e864dd73692e417ef0211bea133c7b74e031eeb9" dependencies = [ "bitflags 2.9.0", "libc", @@ -2184,9 +2184,9 @@ checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "libgit2-sys" -version = "0.18.0+1.9.0" +version = "0.18.1+1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1a117465e7e1597e8febea8bb0c410f1c7fb93b1e1cddf34363f8390367ffec" +checksum = "e1dcb20f84ffcdd825c7a311ae347cce604a6f084a767dec4a4929829645290e" dependencies = [ "cc", "libc", diff --git a/asyncgit/src/sync/patches.rs b/asyncgit/src/sync/patches.rs index dae51160bc..e87a3c9777 100644 --- a/asyncgit/src/sync/patches.rs +++ b/asyncgit/src/sync/patches.rs @@ -9,12 +9,12 @@ pub(crate) struct HunkLines<'a> { } #[allow(clippy::redundant_pub_crate)] -pub(crate) fn get_file_diff_patch_and_hunklines<'a>( +pub(crate) fn get_file_diff_patch<'a>( repo: &'a Repository, file: &str, is_staged: bool, reverse: bool, -) -> Result<(Patch<'a>, Vec>)> { +) -> Result> { let diff = get_diff_raw( repo, file, @@ -34,14 +34,12 @@ pub(crate) fn get_file_diff_patch_and_hunklines<'a>( Error::Generic(String::from("no patch found")) })?; - let lines = patch_get_hunklines(&patch)?; - - Ok((patch, lines)) + Ok(patch) } // -fn patch_get_hunklines<'a>( - patch: &Patch<'a>, +pub fn patch_get_hunklines<'a>( + patch: &'a Patch<'a>, ) -> Result>> { let count_hunks = patch.num_hunks(); let mut res = Vec::with_capacity(count_hunks); diff --git a/asyncgit/src/sync/staging/discard_tracked.rs b/asyncgit/src/sync/staging/discard_tracked.rs index 022aab99b5..83b0646b5c 100644 --- a/asyncgit/src/sync/staging/discard_tracked.rs +++ b/asyncgit/src/sync/staging/discard_tracked.rs @@ -2,8 +2,8 @@ use super::{apply_selection, load_file}; use crate::{ error::Result, sync::{ - diff::DiffLinePosition, - patches::get_file_diff_patch_and_hunklines, repository::repo, + diff::DiffLinePosition, patches::get_file_diff_patch, + patches::patch_get_hunklines, repository::repo, utils::repo_write_file, RepoPath, }, }; @@ -27,9 +27,9 @@ pub fn discard_lines( //TODO: check that file is not new (status modified) let new_content = { - let (_patch, hunks) = get_file_diff_patch_and_hunklines( - &repo, file_path, false, false, - )?; + let patch = + get_file_diff_patch(&repo, file_path, false, false)?; + let hunks = patch_get_hunklines(&patch)?; let working_content = load_file(&repo, file_path)?; let old_lines = working_content.lines().collect::>(); diff --git a/asyncgit/src/sync/staging/stage_tracked.rs b/asyncgit/src/sync/staging/stage_tracked.rs index 2bfe315cdd..891f61bef1 100644 --- a/asyncgit/src/sync/staging/stage_tracked.rs +++ b/asyncgit/src/sync/staging/stage_tracked.rs @@ -2,9 +2,8 @@ use super::apply_selection; use crate::{ error::{Error, Result}, sync::{ - diff::DiffLinePosition, - patches::get_file_diff_patch_and_hunklines, repository::repo, - RepoPath, + diff::DiffLinePosition, patches::get_file_diff_patch, + patches::patch_get_hunklines, repository::repo, RepoPath, }, }; use easy_cast::Conv; @@ -39,9 +38,9 @@ pub fn stage_lines( let indexed_content = String::from_utf8(blob.content().into())?; let new_content = { - let (_patch, hunks) = get_file_diff_patch_and_hunklines( - &repo, file_path, is_stage, false, - )?; + let patch = + get_file_diff_patch(&repo, file_path, is_stage, false)?; + let hunks = patch_get_hunklines(&patch)?; let old_lines = indexed_content.lines().collect::>();