@@ -15,7 +15,7 @@ use git_branchless_revset::{check_revset_syntax, resolve_commits};
15
15
use lib:: core:: config:: get_restack_preserve_timestamps;
16
16
use lib:: core:: dag:: { sorted_commit_set, union_all, CommitSet , Dag } ;
17
17
use lib:: core:: effects:: { Effects , OperationType , WithProgress } ;
18
- use lib:: core:: eventlog:: { EventLogDb , EventReplayer } ;
18
+ use lib:: core:: eventlog:: { EventLogDb , EventReplayer , EventTransactionId } ;
19
19
use lib:: core:: formatting:: { BaseColor , Pluralize , StyledStringBuilder } ;
20
20
use lib:: core:: rewrite:: {
21
21
execute_rebase_plan, BuildRebasePlanError , BuildRebasePlanOptions , ExecuteRebasePlanOptions ,
@@ -45,6 +45,7 @@ fn get_stack_roots(dag: &Dag, commit_sets: Vec<CommitSet>) -> eyre::Result<Commi
45
45
}
46
46
47
47
/// Move all commit stacks on top of the main branch.
48
+ #[ tracing:: instrument]
48
49
pub fn sync (
49
50
effects : & Effects ,
50
51
git_run_info : & GitRunInfo ,
@@ -63,10 +64,6 @@ pub fn sync(
63
64
// side-effects.
64
65
check_revset_syntax ( & repo, & revsets) ?;
65
66
66
- if pull {
67
- try_exit_code ! ( git_run_info. run( effects, Some ( event_tx_id) , & [ "fetch" , "--all" ] ) ?) ;
68
- }
69
-
70
67
let MoveOptions {
71
68
force_rewrite_public_commits,
72
69
force_in_memory,
@@ -82,8 +79,6 @@ pub fn sync(
82
79
dump_rebase_constraints,
83
80
dump_rebase_plan,
84
81
} ;
85
- let now = SystemTime :: now ( ) ;
86
- let event_tx_id = event_log_db. make_transaction_id ( now, "sync" ) ?;
87
82
let execute_options = ExecuteRebasePlanOptions {
88
83
now,
89
84
event_tx_id,
@@ -100,13 +95,16 @@ pub fn sync(
100
95
let thread_pool = ThreadPoolBuilder :: new ( ) . build ( ) ?;
101
96
let repo_pool = RepoResource :: new_pool ( & repo) ?;
102
97
103
- let head_info = repo. get_head_info ( ) ?;
104
98
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(
106
101
effects,
107
102
git_run_info,
108
- & repo,
109
103
& event_log_db,
104
+ event_tx_id,
105
+ & repo,
106
+ & revsets,
107
+ resolve_revset_options,
110
108
& build_options,
111
109
& execute_options,
112
110
& thread_pool,
@@ -115,9 +113,9 @@ pub fn sync(
115
113
) ?) ;
116
114
}
117
115
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(
121
119
effects,
122
120
git_run_info,
123
121
& repo,
@@ -128,9 +126,44 @@ pub fn sync(
128
126
& repo_pool,
129
127
revsets,
130
128
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 ( ( ) ) )
132
164
}
133
165
166
+ #[ tracing:: instrument]
134
167
fn execute_main_branch_sync_plan (
135
168
effects : & Effects ,
136
169
git_run_info : & GitRunInfo ,
@@ -293,6 +326,7 @@ fn execute_main_branch_sync_plan(
293
326
)
294
327
}
295
328
329
+ #[ tracing:: instrument]
296
330
fn execute_sync_plans (
297
331
effects : & Effects ,
298
332
git_run_info : & GitRunInfo ,
@@ -388,6 +422,7 @@ fn execute_sync_plans(
388
422
)
389
423
}
390
424
425
+ #[ tracing:: instrument]
391
426
fn execute_plans (
392
427
effects : & Effects ,
393
428
git_run_info : & GitRunInfo ,
0 commit comments