diff --git a/gitbutler-app/src/error.rs b/gitbutler-app/src/error.rs index 504c951fe..04bba6611 100644 --- a/gitbutler-app/src/error.rs +++ b/gitbutler-app/src/error.rs @@ -67,8 +67,8 @@ pub mod gb { } #[inline] - pub fn context(&self) -> Option<&Context> { - Some(&self.context) + pub fn context(&self) -> &Context { + &self.context } pub(crate) fn into_owned(self) -> (ErrorKind, Context) { @@ -175,10 +175,7 @@ pub mod gb { let r = app_level_io(); assert!(r.is_err()); let e = r.unwrap_err(); - assert_eq!( - e.context().unwrap().vars.get("foo"), - Some(&"bar".to_string()) - ); + assert_eq!(e.context().vars.get("foo"), Some(&"bar".to_string())); assert!(e.source().is_none()); assert!(e.to_string().starts_with("io.other-error:")); } diff --git a/gitbutler-app/src/git/remote.rs b/gitbutler-app/src/git/remote.rs index 8907fe9ad..15f28034c 100644 --- a/gitbutler-app/src/git/remote.rs +++ b/gitbutler-app/src/git/remote.rs @@ -25,10 +25,6 @@ impl<'repo> Remote<'repo> { .map_err(Into::into) } - pub fn url_as_str(&self) -> Result> { - Ok(self.inner.url()) - } - pub fn push( &mut self, refspec: &[&str], diff --git a/gitbutler-app/src/virtual_branches/base.rs b/gitbutler-app/src/virtual_branches/base.rs index 7d069b1ea..606c958a8 100644 --- a/gitbutler-app/src/virtual_branches/base.rs +++ b/gitbutler-app/src/virtual_branches/base.rs @@ -555,7 +555,7 @@ pub fn target_to_base_branch( .context("failed to get upstream commits")? .iter() .map(super::commit_to_remote_commit) - .collect::>>()?; + .collect::>(); // get some recent commits let recent_commits = project_repository @@ -563,7 +563,7 @@ pub fn target_to_base_branch( .context("failed to get recent commits")? .iter() .map(super::commit_to_remote_commit) - .collect::>>()?; + .collect::>(); let base = super::BaseBranch { branch_name: format!("{}/{}", target.branch.remote(), target.branch.branch()), diff --git a/gitbutler-app/src/virtual_branches/branch/hunk.rs b/gitbutler-app/src/virtual_branches/branch/hunk.rs index c3266f668..3d2f50394 100644 --- a/gitbutler-app/src/virtual_branches/branch/hunk.rs +++ b/gitbutler-app/src/virtual_branches/branch/hunk.rs @@ -142,15 +142,15 @@ impl Hunk { self.timestamp_ms } - pub fn contains(&self, line: &u32) -> bool { - self.start <= *line && self.end >= *line + pub fn contains(&self, line: u32) -> bool { + self.start <= line && self.end >= line } pub fn intersects(&self, another: &Hunk) -> bool { - self.contains(&another.start) - || self.contains(&another.end) - || another.contains(&self.start) - || another.contains(&self.end) + self.contains(another.start) + || self.contains(another.end) + || another.contains(self.start) + || another.contains(self.end) } } diff --git a/gitbutler-app/src/virtual_branches/context.rs b/gitbutler-app/src/virtual_branches/context.rs index 9a4b3f71d..d69050f9d 100644 --- a/gitbutler-app/src/virtual_branches/context.rs +++ b/gitbutler-app/src/virtual_branches/context.rs @@ -9,14 +9,14 @@ pub fn hunk_with_context( context_lines: usize, file_lines_before: &[&str], change_type: diff::ChangeType, -) -> Result { +) -> diff::Hunk { let diff_lines = hunk_diff .lines() .map(std::string::ToString::to_string) .collect::>(); if diff_lines.is_empty() { #[allow(clippy::cast_possible_truncation)] - return Ok(diff::Hunk { + return diff::Hunk { diff: hunk_diff.to_owned(), old_start: hunk_old_start_line as u32, old_lines: 0, @@ -24,7 +24,7 @@ pub fn hunk_with_context( new_lines: 0, binary: is_binary, change_type, - }); + }; } let new_file = hunk_old_start_line == 0; @@ -120,7 +120,8 @@ pub fn hunk_with_context( binary: is_binary, change_type, }; - Ok(hunk) + + hunk } #[cfg(test)] @@ -140,8 +141,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); let expected = r#"@@ -5,7 +5,7 @@ [features] @@ -173,8 +173,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); assert_eq!( with_ctx.diff.replace("\n \n", "\n\n"), r#"@@ -1,5 +1,5 @@ @@ -206,8 +205,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); assert_eq!( with_ctx.diff.replace("\n \n", "\n\n"), r#"@@ -1,4 +1,4 @@ @@ -238,8 +236,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); assert_eq!( with_ctx.diff.replace("\n \n", "\n\n"), r#"@@ -10,5 +10,5 @@ @@ -274,8 +271,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); assert_eq!( with_ctx.diff.replace("\n \n", "\n\n"), r#"@@ -5,7 +5,10 @@ @@ -314,8 +310,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); assert_eq!( with_ctx.diff.replace("\n \n", "\n\n"), r#"@@ -4,9 +4,7 @@ @@ -348,8 +343,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); assert_eq!(with_ctx.diff, ""); } @@ -379,8 +373,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), hunk_diff); assert_eq!(with_ctx.old_start, 1); assert_eq!(with_ctx.old_lines, 14); @@ -404,8 +397,7 @@ mod tests { 3, &Vec::new(), diff::ChangeType::Added, - ) - .unwrap(); + ); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), hunk_diff); assert_eq!(with_ctx.old_start, 0); assert_eq!(with_ctx.old_lines, 0); @@ -428,8 +420,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); let expected = r#"@@ -6,6 +6,9 @@ [features] default = ["serde", "rusqlite"] @@ -463,8 +454,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); let expected = r#"@@ -6,6 +10,9 @@ [features] default = ["serde", "rusqlite"] @@ -509,8 +499,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected); assert_eq!(with_ctx.old_start, 4); assert_eq!(with_ctx.old_lines, 9); @@ -544,8 +533,7 @@ mod tests { 3, &file_lines(), diff::ChangeType::Added, - ) - .unwrap(); + ); assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected); assert_eq!(with_ctx.old_start, 4); assert_eq!(with_ctx.old_lines, 9); @@ -567,8 +555,7 @@ mod tests { 3, &file_lines_2(), diff::ChangeType::Added, - ) - .unwrap(); + ); let expected = "@@ -8,8 +8,6 @@ .order(:created_at) .page params[:page] @@ -599,8 +586,7 @@ mod tests { 3, &file_lines_3(), diff::ChangeType::Added, - ) - .unwrap(); + ); let expected = r#"@@ -1,4 +1,5 @@ alias( name = "rdeps", diff --git a/gitbutler-app/src/virtual_branches/files.rs b/gitbutler-app/src/virtual_branches/files.rs index d2df431b8..a193733e2 100644 --- a/gitbutler-app/src/virtual_branches/files.rs +++ b/gitbutler-app/src/virtual_branches/files.rs @@ -74,7 +74,7 @@ fn files_with_hunk_context( .map(|hunk| { if hunk.diff.is_empty() { // noop on empty diff - Ok(hunk.clone()) + hunk.clone() } else { context::hunk_with_context( &hunk.diff, @@ -87,8 +87,7 @@ fn files_with_hunk_context( ) } }) - .collect::>>() - .context("failed to add context to hunk")?; + .collect::>(); } Ok(files) } diff --git a/gitbutler-app/src/virtual_branches/remote.rs b/gitbutler-app/src/virtual_branches/remote.rs index bb2476e63..d460aad52 100644 --- a/gitbutler-app/src/virtual_branches/remote.rs +++ b/gitbutler-app/src/virtual_branches/remote.rs @@ -159,17 +159,17 @@ pub fn branch_to_remote_branch_data( commits: ahead .into_iter() .map(|commit| commit_to_remote_commit(&commit)) - .collect::>>()?, + .collect::>(), }) }) .transpose() } -pub fn commit_to_remote_commit(commit: &git::Commit) -> Result { - Ok(RemoteCommit { +pub fn commit_to_remote_commit(commit: &git::Commit) -> RemoteCommit { + RemoteCommit { id: commit.id().to_string(), description: commit.message().unwrap_or_default().to_string(), created_at: commit.time().seconds().try_into().unwrap(), author: commit.author().into(), - }) + } } diff --git a/gitbutler-app/src/virtual_branches/virtual.rs b/gitbutler-app/src/virtual_branches/virtual.rs index d088814c2..e3acc4a80 100644 --- a/gitbutler-app/src/virtual_branches/virtual.rs +++ b/gitbutler-app/src/virtual_branches/virtual.rs @@ -1007,7 +1007,7 @@ fn files_with_hunk_context( .map(|hunk| { if hunk.diff.is_empty() { // noop on empty diff - Ok(hunk.clone()) + hunk.clone() } else { let hunk_with_ctx = context::hunk_with_context( &hunk.diff, @@ -1021,22 +1021,19 @@ fn files_with_hunk_context( to_virtual_branch_hunk(hunk.clone(), hunk_with_ctx) } }) - .collect::>>() - .context("failed to add context to hunk")?; + .collect::>(); } Ok(files) } fn to_virtual_branch_hunk( mut hunk: VirtualBranchHunk, - diff_with_context: Result, -) -> Result { - diff_with_context.map(|diff| { - hunk.diff = diff.diff; - hunk.start = diff.new_start; - hunk.end = diff.new_start + diff.new_lines; - hunk - }) + diff_with_context: diff::Hunk, +) -> VirtualBranchHunk { + hunk.diff = diff_with_context.diff; + hunk.start = diff_with_context.new_start; + hunk.end = diff_with_context.new_start + diff_with_context.new_lines; + hunk } fn is_requires_force( diff --git a/gitbutler-app/src/writer.rs b/gitbutler-app/src/writer.rs index 0a148d743..e4bdf1a10 100644 --- a/gitbutler-app/src/writer.rs +++ b/gitbutler-app/src/writer.rs @@ -67,18 +67,6 @@ impl DirWriter { })? } - pub fn write_usize(&self, path: &str, contents: &usize) -> Result<(), std::io::Error> { - self.write_string(path, &contents.to_string()) - } - - pub fn write_u128(&self, path: &str, contents: &u128) -> Result<(), std::io::Error> { - self.write_string(path, &contents.to_string()) - } - - pub fn write_bool(&self, path: &str, contents: &bool) -> Result<(), std::io::Error> { - self.write_string(path, &contents.to_string()) - } - pub fn write_string(&self, path: &str, contents: &str) -> Result<(), std::io::Error> { self.write(path, contents) }