Skip to content

Commit 007bda7

Browse files
committed
Replace expect by ?
Add missing `+ 1` to make test pass.
1 parent 3775083 commit 007bda7

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
@@ -113,6 +113,20 @@ pub enum Error {
113113
#[error("gix::revision::walk error: {0}")]
114114
GixRevisionWalk(#[from] gix::revision::walk::Error),
115115

116+
///
117+
#[error("gix::traverse::commit::topo error: {0}")]
118+
GixTraverseCommitTopo(#[from] gix::traverse::commit::topo::Error),
119+
120+
///
121+
#[error("gix::repository::diff_resource_cache error: {0}")]
122+
GixRepositoryDiffResourceCache(
123+
#[from] Box<gix::repository::diff_resource_cache::Error>,
124+
),
125+
126+
///
127+
#[error("gix_blame error: {0}")]
128+
GixBlame(#[from] gix_blame::Error),
129+
116130
///
117131
#[error("amend error: config commit.gpgsign=true detected.\ngpg signing is not supported for amending non-last commits")]
118132
SignAmendNonLastCommit,
@@ -146,3 +160,11 @@ impl From<gix::discover::Error> for Error {
146160
Self::GixDiscover(Box::new(error))
147161
}
148162
}
163+
164+
impl From<gix::repository::diff_resource_cache::Error> for Error {
165+
fn from(
166+
error: gix::repository::diff_resource_cache::Error,
167+
) -> Self {
168+
Self::GixRepositoryDiffResourceCache(Box::new(error))
169+
}
170+
}

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)