@@ -15,7 +15,7 @@ use git_branchless_revset::{check_revset_syntax, resolve_commits};
1515use lib:: core:: config:: get_restack_preserve_timestamps;
1616use lib:: core:: dag:: { sorted_commit_set, union_all, CommitSet , Dag } ;
1717use lib:: core:: effects:: { Effects , OperationType , WithProgress } ;
18- use lib:: core:: eventlog:: { EventLogDb , EventReplayer } ;
18+ use lib:: core:: eventlog:: { EventLogDb , EventReplayer , EventTransactionId } ;
1919use lib:: core:: formatting:: { BaseColor , Pluralize , StyledStringBuilder } ;
2020use lib:: core:: rewrite:: {
2121 execute_rebase_plan, BuildRebasePlanError , BuildRebasePlanOptions , ExecuteRebasePlanOptions ,
@@ -45,6 +45,7 @@ fn get_stack_roots(dag: &Dag, commit_sets: Vec<CommitSet>) -> eyre::Result<Commi
4545}
4646
4747/// Move all commit stacks on top of the main branch.
48+ #[ tracing:: instrument]
4849pub fn sync (
4950 effects : & Effects ,
5051 git_run_info : & GitRunInfo ,
@@ -63,10 +64,6 @@ pub fn sync(
6364 // side-effects.
6465 check_revset_syntax ( & repo, & revsets) ?;
6566
66- if pull {
67- try_exit_code ! ( git_run_info. run( effects, Some ( event_tx_id) , & [ "fetch" , "--all" ] ) ?) ;
68- }
69-
7067 let MoveOptions {
7168 force_rewrite_public_commits,
7269 force_in_memory,
@@ -82,8 +79,6 @@ pub fn sync(
8279 dump_rebase_constraints,
8380 dump_rebase_plan,
8481 } ;
85- let now = SystemTime :: now ( ) ;
86- let event_tx_id = event_log_db. make_transaction_id ( now, "sync" ) ?;
8782 let execute_options = ExecuteRebasePlanOptions {
8883 now,
8984 event_tx_id,
@@ -100,13 +95,16 @@ pub fn sync(
10095 let thread_pool = ThreadPoolBuilder :: new ( ) . build ( ) ?;
10196 let repo_pool = RepoResource :: new_pool ( & repo) ?;
10297
103- let head_info = repo. get_head_info ( ) ?;
10498 if pull {
105- try_exit_code ! ( execute_main_branch_sync_plan(
99+ let head_info = repo. get_head_info ( ) ?;
100+ try_exit_code ! ( pull_main_branch(
106101 effects,
107102 git_run_info,
108- & repo,
109103 & event_log_db,
104+ event_tx_id,
105+ & repo,
106+ & revsets,
107+ resolve_revset_options,
110108 & build_options,
111109 & execute_options,
112110 & thread_pool,
@@ -115,9 +113,9 @@ pub fn sync(
115113 ) ?) ;
116114 }
117115
118- // The main branch might have changed since we synced with `master`, so read its information again.
119-
120- execute_sync_plans (
116+ // NOTE: this function loads its own `Dag` as the graph may have changed after pulling the
117+ // main branch.
118+ try_exit_code ! ( execute_sync_plans(
121119 effects,
122120 git_run_info,
123121 & repo,
@@ -128,9 +126,44 @@ pub fn sync(
128126 & repo_pool,
129127 revsets,
130128 resolve_revset_options,
131- )
129+ ) ?) ;
130+
131+ Ok ( Ok ( ( ) ) )
132+ }
133+
134+ #[ tracing:: instrument]
135+ fn pull_main_branch (
136+ effects : & Effects ,
137+ git_run_info : & GitRunInfo ,
138+ event_log_db : & EventLogDb ,
139+ event_tx_id : EventTransactionId ,
140+ repo : & Repo ,
141+ revsets : & [ Revset ] ,
142+ resolve_revset_options : & ResolveRevsetOptions ,
143+ build_options : & BuildRebasePlanOptions ,
144+ execute_options : & ExecuteRebasePlanOptions ,
145+ thread_pool : & ThreadPool ,
146+ repo_pool : & RepoPool ,
147+ head_info : & ResolvedReferenceInfo ,
148+ ) -> EyreExitOr < ( ) > {
149+ try_exit_code ! ( git_run_info. run( effects, Some ( event_tx_id) , & [ "fetch" , "--all" ] ) ?) ;
150+
151+ try_exit_code ! ( execute_main_branch_sync_plan(
152+ effects,
153+ git_run_info,
154+ repo,
155+ event_log_db,
156+ build_options,
157+ execute_options,
158+ thread_pool,
159+ repo_pool,
160+ head_info,
161+ ) ?) ;
162+
163+ Ok ( Ok ( ( ) ) )
132164}
133165
166+ #[ tracing:: instrument]
134167fn execute_main_branch_sync_plan (
135168 effects : & Effects ,
136169 git_run_info : & GitRunInfo ,
@@ -293,6 +326,7 @@ fn execute_main_branch_sync_plan(
293326 )
294327}
295328
329+ #[ tracing:: instrument]
296330fn execute_sync_plans (
297331 effects : & Effects ,
298332 git_run_info : & GitRunInfo ,
@@ -388,6 +422,7 @@ fn execute_sync_plans(
388422 )
389423}
390424
425+ #[ tracing:: instrument]
391426fn execute_plans (
392427 effects : & Effects ,
393428 git_run_info : & GitRunInfo ,
0 commit comments