History

[commitgraph] Clean up `{file,graph}::verify::Error` types.

Get rid of `file::verify::EitherError` in favor of having `graph::verify::Error` manually copy file errors into the graph error object.

Conor Davis committed 6 years ago

Commit fa22cab1 parent 25711133 files · +64 −44Browse files

Showing the changes to git-commitgraph/src/graph (1 of 3 files). Show all

Unified · Split

git-commitgraph/src/graph/verify.rs+35−7
@@ -1,6 +1,6 @@
11 use crate::{
22 file::{self, commit},
3− graph, Graph, GENERATION_NUMBER_MAX,
3+ graph, Graph, ImpossibleVariantError, GENERATION_NUMBER_MAX,
44 };
55 use git_object::owned;
66 use std::cmp::{max, min};
@@ -22,7 +22,15 @@ pub enum Error<E: std::error::Error + 'static> { · 15 unmodified lines
2222 #[error(transparent)]
2323 Commit(#[from] commit::Error),
2424 #[error("{}: {err}", .path.display())]
25− File { err: file::verify::Error, path: PathBuf },
25+ File {
26+ // Use zero-size error type. We will never return
27+ // `graph::verify::Error::File(file::verify::Error::Processor(...))`, because we are the
28+ // file's processor, and we convert`file::verify::Error::Processor<graph::verify::Error>`
29+ // variants into direct `graph::verify::Error` values.
30+ // TODO: Use never type when it becomes available.
31+ err: file::verify::Error<ImpossibleVariantError>,
32+ path: PathBuf,
33+ },
2634 #[error("Commit {id}'s generation should be {expected} but is {actual}")]
2735 Generation { actual: u32, expected: u32, id: owned::Id },
2836 #[error(
@@ -132,12 +140,32 @@ impl Graph { · 103 unmodified lines
132140
133141 Ok(())
134142 })
135− .map_err(|e| match e {
136− file::verify::EitherError::Internal(err) => Error::File {
137− err,
138− path: file.path().to_owned(),
143+ .map_err(|err| Error::File {
144+ err: match err {
145+ file::verify::Error::Processor(e) => return e,
146+ file::verify::Error::RootTreeId { id, root_tree_id } => {
147+ file::verify::Error::RootTreeId { id, root_tree_id }
148+ }
149+ file::verify::Error::Mismatch { actual, expected } => {
150+ file::verify::Error::Mismatch { actual, expected }
151+ }
152+ file::verify::Error::Generation { generation, id } => {
153+ file::verify::Error::Generation { generation, id }
154+ }
155+ file::verify::Error::Filename(expected) => file::verify::Error::Filename(expected),
156+ file::verify::Error::Commit(err) => file::verify::Error::Commit(err),
157+ file::verify::Error::CommitId { id, pos } => file::verify::Error::CommitId { id, pos },
158+ file::verify::Error::CommitsOutOfOrder {
159+ id,
160+ pos,
161+ predecessor_id,
162+ } => file::verify::Error::CommitsOutOfOrder {
163+ id,
164+ pos,
165+ predecessor_id,
166+ },
139167 },
140− file::verify::EitherError::Processor(e) => e,
168+ path: file.path().to_owned(),
141169 })?;
142170
143171 max_generation = max(max_generation, file_stats.max_generation);