Skip to content

Commit 6cff657

Browse files
authored
Merge pull request #2378 from GitoxideLabs/gix-error
`gix-commitgraph` to `gix-error`
2 parents 12924d7 + e112cac commit 6cff657

31 files changed

Lines changed: 320 additions & 448 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitoxide-core/src/commitgraph/verify.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ impl Default for Context<Vec<u8>, Vec<u8>> {
2222
pub(crate) mod function {
2323
use std::{io, path::Path};
2424

25-
use anyhow::{Context as AnyhowContext, Result};
26-
use gix::commitgraph::{verify::Outcome, Graph};
27-
2825
use crate::OutputFormat;
26+
use anyhow::Result;
27+
use gix::commitgraph::{verify::Outcome, Graph};
28+
use gix::Exn;
2929

3030
pub fn verify<W1, W2>(
3131
path: impl AsRef<Path>,
@@ -34,20 +34,18 @@ pub(crate) mod function {
3434
mut out,
3535
output_statistics,
3636
}: super::Context<W1, W2>,
37-
) -> Result<gix::commitgraph::verify::Outcome>
37+
) -> Result<Outcome>
3838
where
3939
W1: io::Write,
4040
W2: io::Write,
4141
{
42-
let g = Graph::at(path.as_ref()).with_context(|| "Could not open commit graph")?;
42+
let g = Graph::at(path.as_ref()).map_err(Exn::into_error)?;
4343

4444
#[allow(clippy::unnecessary_wraps, unknown_lints)]
4545
fn noop_processor(_commit: &gix::commitgraph::file::Commit<'_>) -> std::result::Result<(), std::fmt::Error> {
4646
Ok(())
4747
}
48-
let stats = g
49-
.verify_integrity(noop_processor)
50-
.with_context(|| "Verification failure")?;
48+
let stats = g.verify_integrity(noop_processor).map_err(Exn::into_error)?;
5149

5250
#[cfg_attr(not(feature = "serde"), allow(clippy::single_match))]
5351
match output_statistics {

gitoxide-core/src/repository/commitgraph/verify.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ pub struct Context<W1: std::io::Write, W2: std::io::Write> {
1212
pub(crate) mod function {
1313
use std::io;
1414

15-
use anyhow::{Context as AnyhowContext, Result};
16-
1715
use crate::{repository::commitgraph::verify::Context, OutputFormat};
16+
use anyhow::Result;
17+
use gix::Exn;
1818

1919
pub fn verify<W1, W2>(
2020
repo: gix::Repository,
@@ -34,9 +34,7 @@ pub(crate) mod function {
3434
fn noop_processor(_commit: &gix::commitgraph::file::Commit<'_>) -> std::result::Result<(), std::fmt::Error> {
3535
Ok(())
3636
}
37-
let stats = g
38-
.verify_integrity(noop_processor)
39-
.with_context(|| "Verification failure")?;
37+
let stats = g.verify_integrity(noop_processor).map_err(Exn::into_error)?;
4038

4139
#[cfg_attr(not(feature = "serde"), allow(clippy::single_match))]
4240
match output_statistics {

gix-blame/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rust-version = "1.82"
1616
blob-experimental = ["gix-diff/blob-experimental"]
1717

1818
[dependencies]
19+
gix-error = { version = "0.0.0", path = "../gix-error" }
1920
gix-commitgraph = { version = "^0.31.0", path = "../gix-commitgraph" }
2021
gix-revwalk = { version = "^0.25.0", path = "../gix-revwalk" }
2122
gix-trace = { version = "^0.1.17", path = "../gix-trace" }

gix-blame/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ pub enum Error {
3434
#[error("Failure to decode commit during traversal")]
3535
DecodeCommit(#[from] gix_object::decode::Error),
3636
#[error("Failed to get parent from commitgraph during traversal")]
37-
GetParentFromCommitGraph(#[from] gix_commitgraph::file::commit::Error),
37+
GetParentFromCommitGraph(#[from] gix_error::Message),
3838
}

gix-chunk/src/file/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl Index {
6363
pub fn data_by_id<'a>(&self, data: &'a [u8], kind: Id) -> Result<&'a [u8], Message> {
6464
let offset = self.offset_by_id(kind)?;
6565
Ok(&data[crate::range::into_usize(offset)
66-
.ok_or_else(|| message!("The offsets into the file couldn't be represented by usize"))?])
66+
.ok_or_else(|| message("The offsets into the file couldn't be represented by usize"))?])
6767
}
6868

6969
/// Return the end offset of the last chunk, which is the highest offset as well.

gix-commitgraph/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ gix-error = { version = "^0.0.0", path = "../gix-error" }
2727
bstr = { version = "1.12.0", default-features = false, features = ["std"] }
2828
memmap2 = "0.9.7"
2929
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
30-
thiserror = "2.0.17"
3130

3231
document-features = { version = "0.2.0", optional = true }
3332

gix-commitgraph/fuzz/fuzz_targets/fuzz_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn fuzz(data: &[u8]) -> Result<()> {
1111
d.copy_from_slice(data);
1212
d.make_read_only()?
1313
};
14-
let file = File::new(data, "does not matter".into())?;
14+
let file = File::new(data, "does not matter".into()).map_err(|e| e.into_inner())?;
1515

1616
_ = black_box(file.iter_base_graph_ids().count());
1717
_ = black_box(file.iter_commits().count());

gix-commitgraph/src/file/commit.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
//! Low-level operations on individual commits.
2-
use std::{
3-
fmt::{Debug, Formatter},
4-
slice::Chunks,
5-
};
6-
72
use crate::{
83
file::{self, EXTENDED_EDGES_MASK, LAST_EXTENDED_EDGE_MASK, NO_PARENT},
94
File, Position,
105
};
11-
12-
/// The error used in the [`file::commit`][self] module.
13-
#[derive(thiserror::Error, Debug)]
14-
#[allow(missing_docs)]
15-
pub enum Error {
16-
#[error("commit {0}'s extra edges overflows the commit-graph file's extra edges list")]
17-
ExtraEdgesListOverflow(gix_hash::ObjectId),
18-
#[error("commit {0}'s first parent is an extra edge index, which is invalid")]
19-
FirstParentIsExtraEdgeIndex(gix_hash::ObjectId),
20-
#[error("commit {0} has extra edges, but commit-graph file has no extra edges list")]
21-
MissingExtraEdgesList(gix_hash::ObjectId),
22-
#[error("commit {0} has a second parent but not a first parent")]
23-
SecondParentWithoutFirstParent(gix_hash::ObjectId),
24-
}
6+
use gix_error::{message, Message};
7+
use std::{
8+
fmt::{Debug, Formatter},
9+
slice::Chunks,
10+
};
2511

2612
/// A commit as stored in a [`File`].
2713
#[derive(Copy, Clone)]
@@ -91,7 +77,7 @@ impl<'a> Commit<'a> {
9177
}
9278

9379
/// Returns the first parent of this commit.
94-
pub fn parent1(&self) -> Result<Option<Position>, Error> {
80+
pub fn parent1(&self) -> Result<Option<Position>, Message> {
9581
self.iter_parents().next().transpose()
9682
}
9783

@@ -136,23 +122,27 @@ pub struct Parents<'a> {
136122
}
137123

138124
impl Iterator for Parents<'_> {
139-
type Item = Result<Position, Error>;
125+
type Item = Result<Position, Message>;
140126

141127
fn next(&mut self) -> Option<Self::Item> {
142128
let state = std::mem::replace(&mut self.state, ParentIteratorState::Exhausted);
143129
match state {
144130
ParentIteratorState::First => match self.commit_data.parent1 {
145131
ParentEdge::None => match self.commit_data.parent2 {
146132
ParentEdge::None => None,
147-
_ => Some(Err(Error::SecondParentWithoutFirstParent(self.commit_data.id().into()))),
133+
_ => Some(Err(message!(
134+
"commit {} has a second parent but not a first parent",
135+
self.commit_data.id()
136+
))),
148137
},
149138
ParentEdge::GraphPosition(pos) => {
150139
self.state = ParentIteratorState::Second;
151140
Some(Ok(pos))
152141
}
153-
ParentEdge::ExtraEdgeIndex(_) => {
154-
Some(Err(Error::FirstParentIsExtraEdgeIndex(self.commit_data.id().into())))
155-
}
142+
ParentEdge::ExtraEdgeIndex(_) => Some(Err(message!(
143+
"commit {}'s first parent is an extra edge index, which is invalid",
144+
self.commit_data.id(),
145+
))),
156146
},
157147
ParentIteratorState::Second => match self.commit_data.parent2 {
158148
ParentEdge::None => None,
@@ -171,10 +161,16 @@ impl Iterator for Parents<'_> {
171161
// with a std::iter::from_fn closure.
172162
self.next()
173163
} else {
174-
Some(Err(Error::ExtraEdgesListOverflow(self.commit_data.id().into())))
164+
Some(Err(message!(
165+
"commit {0}'s extra edges overflows the commit-graph file's extra edges list",
166+
self.commit_data.id()
167+
)))
175168
}
176169
} else {
177-
Some(Err(Error::MissingExtraEdgesList(self.commit_data.id().into())))
170+
Some(Err(message!(
171+
"commit {} has extra edges, but commit-graph file has no extra edges list",
172+
self.commit_data.id()
173+
)))
178174
}
179175
}
180176
},
@@ -189,7 +185,10 @@ impl Iterator for Parents<'_> {
189185
ExtraEdge::Last(pos) => Some(Ok(pos)),
190186
}
191187
} else {
192-
Some(Err(Error::ExtraEdgesListOverflow(self.commit_data.id().into())))
188+
Some(Err(message!(
189+
"commit {}'s extra edges overflows the commit-graph file's extra edges list",
190+
self.commit_data.id()
191+
)))
193192
}
194193
}
195194
ParentIteratorState::Exhausted => None,

0 commit comments

Comments
 (0)