@@ -3,9 +3,10 @@ use std::io::{self, Write};
33
44use crate :: commands:: doctor;
55use crate :: core:: config:: RailConfig ;
6+ use crate :: core:: context:: WorkspaceContext ;
67use crate :: core:: error:: { ConfigError , RailError , RailResult } ;
8+ use crate :: core:: executor:: PlanExecutor ;
79use crate :: core:: plan:: { Operation , OperationType , Plan } ;
8- use crate :: core:: split:: { SplitConfig , Splitter } ;
910use crate :: ui:: progress:: { FileProgress , MultiProgress } ;
1011use crate :: utils;
1112use rayon:: prelude:: * ;
@@ -119,9 +120,6 @@ pub fn run_split(
119120 }
120121 }
121122
122- // Create splitter with security config
123- let splitter = Splitter :: new ( config. workspace . root . clone ( ) , config. security . clone ( ) ) ?;
124-
125123 // Build plans using the unified Plan system
126124 let mut plans = Vec :: new ( ) ;
127125
@@ -141,33 +139,17 @@ pub fn run_split(
141139 current_dir. join ( ".." ) . join ( remote_name)
142140 } ;
143141
144- // Build unified Plan
142+ // Build unified Plan with ExecuteSplit operation
145143 let mut plan = Plan :: new ( OperationType :: Split , Some ( split_config. name . clone ( ) ) ) ;
146144
147- // Add operations
148- plan. add_operation ( Operation :: InitRepo {
149- path : target_repo_path. display ( ) . to_string ( ) ,
150- } ) ;
151-
152- plan. add_operation ( Operation :: CreateCommit {
153- message : "Walking commit history for crate paths" . to_string ( ) ,
154- files : crate_paths. iter ( ) . map ( |p| p. display ( ) . to_string ( ) ) . collect ( ) ,
155- } ) ;
156-
157- plan. add_operation ( Operation :: Transform {
158- path : target_repo_path. join ( "Cargo.toml" ) . display ( ) . to_string ( ) ,
159- transform_type : "workspace_to_concrete" . to_string ( ) ,
160- } ) ;
161-
162- plan. add_operation ( Operation :: Copy {
163- from : "auxiliary_files" . to_string ( ) ,
164- to : target_repo_path. display ( ) . to_string ( ) ,
165- } ) ;
166-
167- plan. add_operation ( Operation :: Push {
168- remote : split_config. remote . clone ( ) ,
145+ // Add high-level ExecuteSplit operation
146+ plan. add_operation ( Operation :: ExecuteSplit {
147+ crate_name : split_config. name . clone ( ) ,
148+ crate_paths : crate_paths. iter ( ) . map ( |p| p. display ( ) . to_string ( ) ) . collect ( ) ,
149+ mode : format ! ( "{:?}" , split_config. mode) ,
150+ target_repo_path : target_repo_path. display ( ) . to_string ( ) ,
169151 branch : split_config. branch . clone ( ) ,
170- force : false ,
152+ remote_url : Some ( split_config . remote . clone ( ) ) ,
171153 } ) ;
172154
173155 // Add metadata
@@ -233,6 +215,10 @@ pub fn run_split(
233215 println ! ( "\n 🚀 APPLY MODE - Executing split operations\n " ) ;
234216 }
235217
218+ // Build workspace context for execution
219+ let workspace_context = WorkspaceContext :: build ( & current_dir) ?;
220+ let executor = PlanExecutor :: new ( & workspace_context) ;
221+
236222 let plan_count = plans. len ( ) ;
237223
238224 // Use parallel processing for multiple crates
@@ -245,22 +231,15 @@ pub fn run_split(
245231 . map ( |( split_config, _, _, _) | multi_progress. add_bar ( 1 , format ! ( "Splitting {}" , split_config. name) ) )
246232 . collect ( ) ;
247233
234+ // For parallel execution, we need to build contexts per-thread
248235 let results: Vec < RailResult < ( ) > > = plans
249236 . into_par_iter ( )
250237 . enumerate ( )
251- . map ( |( idx, ( split_config, crate_paths, target_repo_path, _) ) | {
252- let split_cfg = SplitConfig {
253- crate_name : split_config. name . clone ( ) ,
254- crate_paths,
255- mode : split_config. mode . clone ( ) ,
256- target_repo_path,
257- branch : split_config. branch . clone ( ) ,
258- remote_url : Some ( split_config. remote . clone ( ) ) ,
259- } ;
260-
261- // Create a new splitter for this thread
262- let thread_splitter = Splitter :: new ( config. workspace . root . clone ( ) , config. security . clone ( ) ) ?;
263- let result = thread_splitter. split ( & split_cfg) ;
238+ . map ( |( idx, ( _, _, _, plan) ) | {
239+ // Build workspace context for this thread
240+ let thread_context = WorkspaceContext :: build ( & current_dir) ?;
241+ let thread_executor = PlanExecutor :: new ( & thread_context) ;
242+ let result = thread_executor. execute ( & plan) ;
264243
265244 multi_progress. inc ( & bars[ idx] ) ;
266245 result
@@ -282,21 +261,12 @@ pub fn run_split(
282261 None
283262 } ;
284263
285- for ( split_config, crate_paths , target_repo_path , _ ) in plans {
264+ for ( split_config, _ , _ , plan ) in plans {
286265 if crate_progress. is_none ( ) {
287266 println ! ( "🔨 Splitting crate '{}'..." , split_config. name) ;
288267 }
289268
290- let split_cfg = SplitConfig {
291- crate_name : split_config. name . clone ( ) ,
292- crate_paths,
293- mode : split_config. mode . clone ( ) ,
294- target_repo_path,
295- branch : split_config. branch . clone ( ) ,
296- remote_url : Some ( split_config. remote . clone ( ) ) ,
297- } ;
298-
299- splitter. split ( & split_cfg) ?;
269+ executor. execute ( & plan) ?;
300270
301271 if let Some ( ref mut p) = crate_progress {
302272 p. inc ( ) ;
0 commit comments