@@ -263,6 +263,26 @@ impl ConsumeHunk for FileDiff {
263263 }
264264}
265265
266+ fn resolve_revspec (
267+ gix_repo : & gix:: Repository ,
268+ revspec : & str ,
269+ ) -> ( ObjectId , Option < std:: path:: PathBuf > ) {
270+ gix_repo. rev_parse ( revspec) . map_or_else (
271+ |_| {
272+ (
273+ ObjectId :: null ( gix:: hash:: Kind :: Sha1 ) ,
274+ gix_repo. workdir ( ) . map ( ToOwned :: to_owned) ,
275+ )
276+ } ,
277+ |resolved_revspec| {
278+ resolved_revspec. single ( ) . map_or_else (
279+ || ( ObjectId :: null ( gix:: hash:: Kind :: Sha1 ) , None ) ,
280+ |id| ( id. into ( ) , None ) ,
281+ )
282+ } ,
283+ )
284+ }
285+
266286/// returns diff of a specific file either in `stage` or workdir
267287pub fn get_diff (
268288 repo_path : & RepoPath ,
@@ -285,24 +305,8 @@ pub fn get_diff(
285305 ) ;
286306
287307 let old_revspec = format ! ( "HEAD:{p}" ) ;
288-
289- // TODO:
290- // This is identical to the corresponding block that gets `(new_blob_id, new_root)`.
291308 let ( old_blob_id, old_root) =
292- gix_repo. rev_parse ( & * old_revspec) . map_or_else (
293- |_| {
294- (
295- ObjectId :: null ( gix:: hash:: Kind :: Sha1 ) ,
296- gix_repo. workdir ( ) . map ( ToOwned :: to_owned) ,
297- )
298- } ,
299- |resolved_revspec| {
300- resolved_revspec. single ( ) . map_or_else (
301- || ( ObjectId :: null ( gix:: hash:: Kind :: Sha1 ) , None ) ,
302- |id| ( id. into ( ) , None ) ,
303- )
304- } ,
305- ) ;
309+ resolve_revspec ( & gix_repo, & old_revspec) ;
306310
307311 // TODO:
308312 // Make sure that the revspec logic is correct, i. e. uses the correct syntax for all the
@@ -314,20 +318,7 @@ pub fn get_diff(
314318 } ;
315319
316320 let ( new_blob_id, new_root) =
317- gix_repo. rev_parse ( & * new_revspec) . map_or_else (
318- |_| {
319- (
320- ObjectId :: null ( gix:: hash:: Kind :: Sha1 ) ,
321- gix_repo. workdir ( ) . map ( ToOwned :: to_owned) ,
322- )
323- } ,
324- |resolved_revspec| {
325- resolved_revspec. single ( ) . map_or_else (
326- || ( ObjectId :: null ( gix:: hash:: Kind :: Sha1 ) , None ) ,
327- |id| ( id. into ( ) , None ) ,
328- )
329- } ,
330- ) ;
321+ resolve_revspec ( & gix_repo, & new_revspec) ;
331322
332323 let worktree_roots = gix:: diff:: blob:: pipeline:: WorktreeRoots {
333324 old_root,
0 commit comments