@@ -319,26 +319,6 @@ impl ConsumeHunk for FileDiff {
319
319
}
320
320
}
321
321
322
- fn resolve_revspec (
323
- gix_repo : & gix:: Repository ,
324
- revspec : & str ,
325
- ) -> ( ObjectId , Option < std:: path:: PathBuf > ) {
326
- gix_repo. rev_parse ( revspec) . map_or_else (
327
- |_| {
328
- (
329
- ObjectId :: null ( gix:: hash:: Kind :: Sha1 ) ,
330
- gix_repo. workdir ( ) . map ( ToOwned :: to_owned) ,
331
- )
332
- } ,
333
- |resolved_revspec| {
334
- resolved_revspec. single ( ) . map_or_else (
335
- || ( ObjectId :: null ( gix:: hash:: Kind :: Sha1 ) , None ) ,
336
- |id| ( id. into ( ) , None ) ,
337
- )
338
- } ,
339
- )
340
- }
341
-
342
322
/// returns diff of a specific file either in `stage` or workdir
343
323
pub fn get_diff (
344
324
repo_path : & RepoPath ,
@@ -356,18 +336,42 @@ pub fn get_diff(
356
336
) ;
357
337
358
338
// TODO:
359
- // Make sure that the revspec logic is correct, i. e. uses the correct syntax for all the
360
- // relevant cases.
361
- let ( old_revspec, new_revspec) = if stage {
362
- ( format ! ( "HEAD:{p}" ) , format ! ( ":{p}" ) )
339
+ // The lower tree is `stage == true`, the upper tree is `stage == false`.
340
+ let ( old_blob_id, old_root) = if stage {
341
+ (
342
+ gix_repo
343
+ . head_tree ( ) ?
344
+ . lookup_entry_by_path ( p)
345
+ . expect ( "TODO" )
346
+ . expect ( "TODO" )
347
+ . object_id ( ) ,
348
+ None ,
349
+ )
363
350
} else {
364
- ( format ! ( ":{p}" ) , p. to_string ( ) )
351
+ (
352
+ gix_repo
353
+ . index ( ) ?
354
+ . entry_by_path ( p. into ( ) )
355
+ . expect ( "TODO" )
356
+ . id ,
357
+ None ,
358
+ )
359
+ } ;
360
+ let ( new_blob_id, new_root) = if stage {
361
+ (
362
+ gix_repo
363
+ . index ( ) ?
364
+ . entry_by_path ( p. into ( ) )
365
+ . expect ( "TODO" )
366
+ . id ,
367
+ None ,
368
+ )
369
+ } else {
370
+ (
371
+ ObjectId :: null ( gix:: hash:: Kind :: Sha1 ) ,
372
+ gix_repo. workdir ( ) . map ( ToOwned :: to_owned) ,
373
+ )
365
374
} ;
366
-
367
- let ( old_blob_id, old_root) =
368
- resolve_revspec ( & gix_repo, & old_revspec) ;
369
- let ( new_blob_id, new_root) =
370
- resolve_revspec ( & gix_repo, & new_revspec) ;
371
375
372
376
let worktree_roots = gix:: diff:: blob:: pipeline:: WorktreeRoots {
373
377
old_root,
0 commit comments