@@ -263,6 +263,26 @@ impl ConsumeHunk for FileDiff {
263
263
}
264
264
}
265
265
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
+
266
286
/// returns diff of a specific file either in `stage` or workdir
267
287
pub fn get_diff (
268
288
repo_path : & RepoPath ,
@@ -285,24 +305,8 @@ pub fn get_diff(
285
305
) ;
286
306
287
307
let old_revspec = format ! ( "HEAD:{p}" ) ;
288
-
289
- // TODO:
290
- // This is identical to the corresponding block that gets `(new_blob_id, new_root)`.
291
308
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) ;
306
310
307
311
// TODO:
308
312
// 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(
314
318
} ;
315
319
316
320
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) ;
331
322
332
323
let worktree_roots = gix:: diff:: blob:: pipeline:: WorktreeRoots {
333
324
old_root,
0 commit comments