11//! Low-level operations on individual commits.
2- use std:: {
3- fmt:: { Debug , Formatter } ,
4- slice:: Chunks ,
5- } ;
6-
72use 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
138124impl 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