Skip to content

Commit c1c12ab

Browse files
committed
Replace expect by ?
Add missing `+ 1` to make test pass.
1 parent 75b8a7a commit c1c12ab

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

asyncgit/src/error.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@ pub enum Error {
123123
#[from] gix::object::find::existing::with_conversion::Error,
124124
),
125125

126+
///
127+
#[error("gix::traverse::commit::topo error: {0}")]
128+
GixTraverseCommitTopo(#[from] gix::traverse::commit::topo::Error),
129+
130+
///
131+
#[error("gix::repository::commit_graph_if_enabled error: {0}")]
132+
GixRepositoryCommitGraphIfEnabled(
133+
#[from] gix::repository::commit_graph_if_enabled::Error,
134+
),
135+
136+
///
137+
#[error("gix::repository::diff_resource_cache error: {0}")]
138+
GixRepositoryDiffResourceCache(
139+
#[from] Box<gix::repository::diff_resource_cache::Error>,
140+
),
141+
142+
///
143+
#[error("gix_blame error: {0}")]
144+
GixBlame(#[from] gix_blame::Error),
145+
126146
///
127147
#[error("amend error: config commit.gpgsign=true detected.\ngpg signing is not supported for amending non-last commits")]
128148
SignAmendNonLastCommit,
@@ -156,3 +176,11 @@ impl From<gix::discover::Error> for Error {
156176
Self::GixDiscover(Box::new(error))
157177
}
158178
}
179+
180+
impl From<gix::repository::diff_resource_cache::Error> for Error {
181+
fn from(
182+
error: gix::repository::diff_resource_cache::Error,
183+
) -> Self {
184+
Self::GixRepositoryDiffResourceCache(Box::new(error))
185+
}
186+
}

asyncgit/src/sync/blame.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ pub fn blame_file(
5353
};
5454

5555
let cache: Option<gix::commitgraph::Graph> =
56-
repo.commit_graph_if_enabled().expect("TODO");
56+
repo.commit_graph_if_enabled()?;
5757
let mut resource_cache =
58-
repo.diff_resource_cache_for_tree_diff().expect("TODO");
58+
repo.diff_resource_cache_for_tree_diff()?;
5959

6060
let options: gix_blame::Options = Default::default();
6161

@@ -66,8 +66,7 @@ pub fn blame_file(
6666
&mut resource_cache,
6767
file_path.into(),
6868
options,
69-
)
70-
.expect("TODO");
69+
)?;
7170

7271
let commit_id = if let Some(commit_id) = commit_id {
7372
commit_id
@@ -77,15 +76,10 @@ pub fn blame_file(
7776
utils::get_head_repo(&repo)?
7877
};
7978

80-
let unique_commit_ids: HashSet<_> = outcome
79+
let unique_commit_ids: HashSet<CommitId> = outcome
8180
.entries
8281
.iter()
83-
.map(|entry| {
84-
CommitId::new(
85-
git2::Oid::from_bytes(entry.commit_id.as_bytes())
86-
.expect("TODO"),
87-
)
88-
})
82+
.map(|entry| entry.commit_id.into())
8983
.collect();
9084
let mut commit_ids = Vec::with_capacity(unique_commit_ids.len());
9185
commit_ids.extend(unique_commit_ids);
@@ -102,10 +96,7 @@ pub fn blame_file(
10296
let lines: Vec<(Option<BlameHunk>, String)> = outcome
10397
.entries_with_lines()
10498
.flat_map(|(entry, lines)| {
105-
let commit_id = CommitId::new(
106-
git2::Oid::from_bytes(entry.commit_id.as_bytes())
107-
.expect("TODO"),
108-
);
99+
let commit_id = entry.commit_id.into();
109100
let start_in_blamed_file =
110101
entry.start_in_blamed_file as usize;
111102

@@ -126,7 +117,8 @@ pub fn blame_file(
126117
author: commit_info.author.clone(),
127118
time: commit_info.time,
128119
start_line: start_in_blamed_file + i,
129-
end_line: start_in_blamed_file + i,
120+
end_line: start_in_blamed_file
121+
+ i + 1,
130122
}),
131123
trimmed_line,
132124
);

0 commit comments

Comments
 (0)