From c5e7fe865c1aff859ad011f1edb7176fb34f2649 Mon Sep 17 00:00:00 2001 From: Scott Chacon Date: Mon, 29 Apr 2024 15:42:58 +0200 Subject: [PATCH] fix clippy issues fix a few more clippy issues --- .../src/virtual_branches/virtual.rs | 52 ++++++++----------- .../gitbutler-tauri/src/virtual_branches.rs | 12 ++--- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/crates/gitbutler-core/src/virtual_branches/virtual.rs b/crates/gitbutler-core/src/virtual_branches/virtual.rs index 17e2dfd58..419414d1a 100644 --- a/crates/gitbutler-core/src/virtual_branches/virtual.rs +++ b/crates/gitbutler-core/src/virtual_branches/virtual.rs @@ -2723,7 +2723,7 @@ pub fn move_commit_file( }) })?; - let mut to_amend_oid = to_commit_oid.clone(); + let mut to_amend_oid = to_commit_oid; let mut amend_commit = project_repository .git_repository .find_commit(to_amend_oid) @@ -2835,23 +2835,19 @@ pub fn move_commit_file( // write our new tree and commit for the new "from" commit without the moved changes let new_from_tree_oid = write_tree_onto_commit(project_repository, from_parent.id(), &diffs_to_keep)?; - let new_from_tree = &repo.find_tree(new_from_tree_oid).or_else(|_error| { - return Err(errors::VirtualBranchError::GitObjectNotFound( - new_from_tree_oid, - )); - })?; + let new_from_tree = &repo + .find_tree(new_from_tree_oid) + .map_err(|_error| errors::VirtualBranchError::GitObjectNotFound(new_from_tree_oid))?; let new_from_commit_oid = repo .commit( None, &from_commit.author(), &from_commit.committer(), &from_commit.message().to_str_lossy(), - &new_from_tree, + new_from_tree, &[&from_parent], ) - .or_else(|_error| { - return Err(errors::VirtualBranchError::CommitFailed); - })?; + .map_err(|_error| errors::VirtualBranchError::CommitFailed)?; // rebase everything above the new "from" commit that has the moved changes removed let new_head = match cherry_rebase( @@ -2956,9 +2952,9 @@ pub fn move_commit_file( target_branch.head = new_head; vb_state.set_branch(target_branch.clone())?; super::integration::update_gitbutler_integration(&vb_state, project_repository)?; - return Ok(commit_oid); + Ok(commit_oid) } else { - return Err(errors::VirtualBranchError::RebaseFailed); + Err(errors::VirtualBranchError::RebaseFailed) } } @@ -3143,9 +3139,9 @@ pub fn amend( target_branch.head = new_head; vb_state.set_branch(target_branch.clone())?; super::integration::update_gitbutler_integration(&vb_state, project_repository)?; - return Ok(commit_oid); + Ok(commit_oid) } else { - return Err(errors::VirtualBranchError::RebaseFailed); + Err(errors::VirtualBranchError::RebaseFailed) } } @@ -3253,7 +3249,7 @@ pub fn reorder_commit( } } - return Ok(()); + Ok(()) } // create and insert a blank commit (no tree change) either above or below a commit @@ -3323,7 +3319,7 @@ pub fn insert_blank_commit( } } - return Ok(()); + Ok(()) } // remove a commit in a branch by rebasing all commits _except_ for it onto it's parent @@ -3385,7 +3381,7 @@ pub fn undo_commit( .context("failed to update gitbutler integration")?; } - return Ok(()); + Ok(()) } // cherry-pick based rebase, which handles empty commits @@ -3410,7 +3406,7 @@ pub fn cherry_rebase( let new_head_id = cherry_rebase_group(project_repository, target_commit_oid, &mut ids_to_rebase)?; - return Ok(new_head_id); + Ok(new_head_id) } // takes a vector of commit oids and rebases them onto a target commit and returns the @@ -3420,7 +3416,7 @@ pub fn cherry_rebase( fn cherry_rebase_group( project_repository: &project_repository::Repository, target_commit_oid: git::Oid, - ids_to_rebase: &mut Vec, + ids_to_rebase: &mut [git::Oid], ) -> Result, anyhow::Error> { ids_to_rebase.reverse(); // now, rebase unchanged commits onto the new commit @@ -3478,7 +3474,7 @@ fn cherry_rebase_group( )? .id(); - return Ok(Some(new_head_id)); + Ok(Some(new_head_id)) } // runs a simple libgit2 based in-memory rebase on a commit range onto a target commit @@ -3527,11 +3523,11 @@ pub fn simple_rebase( if rebase_success { // rebase worked out, rewrite the branch head rebase.finish(None).context("failed to finish rebase")?; - return Ok(Some(last_rebase_head)); + Ok(Some(last_rebase_head)) } else { // rebase failed, do a merge commit rebase.abort().context("failed to abort rebase")?; - return Ok(None); + Ok(None) } } @@ -3838,9 +3834,7 @@ pub fn squash( .context("failed to update gitbutler integration")?; Ok(()) } - _ => { - return Err(errors::SquashError::Other(anyhow!("rebase error"))); - } + _ => Err(errors::SquashError::Other(anyhow!("rebase error"))), } } @@ -3956,11 +3950,9 @@ pub fn update_commit_message( .context("failed to update gitbutler integration")?; Ok(()) } - _ => { - return Err(errors::UpdateCommitMessageError::Other(anyhow!( - "rebase error" - ))); - } + _ => Err(errors::UpdateCommitMessageError::Other(anyhow!( + "rebase error" + ))), } } diff --git a/crates/gitbutler-tauri/src/virtual_branches.rs b/crates/gitbutler-tauri/src/virtual_branches.rs index b1a9d9d43..c04ed397f 100644 --- a/crates/gitbutler-tauri/src/virtual_branches.rs +++ b/crates/gitbutler-tauri/src/virtual_branches.rs @@ -393,12 +393,12 @@ pub mod commands { branch_id: BranchId, commit_oid: git::Oid, ) -> Result<(), Error> { - let oid = handle + handle .state::() .undo_commit(&project_id, &branch_id, commit_oid) .await?; emit_vbranches(&handle, &project_id).await; - Ok(oid) + Ok(()) } #[tauri::command(async)] @@ -410,12 +410,12 @@ pub mod commands { commit_oid: git::Oid, offset: i32, ) -> Result<(), Error> { - let oid = handle + handle .state::() .insert_blank_commit(&project_id, &branch_id, commit_oid, offset) .await?; emit_vbranches(&handle, &project_id).await; - Ok(oid) + Ok(()) } #[tauri::command(async)] @@ -427,12 +427,12 @@ pub mod commands { commit_oid: git::Oid, offset: i32, ) -> Result<(), Error> { - let oid = handle + handle .state::() .reorder_commit(&project_id, &branch_id, commit_oid, offset) .await?; emit_vbranches(&handle, &project_id).await; - Ok(oid) + Ok(()) } #[tauri::command(async)]