@@ -94,11 +94,12 @@ pub struct BlameFilePopup {
94
94
table_state : std:: cell:: Cell < TableState > ,
95
95
key_config : SharedKeyConfig ,
96
96
current_height : std:: cell:: Cell < usize > ,
97
- blame : BlameProcess ,
97
+ blame : Option < BlameProcess > ,
98
98
app_sender : Sender < AsyncAppNotification > ,
99
99
git_sender : Sender < AsyncGitNotification > ,
100
100
repo : RepoPathRef ,
101
101
}
102
+
102
103
impl DrawableComponent for BlameFilePopup {
103
104
fn draw < B : Backend > (
104
105
& self ,
@@ -126,16 +127,16 @@ impl DrawableComponent for BlameFilePopup {
126
127
Constraint :: Percentage ( 100 ) ,
127
128
] ;
128
129
129
- let number_of_rows = rows. len ( ) ;
130
+ let number_of_rows: usize = rows. len ( ) ;
130
131
let syntax_highlight_progress = match self . blame {
131
- BlameProcess :: SyntaxHighlighting {
132
- ref job, ..
133
- } => job
132
+ Some ( BlameProcess :: SyntaxHighlighting {
133
+ ref job,
134
+ ..
135
+ } ) => job
134
136
. progress ( )
135
137
. map ( |p| format ! ( " ({}%)" , p. progress) )
136
138
. unwrap_or_default ( ) ,
137
- BlameProcess :: GettingBlame ( _)
138
- | BlameProcess :: Result ( _) => String :: new ( ) ,
139
+ _ => String :: new ( ) ,
139
140
} ;
140
141
let title_with_highlight_progress =
141
142
format ! ( "{title}{syntax_highlight_progress}" ) ;
@@ -198,7 +199,11 @@ impl Component for BlameFilePopup {
198
199
out : & mut Vec < CommandInfo > ,
199
200
force_all : bool ,
200
201
) -> CommandBlocking {
201
- let file_blame = self . blame . result ( ) ;
202
+ let has_result = self
203
+ . blame
204
+ . as_ref ( )
205
+ . map ( |blame| blame. result ( ) . is_some ( ) )
206
+ . unwrap_or_default ( ) ;
202
207
if self . is_visible ( ) || force_all {
203
208
out. push (
204
209
CommandInfo :: new (
@@ -212,7 +217,7 @@ impl Component for BlameFilePopup {
212
217
CommandInfo :: new (
213
218
strings:: commands:: scroll ( & self . key_config ) ,
214
219
true ,
215
- file_blame . is_some ( ) ,
220
+ has_result ,
216
221
)
217
222
. order ( 1 ) ,
218
223
) ;
@@ -222,7 +227,7 @@ impl Component for BlameFilePopup {
222
227
& self . key_config ,
223
228
) ,
224
229
true ,
225
- file_blame . is_some ( ) ,
230
+ has_result ,
226
231
)
227
232
. order ( 1 ) ,
228
233
) ;
@@ -232,7 +237,7 @@ impl Component for BlameFilePopup {
232
237
& self . key_config ,
233
238
) ,
234
239
true ,
235
- file_blame . is_some ( ) ,
240
+ has_result ,
236
241
)
237
242
. order ( 1 ) ,
238
243
) ;
@@ -344,10 +349,7 @@ impl BlameFilePopup {
344
349
current_height : std:: cell:: Cell :: new ( 0 ) ,
345
350
app_sender : env. sender_app . clone ( ) ,
346
351
git_sender : env. sender_git . clone ( ) ,
347
- blame : BlameProcess :: GettingBlame ( AsyncBlame :: new (
348
- env. repo . borrow ( ) . clone ( ) ,
349
- & env. sender_git ,
350
- ) ) ,
352
+ blame : None ,
351
353
repo : env. repo . clone ( ) ,
352
354
}
353
355
}
@@ -376,10 +378,11 @@ impl BlameFilePopup {
376
378
file_path : open. file_path ,
377
379
commit_id : open. commit_id ,
378
380
} ) ;
379
- self . blame = BlameProcess :: GettingBlame ( AsyncBlame :: new (
380
- self . repo . borrow ( ) . clone ( ) ,
381
- & self . git_sender ,
382
- ) ) ;
381
+ self . blame =
382
+ Some ( BlameProcess :: GettingBlame ( AsyncBlame :: new (
383
+ self . repo . borrow ( ) . clone ( ) ,
384
+ & self . git_sender ,
385
+ ) ) ) ;
383
386
self . table_state . get_mut ( ) . select ( Some ( 0 ) ) ;
384
387
self . visible = true ;
385
388
self . update ( ) ?;
@@ -389,7 +392,8 @@ impl BlameFilePopup {
389
392
390
393
///
391
394
pub fn any_work_pending ( & self ) -> bool {
392
- !matches ! ( self . blame, BlameProcess :: Result ( _) )
395
+ self . blame . is_some ( )
396
+ && !matches ! ( self . blame, Some ( BlameProcess :: Result ( _) ) )
393
397
}
394
398
395
399
pub fn update_async (
@@ -417,35 +421,38 @@ impl BlameFilePopup {
417
421
418
422
fn update ( & mut self ) -> Result < ( ) > {
419
423
if self . is_visible ( ) {
420
- match self . blame {
421
- BlameProcess :: Result ( _)
422
- | BlameProcess :: SyntaxHighlighting { .. } => { }
423
- BlameProcess :: GettingBlame ( ref mut async_blame) => {
424
- if let Some ( params) = & self . params {
425
- if let Some ( (
426
- previous_blame_params,
427
- last_file_blame,
428
- ) ) = async_blame. last ( ) ?
429
- {
430
- if previous_blame_params == * params {
431
- self . blame = BlameProcess :: SyntaxHighlighting {
432
- unstyled_file_blame : SyntaxFileBlame {
433
- file_blame : last_file_blame,
434
- styled_text : None ,
435
- } ,
436
- job : AsyncSingleJob :: new (
437
- self . app_sender . clone ( ) ,
438
- )
439
- } ;
440
- self . set_open_selection ( ) ;
441
- self . highlight_blame_lines ( ) ;
442
-
443
- return Ok ( ( ) ) ;
444
- }
424
+ if let Some ( BlameProcess :: GettingBlame (
425
+ ref mut async_blame,
426
+ ) ) = self . blame
427
+ {
428
+ if let Some ( params) = & self . params {
429
+ if let Some ( (
430
+ previous_blame_params,
431
+ last_file_blame,
432
+ ) ) = async_blame. last ( ) ?
433
+ {
434
+ if previous_blame_params == * params {
435
+ self . blame = Some (
436
+ BlameProcess :: SyntaxHighlighting {
437
+ unstyled_file_blame :
438
+ SyntaxFileBlame {
439
+ file_blame :
440
+ last_file_blame,
441
+ styled_text : None ,
442
+ } ,
443
+ job : AsyncSingleJob :: new (
444
+ self . app_sender . clone ( ) ,
445
+ ) ,
446
+ } ,
447
+ ) ;
448
+ self . set_open_selection ( ) ;
449
+ self . highlight_blame_lines ( ) ;
450
+
451
+ return Ok ( ( ) ) ;
445
452
}
446
-
447
- async_blame. request ( params. clone ( ) ) ?;
448
453
}
454
+
455
+ async_blame. request ( params. clone ( ) ) ?;
449
456
}
450
457
}
451
458
}
@@ -454,10 +461,10 @@ impl BlameFilePopup {
454
461
}
455
462
456
463
fn update_syntax ( & mut self , ev : AsyncNotification ) {
457
- let BlameProcess :: SyntaxHighlighting {
464
+ let Some ( BlameProcess :: SyntaxHighlighting {
458
465
ref unstyled_file_blame,
459
466
ref job,
460
- } = self . blame
467
+ } ) = self . blame
461
468
else {
462
469
return ;
463
470
} ;
@@ -474,15 +481,16 @@ impl BlameFilePopup {
474
481
== Path :: new (
475
482
unstyled_file_blame. path ( ) ,
476
483
) {
477
- self . blame = BlameProcess :: Result (
478
- SyntaxFileBlame {
479
- file_blame :
480
- unstyled_file_blame
481
- . file_blame
482
- . clone ( ) ,
483
- styled_text : Some ( syntax) ,
484
- } ,
485
- ) ;
484
+ self . blame =
485
+ Some ( BlameProcess :: Result (
486
+ SyntaxFileBlame {
487
+ file_blame :
488
+ unstyled_file_blame
489
+ . file_blame
490
+ . clone ( ) ,
491
+ styled_text : Some ( syntax) ,
492
+ } ,
493
+ ) ) ;
486
494
}
487
495
}
488
496
}
@@ -497,7 +505,7 @@ impl BlameFilePopup {
497
505
match (
498
506
self . any_work_pending ( ) ,
499
507
self . params . as_ref ( ) ,
500
- self . blame . result ( ) ,
508
+ self . blame . as_ref ( ) . and_then ( |blame| blame . result ( ) ) ,
501
509
) {
502
510
( true , Some ( params) , _) => {
503
511
format ! (
@@ -525,9 +533,9 @@ impl BlameFilePopup {
525
533
526
534
///
527
535
fn get_rows ( & self , width : usize ) -> Vec < Row > {
528
- let file_blame = self . blame . result ( ) ;
529
-
530
- file_blame
536
+ self . blame
537
+ . as_ref ( )
538
+ . and_then ( |blame| blame . result ( ) )
531
539
. map ( |file_blame| {
532
540
let styled_text: Option < Text < ' _ > > = file_blame
533
541
. styled_text
@@ -552,10 +560,10 @@ impl BlameFilePopup {
552
560
}
553
561
554
562
fn highlight_blame_lines ( & mut self ) {
555
- let BlameProcess :: SyntaxHighlighting {
563
+ let Some ( BlameProcess :: SyntaxHighlighting {
556
564
ref unstyled_file_blame,
557
565
ref mut job,
558
- } = self . blame
566
+ } ) = self . blame
559
567
else {
560
568
return ;
561
569
} ;
@@ -651,7 +659,8 @@ impl BlameFilePopup {
651
659
time_to_string ( hunk. time , true )
652
660
} ) ;
653
661
654
- let file_blame = self . blame . result ( ) ;
662
+ let file_blame =
663
+ self . blame . as_ref ( ) . and_then ( |blame| blame. result ( ) ) ;
655
664
let is_blamed_commit = file_blame
656
665
. and_then ( |file_blame| {
657
666
blame_hunk. map ( |hunk| {
@@ -671,7 +680,8 @@ impl BlameFilePopup {
671
680
672
681
fn get_max_line_number ( & self ) -> usize {
673
682
self . blame
674
- . result ( )
683
+ . as_ref ( )
684
+ . and_then ( |blame| blame. result ( ) )
675
685
. map_or ( 0 , |file_blame| file_blame. lines ( ) . len ( ) - 1 )
676
686
}
677
687
@@ -723,33 +733,39 @@ impl BlameFilePopup {
723
733
}
724
734
725
735
fn get_selection ( & self ) -> Option < usize > {
726
- self . blame . result ( ) . as_ref ( ) . and_then ( |_| {
727
- let table_state = self . table_state . take ( ) ;
736
+ self . blame
737
+ . as_ref ( )
738
+ . and_then ( |blame| blame. result ( ) )
739
+ . and_then ( |_| {
740
+ let table_state = self . table_state . take ( ) ;
728
741
729
- let selection = table_state. selected ( ) ;
742
+ let selection = table_state. selected ( ) ;
730
743
731
- self . table_state . set ( table_state) ;
744
+ self . table_state . set ( table_state) ;
732
745
733
- selection
734
- } )
746
+ selection
747
+ } )
735
748
}
736
749
737
750
fn selected_commit ( & self ) -> Option < CommitId > {
738
- self . blame . result ( ) . as_ref ( ) . and_then ( |file_blame| {
739
- let table_state = self . table_state . take ( ) ;
751
+ self . blame
752
+ . as_ref ( )
753
+ . and_then ( |blame| blame. result ( ) )
754
+ . and_then ( |file_blame| {
755
+ let table_state = self . table_state . take ( ) ;
740
756
741
- let commit_id =
742
- table_state. selected ( ) . and_then ( |selected| {
743
- file_blame. lines ( ) [ selected]
744
- . 0
745
- . as_ref ( )
746
- . map ( |hunk| hunk. commit_id )
747
- } ) ;
757
+ let commit_id =
758
+ table_state. selected ( ) . and_then ( |selected| {
759
+ file_blame. lines ( ) [ selected]
760
+ . 0
761
+ . as_ref ( )
762
+ . map ( |hunk| hunk. commit_id )
763
+ } ) ;
748
764
749
- self . table_state . set ( table_state) ;
765
+ self . table_state . set ( table_state) ;
750
766
751
- commit_id
752
- } )
767
+ commit_id
768
+ } )
753
769
}
754
770
}
755
771
0 commit comments