@@ -94,11 +94,12 @@ pub struct BlameFilePopup {
9494 table_state : std:: cell:: Cell < TableState > ,
9595 key_config : SharedKeyConfig ,
9696 current_height : std:: cell:: Cell < usize > ,
97- blame : BlameProcess ,
97+ blame : Option < BlameProcess > ,
9898 app_sender : Sender < AsyncAppNotification > ,
9999 git_sender : Sender < AsyncGitNotification > ,
100100 repo : RepoPathRef ,
101101}
102+
102103impl DrawableComponent for BlameFilePopup {
103104 fn draw < B : Backend > (
104105 & self ,
@@ -126,16 +127,16 @@ impl DrawableComponent for BlameFilePopup {
126127 Constraint :: Percentage ( 100 ) ,
127128 ] ;
128129
129- let number_of_rows = rows. len ( ) ;
130+ let number_of_rows: usize = rows. len ( ) ;
130131 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
134136 . progress ( )
135137 . map ( |p| format ! ( " ({}%)" , p. progress) )
136138 . unwrap_or_default ( ) ,
137- BlameProcess :: GettingBlame ( _)
138- | BlameProcess :: Result ( _) => String :: new ( ) ,
139+ _ => String :: new ( ) ,
139140 } ;
140141 let title_with_highlight_progress =
141142 format ! ( "{title}{syntax_highlight_progress}" ) ;
@@ -198,7 +199,11 @@ impl Component for BlameFilePopup {
198199 out : & mut Vec < CommandInfo > ,
199200 force_all : bool ,
200201 ) -> 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 ( ) ;
202207 if self . is_visible ( ) || force_all {
203208 out. push (
204209 CommandInfo :: new (
@@ -212,7 +217,7 @@ impl Component for BlameFilePopup {
212217 CommandInfo :: new (
213218 strings:: commands:: scroll ( & self . key_config ) ,
214219 true ,
215- file_blame . is_some ( ) ,
220+ has_result ,
216221 )
217222 . order ( 1 ) ,
218223 ) ;
@@ -222,7 +227,7 @@ impl Component for BlameFilePopup {
222227 & self . key_config ,
223228 ) ,
224229 true ,
225- file_blame . is_some ( ) ,
230+ has_result ,
226231 )
227232 . order ( 1 ) ,
228233 ) ;
@@ -232,7 +237,7 @@ impl Component for BlameFilePopup {
232237 & self . key_config ,
233238 ) ,
234239 true ,
235- file_blame . is_some ( ) ,
240+ has_result ,
236241 )
237242 . order ( 1 ) ,
238243 ) ;
@@ -344,10 +349,7 @@ impl BlameFilePopup {
344349 current_height : std:: cell:: Cell :: new ( 0 ) ,
345350 app_sender : env. sender_app . clone ( ) ,
346351 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 ,
351353 repo : env. repo . clone ( ) ,
352354 }
353355 }
@@ -376,10 +378,11 @@ impl BlameFilePopup {
376378 file_path : open. file_path ,
377379 commit_id : open. commit_id ,
378380 } ) ;
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+ ) ) ) ;
383386 self . table_state . get_mut ( ) . select ( Some ( 0 ) ) ;
384387 self . visible = true ;
385388 self . update ( ) ?;
@@ -389,7 +392,8 @@ impl BlameFilePopup {
389392
390393 ///
391394 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 ( _) ) )
393397 }
394398
395399 pub fn update_async (
@@ -417,35 +421,38 @@ impl BlameFilePopup {
417421
418422 fn update ( & mut self ) -> Result < ( ) > {
419423 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 ( ( ) ) ;
445452 }
446-
447- async_blame. request ( params. clone ( ) ) ?;
448453 }
454+
455+ async_blame. request ( params. clone ( ) ) ?;
449456 }
450457 }
451458 }
@@ -454,10 +461,10 @@ impl BlameFilePopup {
454461 }
455462
456463 fn update_syntax ( & mut self , ev : AsyncNotification ) {
457- let BlameProcess :: SyntaxHighlighting {
464+ let Some ( BlameProcess :: SyntaxHighlighting {
458465 ref unstyled_file_blame,
459466 ref job,
460- } = self . blame
467+ } ) = self . blame
461468 else {
462469 return ;
463470 } ;
@@ -474,15 +481,16 @@ impl BlameFilePopup {
474481 == Path :: new (
475482 unstyled_file_blame. path ( ) ,
476483 ) {
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+ ) ) ;
486494 }
487495 }
488496 }
@@ -497,7 +505,7 @@ impl BlameFilePopup {
497505 match (
498506 self . any_work_pending ( ) ,
499507 self . params . as_ref ( ) ,
500- self . blame . result ( ) ,
508+ self . blame . as_ref ( ) . and_then ( |blame| blame . result ( ) ) ,
501509 ) {
502510 ( true , Some ( params) , _) => {
503511 format ! (
@@ -525,9 +533,9 @@ impl BlameFilePopup {
525533
526534 ///
527535 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 ( ) )
531539 . map ( |file_blame| {
532540 let styled_text: Option < Text < ' _ > > = file_blame
533541 . styled_text
@@ -552,10 +560,10 @@ impl BlameFilePopup {
552560 }
553561
554562 fn highlight_blame_lines ( & mut self ) {
555- let BlameProcess :: SyntaxHighlighting {
563+ let Some ( BlameProcess :: SyntaxHighlighting {
556564 ref unstyled_file_blame,
557565 ref mut job,
558- } = self . blame
566+ } ) = self . blame
559567 else {
560568 return ;
561569 } ;
@@ -651,7 +659,8 @@ impl BlameFilePopup {
651659 time_to_string ( hunk. time , true )
652660 } ) ;
653661
654- let file_blame = self . blame . result ( ) ;
662+ let file_blame =
663+ self . blame . as_ref ( ) . and_then ( |blame| blame. result ( ) ) ;
655664 let is_blamed_commit = file_blame
656665 . and_then ( |file_blame| {
657666 blame_hunk. map ( |hunk| {
@@ -671,7 +680,8 @@ impl BlameFilePopup {
671680
672681 fn get_max_line_number ( & self ) -> usize {
673682 self . blame
674- . result ( )
683+ . as_ref ( )
684+ . and_then ( |blame| blame. result ( ) )
675685 . map_or ( 0 , |file_blame| file_blame. lines ( ) . len ( ) - 1 )
676686 }
677687
@@ -723,33 +733,39 @@ impl BlameFilePopup {
723733 }
724734
725735 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 ( ) ;
728741
729- let selection = table_state. selected ( ) ;
742+ let selection = table_state. selected ( ) ;
730743
731- self . table_state . set ( table_state) ;
744+ self . table_state . set ( table_state) ;
732745
733- selection
734- } )
746+ selection
747+ } )
735748 }
736749
737750 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 ( ) ;
740756
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+ } ) ;
748764
749- self . table_state . set ( table_state) ;
765+ self . table_state . set ( table_state) ;
750766
751- commit_id
752- } )
767+ commit_id
768+ } )
753769 }
754770}
755771
0 commit comments