Skip to content

Commit 675a457

Browse files
committed
Replace expect by ?
Add missing `+ 1` to make test pass.
1 parent a106987 commit 675a457

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

asyncgit/src/error.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ pub enum Error {
115115
#[error("gix::revision::walk error: {0}")]
116116
GixRevisionWalk(#[from] gix::revision::walk::Error),
117117

118+
///
119+
#[error("gix::traverse::commit::topo error: {0}")]
120+
GixTraverseCommitTopo(#[from] gix::traverse::commit::topo::Error),
121+
122+
///
123+
#[error("gix::repository::diff_resource_cache error: {0}")]
124+
GixRepositoryDiffResourceCache(
125+
#[from] Box<gix::repository::diff_resource_cache::Error>,
126+
),
127+
128+
///
129+
#[error("gix_blame error: {0}")]
130+
GixBlame(#[from] gix_blame::Error),
131+
118132
///
119133
#[error("amend error: config commit.gpgsign=true detected.\ngpg signing is not supported for amending non-last commits")]
120134
SignAmendNonLastCommit,
@@ -148,3 +162,11 @@ impl From<gix::discover::Error> for Error {
148162
Self::GixDiscover(Box::new(error))
149163
}
150164
}
165+
166+
impl From<gix::repository::diff_resource_cache::Error> for Error {
167+
fn from(
168+
error: gix::repository::diff_resource_cache::Error,
169+
) -> Self {
170+
Self::GixRepositoryDiffResourceCache(Box::new(error))
171+
}
172+
}

asyncgit/src/sync/blame.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ pub struct FileBlame {
3434
pub lines: Vec<(Option<BlameHunk>, String)>,
3535
}
3636

37+
fn object_id_to_oid(object_id: gix::ObjectId) -> git2::Oid {
38+
// TODO
39+
// This should not fail. It will also become obsolete once `gix::ObjectId` is used throughout
40+
// `gitui`.
41+
#[allow(clippy::expect_used)]
42+
git2::Oid::from_bytes(object_id.as_bytes())
43+
.expect("ObjectId could not be converted to Oid")
44+
}
45+
3746
///
3847
pub fn blame_file(
3948
repo_path: &RepoPath,
@@ -56,20 +65,18 @@ pub fn blame_file(
5665
[tip],
5766
None::<Vec<gix::ObjectId>>,
5867
)
59-
.build()
60-
.expect("TODO");
68+
.build()?;
6169

6270
let mut resource_cache =
63-
repo.diff_resource_cache_for_tree_diff().expect("TODO");
71+
repo.diff_resource_cache_for_tree_diff()?;
6472

6573
let outcome = gix_blame::file(
6674
&repo.objects,
6775
traverse,
6876
&mut resource_cache,
6977
file_path.into(),
7078
None,
71-
)
72-
.expect("TODO");
79+
)?;
7380

7481
let commit_id = if let Some(commit_id) = commit_id {
7582
commit_id
@@ -82,12 +89,7 @@ pub fn blame_file(
8289
let unique_commit_ids: HashSet<_> = outcome
8390
.entries
8491
.iter()
85-
.map(|entry| {
86-
CommitId::new(
87-
git2::Oid::from_bytes(entry.commit_id.as_bytes())
88-
.expect("TODO"),
89-
)
90-
})
92+
.map(|entry| CommitId::new(object_id_to_oid(entry.commit_id)))
9193
.collect();
9294
let mut commit_ids = Vec::with_capacity(unique_commit_ids.len());
9395
commit_ids.extend(unique_commit_ids);
@@ -104,10 +106,8 @@ pub fn blame_file(
104106
let lines: Vec<(Option<BlameHunk>, String)> = outcome
105107
.entries_with_lines()
106108
.flat_map(|(entry, lines)| {
107-
let commit_id = CommitId::new(
108-
git2::Oid::from_bytes(entry.commit_id.as_bytes())
109-
.expect("TODO"),
110-
);
109+
let commit_id =
110+
CommitId::new(object_id_to_oid(entry.commit_id));
111111
let start_in_blamed_file =
112112
entry.start_in_blamed_file as usize;
113113

@@ -128,7 +128,8 @@ pub fn blame_file(
128128
author: commit_info.author.clone(),
129129
time: commit_info.time,
130130
start_line: start_in_blamed_file + i,
131-
end_line: start_in_blamed_file + i,
131+
end_line: start_in_blamed_file
132+
+ i + 1,
132133
}),
133134
trimmed_line,
134135
);

0 commit comments

Comments
 (0)