@@ -9,12 +9,13 @@ use gix::{
99 Delegate ,
1010 } ,
1111 } ,
12+ Exn ,
1213} ;
1314
1415pub fn explain ( spec : std:: ffi:: OsString , mut out : impl std:: io:: Write ) -> anyhow:: Result < ( ) > {
1516 let mut explain = Explain :: new ( & mut out) ;
1617 let spec = gix:: path:: os_str_into_bstr ( & spec) ?;
17- gix:: revision:: plumbing:: spec:: parse ( spec, & mut explain) ?;
18+ gix:: revision:: plumbing:: spec:: parse ( spec, & mut explain) . map_err ( gix :: Error :: from ) ?;
1819 if let Some ( err) = explain. err {
1920 bail ! ( err) ;
2021 }
@@ -41,9 +42,10 @@ impl<'a> Explain<'a> {
4142 err : None ,
4243 }
4344 }
44- fn prefix ( & mut self ) -> Option < ( ) > {
45+ fn prefix ( & mut self ) -> Result < ( ) , Exn > {
4546 self . call += 1 ;
46- write ! ( self . out, "{:02}. " , self . call) . ok ( )
47+ write ! ( self . out, "{:02}. " , self . call) . ok ( ) ;
48+ Ok ( ( ) )
4749 }
4850 fn revision_name ( & self ) -> BString {
4951 self . ref_name . clone ( ) . unwrap_or_else ( || {
@@ -56,13 +58,18 @@ impl<'a> Explain<'a> {
5658}
5759
5860impl delegate:: Revision for Explain < ' _ > {
59- fn find_ref ( & mut self , name : & BStr ) -> Option < ( ) > {
61+ fn find_ref ( & mut self , name : & BStr ) -> Result < ( ) , Exn > {
6062 self . prefix ( ) ?;
6163 self . ref_name = Some ( name. into ( ) ) ;
62- writeln ! ( self . out, "Lookup the '{name}' reference" ) . ok ( )
64+ writeln ! ( self . out, "Lookup the '{name}' reference" ) . ok ( ) ;
65+ Ok ( ( ) )
6366 }
6467
65- fn disambiguate_prefix ( & mut self , prefix : gix:: hash:: Prefix , hint : Option < delegate:: PrefixHint < ' _ > > ) -> Option < ( ) > {
68+ fn disambiguate_prefix (
69+ & mut self ,
70+ prefix : gix:: hash:: Prefix ,
71+ hint : Option < delegate:: PrefixHint < ' _ > > ,
72+ ) -> Result < ( ) , Exn > {
6673 self . prefix ( ) ?;
6774 self . oid_prefix = Some ( prefix) ;
6875 writeln ! (
@@ -76,10 +83,11 @@ impl delegate::Revision for Explain<'_> {
7683 format!( "commit {generation} generations in future of reference {ref_name:?}" ) ,
7784 }
7885 )
79- . ok ( )
86+ . ok ( ) ;
87+ Ok ( ( ) )
8088 }
8189
82- fn reflog ( & mut self , query : ReflogLookup ) -> Option < ( ) > {
90+ fn reflog ( & mut self , query : ReflogLookup ) -> Result < ( ) , Exn > {
8391 self . prefix ( ) ?;
8492 self . has_implicit_anchor = true ;
8593 let ref_name: & BStr = self . ref_name . as_ref ( ) . map_or_else ( || "HEAD" . into ( ) , AsRef :: as_ref) ;
@@ -92,16 +100,18 @@ impl delegate::Revision for Explain<'_> {
92100 ref_name
93101 )
94102 . ok ( ) ,
95- }
103+ } ;
104+ Ok ( ( ) )
96105 }
97106
98- fn nth_checked_out_branch ( & mut self , branch_no : usize ) -> Option < ( ) > {
107+ fn nth_checked_out_branch ( & mut self , branch_no : usize ) -> Result < ( ) , Exn > {
99108 self . prefix ( ) ?;
100109 self . has_implicit_anchor = true ;
101- writeln ! ( self . out, "Find the {branch_no}th checked-out branch of 'HEAD'" ) . ok ( )
110+ writeln ! ( self . out, "Find the {branch_no}th checked-out branch of 'HEAD'" ) . ok ( ) ;
111+ Ok ( ( ) )
102112 }
103113
104- fn sibling_branch ( & mut self , kind : SiblingBranch ) -> Option < ( ) > {
114+ fn sibling_branch ( & mut self , kind : SiblingBranch ) -> Result < ( ) , Exn > {
105115 self . prefix ( ) ?;
106116 self . has_implicit_anchor = true ;
107117 let ref_info = match self . ref_name . as_ref ( ) {
@@ -117,12 +127,13 @@ impl delegate::Revision for Explain<'_> {
117127 } ,
118128 ref_info
119129 )
120- . ok ( )
130+ . ok ( ) ;
131+ Ok ( ( ) )
121132 }
122133}
123134
124135impl delegate:: Navigate for Explain < ' _ > {
125- fn traverse ( & mut self , kind : Traversal ) -> Option < ( ) > {
136+ fn traverse ( & mut self , kind : Traversal ) -> Result < ( ) , Exn > {
126137 self . prefix ( ) ?;
127138 let name = self . revision_name ( ) ;
128139 writeln ! (
@@ -133,10 +144,11 @@ impl delegate::Navigate for Explain<'_> {
133144 Traversal :: NthParent ( no) => format!( "Select the {no}. parent of revision named '{name}'" ) ,
134145 }
135146 )
136- . ok ( )
147+ . ok ( ) ;
148+ Ok ( ( ) )
137149 }
138150
139- fn peel_until ( & mut self , kind : PeelTo < ' _ > ) -> Option < ( ) > {
151+ fn peel_until ( & mut self , kind : PeelTo < ' _ > ) -> Result < ( ) , Exn > {
140152 self . prefix ( ) ?;
141153 writeln ! (
142154 self . out,
@@ -148,10 +160,11 @@ impl delegate::Navigate for Explain<'_> {
148160 PeelTo :: Path ( path) => format!( "Lookup the object at '{path}' from the current tree-ish" ) ,
149161 }
150162 )
151- . ok ( )
163+ . ok ( ) ;
164+ Ok ( ( ) )
152165 }
153166
154- fn find ( & mut self , regex : & BStr , negated : bool ) -> Option < ( ) > {
167+ fn find ( & mut self , regex : & BStr , negated : bool ) -> Result < ( ) , Exn > {
155168 self . prefix ( ) ?;
156169 self . has_implicit_anchor = true ;
157170 let negate_text = if negated { "does not match" } else { "matches" } ;
@@ -172,10 +185,11 @@ impl delegate::Navigate for Explain<'_> {
172185 ) ,
173186 }
174187 )
175- . ok ( )
188+ . ok ( ) ;
189+ Ok ( ( ) )
176190 }
177191
178- fn index_lookup ( & mut self , path : & BStr , stage : u8 ) -> Option < ( ) > {
192+ fn index_lookup ( & mut self , path : & BStr , stage : u8 ) -> Result < ( ) , Exn > {
179193 self . prefix ( ) ?;
180194 self . has_implicit_anchor = true ;
181195 writeln ! (
@@ -190,12 +204,13 @@ impl delegate::Navigate for Explain<'_> {
190204 _ => unreachable!( "BUG: parser assures of that" ) ,
191205 }
192206 )
193- . ok ( )
207+ . ok ( ) ;
208+ Ok ( ( ) )
194209 }
195210}
196211
197212impl delegate:: Kind for Explain < ' _ > {
198- fn kind ( & mut self , kind : spec:: Kind ) -> Option < ( ) > {
213+ fn kind ( & mut self , kind : spec:: Kind ) -> Result < ( ) , Exn > {
199214 self . prefix ( ) ?;
200215 self . call = 0 ;
201216 writeln ! (
@@ -211,14 +226,16 @@ impl delegate::Kind for Explain<'_> {
211226 unreachable!( "BUG: 'single' mode is implied but cannot be set explicitly" ) ,
212227 }
213228 )
214- . ok ( )
229+ . ok ( ) ;
230+ Ok ( ( ) )
215231 }
216232}
217233
218234impl Delegate for Explain < ' _ > {
219- fn done ( & mut self ) {
235+ fn done ( & mut self ) -> Result < ( ) , Exn > {
220236 if !self . has_implicit_anchor && self . ref_name . is_none ( ) && self . oid_prefix . is_none ( ) {
221237 self . err = Some ( "Incomplete specification lacks its anchor, like a reference or object name" . into ( ) ) ;
222238 }
239+ Ok ( ( ) )
223240 }
224241}
0 commit comments