@@ -33,10 +33,7 @@ use crate::{
3333 CliId ,
3434 command:: legacy:: {
3535 reword:: get_branch_name_from_editor,
36- rub:: {
37- RubOperation , RubOperationDiscriminants , StackToCommitOperation ,
38- UnassignedToCommitOperation ,
39- } ,
36+ rub:: RubOperationDiscriminants ,
4037 status:: {
4138 CommitLineContent , FileLineContent , StatusFlags , StatusOutputLine , TuiLaunchOptions ,
4239 output:: BranchLineContent ,
@@ -604,6 +601,9 @@ impl App {
604601 } => {
605602 self . handle_start_rub_with_source ( source, unlock_details) ;
606603 }
604+ RubMessage :: StartReverse => {
605+ self . handle_rub_start_reverse ( ctx) ?;
606+ }
607607 RubMessage :: Confirm => self . handle_confirm_rub ( ctx, messages) ?,
608608 } ,
609609 Message :: EnterNormalMode => {
@@ -727,9 +727,6 @@ impl App {
727727 terminal_area,
728728 ) ;
729729 }
730- Message :: Amend => {
731- self . handle_amend ( ctx) ?;
732- }
733730 }
734731
735732 self . ensure_cursor_visible ( visible_height) ;
@@ -813,6 +810,23 @@ impl App {
813810 self . handle_start_rub_with_source ( RubSource :: CliId ( Arc :: clone ( cli_id) ) , None ) ;
814811 }
815812
813+ fn available_targets_for_rub_mode ( & self , source : & RubSource ) -> Vec < Arc < CliId > > {
814+ self . status_lines
815+ . iter ( )
816+ . filter_map ( |line| line. data . cli_id ( ) )
817+ . filter ( |target| {
818+ * source == * * * target
819+ || match & source {
820+ RubSource :: CliId ( source) => rub:: route_operation ( source, target) . is_some ( ) ,
821+ RubSource :: CommittedHunk ( hunk) => {
822+ rub_from_detail_view:: route_operation ( hunk, target) . is_some ( )
823+ }
824+ }
825+ } )
826+ . cloned ( )
827+ . collect :: < Vec < _ > > ( )
828+ }
829+
816830 fn handle_start_rub_with_source (
817831 & mut self ,
818832 source : RubSource ,
@@ -827,21 +841,7 @@ impl App {
827841 RubSource :: CommittedHunk ( ..) => { }
828842 }
829843
830- let available_targets = self
831- . status_lines
832- . iter ( )
833- . filter_map ( |line| line. data . cli_id ( ) )
834- . filter ( |target| {
835- source == * * * target
836- || match & source {
837- RubSource :: CliId ( source) => rub:: route_operation ( source, target) . is_some ( ) ,
838- RubSource :: CommittedHunk ( hunk) => {
839- rub_from_detail_view:: route_operation ( hunk, target) . is_some ( )
840- }
841- }
842- } )
843- . cloned ( )
844- . collect :: < Vec < _ > > ( ) ;
844+ let available_targets = self . available_targets_for_rub_mode ( & source) ;
845845
846846 self . mode = Mode :: Rub ( RubMode {
847847 source,
@@ -872,6 +872,61 @@ impl App {
872872 }
873873 }
874874
875+ fn handle_rub_start_reverse ( & mut self , ctx : & mut Context ) -> anyhow:: Result < ( ) > {
876+ let Some ( selection) = self
877+ . cursor
878+ . selected_line ( & self . status_lines )
879+ . and_then ( |line| line. data . cli_id ( ) )
880+ else {
881+ return Ok ( ( ) ) ;
882+ } ;
883+
884+ let CliId :: Commit { commit_id, .. } = & * * selection else {
885+ return Ok ( ( ) ) ;
886+ } ;
887+
888+ let stack_id = {
889+ let ( _guard, _, ws, _) = ctx. workspace_and_db ( ) ?;
890+ ws. find_commit_and_containers ( * commit_id)
891+ . and_then ( |( stack, _, _) | stack. id )
892+ } ;
893+
894+ let source = if let Some ( stack_id) = stack_id
895+ && operations:: stack_has_assigned_changes ( ctx, stack_id) ?
896+ && let Some ( id) = self
897+ . status_lines
898+ . iter ( )
899+ . filter_map ( |line| line. data . cli_id ( ) )
900+ . find_map ( |id| {
901+ if let CliId :: Stack { id, stack_id : sid } = & * * id
902+ && * sid == stack_id
903+ {
904+ Some ( id)
905+ } else {
906+ None
907+ }
908+ } ) {
909+ RubSource :: CliId ( Arc :: new ( CliId :: Stack {
910+ id : id. to_owned ( ) ,
911+ stack_id,
912+ } ) )
913+ } else {
914+ RubSource :: CliId ( Arc :: new ( CliId :: Unassigned {
915+ id : UNASSIGNED . to_owned ( ) ,
916+ } ) )
917+ } ;
918+
919+ let available_targets = self . available_targets_for_rub_mode ( & source) ;
920+
921+ self . mode = Mode :: Rub ( RubMode {
922+ source,
923+ available_targets,
924+ _unlock_details : None ,
925+ } ) ;
926+
927+ Ok ( ( ) )
928+ }
929+
875930 /// Handles toggling file visibility and requests a status reload.
876931 fn handle_toggle_global_files_list ( & mut self , messages : & mut Vec < Message > ) {
877932 self . flags . show_files = match self . flags . show_files {
@@ -2695,57 +2750,6 @@ impl App {
26952750 let details_viewport = self . details_viewport ( terminal_area) ;
26962751 self . details . ensure_selection_visible ( details_viewport) ;
26972752 }
2698-
2699- fn handle_amend ( & mut self , ctx : & mut Context ) -> anyhow:: Result < ( ) > {
2700- let Some ( selection) = self
2701- . cursor
2702- . selected_line ( & self . status_lines )
2703- . and_then ( |line| line. data . cli_id ( ) )
2704- else {
2705- return Ok ( ( ) ) ;
2706- } ;
2707-
2708- let CliId :: Commit { commit_id, .. } = & * * selection else {
2709- return Ok ( ( ) ) ;
2710- } ;
2711-
2712- let stack_id = {
2713- let ( _guard, _, ws, _) = ctx. workspace_and_db ( ) ?;
2714- ws. find_commit_and_containers ( * commit_id)
2715- . and_then ( |( stack, _, _) | stack. id )
2716- } ;
2717-
2718- let ( operation, confirm_message) = if let Some ( stack_id) = stack_id
2719- && operations:: stack_has_assigned_changes ( ctx, stack_id) ?
2720- {
2721- (
2722- RubOperation :: StackToCommit ( StackToCommitOperation {
2723- from : stack_id,
2724- to : * commit_id,
2725- } ) ,
2726- format ! (
2727- "Amend changes assigned to stack into {}?" ,
2728- commit_id. to_hex_with_len( 7 )
2729- ) ,
2730- )
2731- } else {
2732- (
2733- RubOperation :: UnassignedToCommit ( UnassignedToCommitOperation { oid : * commit_id } ) ,
2734- format ! ( "Amend unassigned into {}?" , commit_id. to_hex_with_len( 7 ) ) ,
2735- )
2736- } ;
2737-
2738- self . confirm = Some ( Confirm :: new (
2739- confirm_message,
2740- run_after_confirmation_msg ( move |_, ctx, messages| {
2741- let what_to_select = operations:: rub ( ctx, & operation) ?;
2742- messages. push ( Message :: Reload ( what_to_select) ) ;
2743- Ok ( ( ) )
2744- } ) ,
2745- ) ) ;
2746-
2747- Ok ( ( ) )
2748- }
27492753}
27502754
27512755fn event_to_messages ( ev : Event , key_binds : & KeyBinds , mode : & Mode , messages : & mut Vec < Message > ) {
@@ -2832,7 +2836,6 @@ enum Message {
28322836 EnterDetailsMode ,
28332837 LeaveDetailsMode ,
28342838 NewBranch ,
2835- Amend ,
28362839
28372840 // Utilities
28382841 CopySelection ,
@@ -2887,6 +2890,7 @@ enum RubMessage {
28872890 source : RubSource ,
28882891 unlock_details : Option < MessageOnDrop > ,
28892892 } ,
2893+ StartReverse ,
28902894 Confirm ,
28912895}
28922896
0 commit comments