@@ -42,6 +42,7 @@ pub fn split(
42
42
resolve_revset_options : & ResolveRevsetOptions ,
43
43
files_to_extract : Vec < String > ,
44
44
detach : bool ,
45
+ discard : bool ,
45
46
move_options : & MoveOptions ,
46
47
git_run_info : & GitRunInfo ,
47
48
) -> EyreExitOr < ( ) > {
@@ -248,46 +249,57 @@ pub fn split(
248
249
return Ok ( Err ( ExitCode ( 1 ) ) ) ;
249
250
} ;
250
251
251
- let extracted_tree = repo. cherry_pick_fast (
252
- & commit_to_split,
253
- & split_commit,
254
- & CherryPickFastOptions {
255
- reuse_parent_tree_if_possible : true ,
256
- } ,
257
- ) ?;
258
- let extracted_commit_oid = repo. create_commit (
259
- None ,
260
- & commit_to_split. get_author ( ) ,
261
- & commit_to_split. get_committer ( ) ,
262
- format ! ( "temp(split): {message}" ) . as_str ( ) ,
263
- & extracted_tree,
264
- vec ! [ & split_commit] ,
265
- ) ?;
266
-
267
- // see git-branchless/src/commands/amend.rs:172
268
- // TODO maybe this should happen after we've confirmed the rebase has succeeded
269
- mark_commit_reachable ( & repo, extracted_commit_oid)
270
- . wrap_err ( "Marking commit as reachable for GC purposes." ) ?;
271
252
event_log_db. add_events ( vec ! [ Event :: RewriteEvent {
272
253
timestamp: now. duration_since( UNIX_EPOCH ) ?. as_secs_f64( ) ,
273
254
event_tx_id,
274
255
old_commit_oid: MaybeZeroOid :: NonZero ( commit_to_split_oid) ,
275
256
new_commit_oid: MaybeZeroOid :: NonZero ( split_commit_oid) ,
276
257
} ] ) ?;
277
- event_log_db. add_events ( vec ! [ Event :: CommitEvent {
278
- timestamp: now. duration_since( UNIX_EPOCH ) ?. as_secs_f64( ) ,
279
- event_tx_id,
280
- commit_oid: extracted_commit_oid,
281
- } ] ) ?;
258
+
259
+ let extracted_commit_oid = if discard {
260
+ None
261
+ } else {
262
+ let extracted_tree = repo. cherry_pick_fast (
263
+ & commit_to_split,
264
+ & split_commit,
265
+ & CherryPickFastOptions {
266
+ reuse_parent_tree_if_possible : true ,
267
+ } ,
268
+ ) ?;
269
+ let extracted_commit_oid = repo. create_commit (
270
+ None ,
271
+ & commit_to_split. get_author ( ) ,
272
+ & commit_to_split. get_committer ( ) ,
273
+ format ! ( "temp(split): {message}" ) . as_str ( ) ,
274
+ & extracted_tree,
275
+ vec ! [ & split_commit] ,
276
+ ) ?;
277
+
278
+ // see git-branchless/src/commands/amend.rs:172
279
+ // TODO maybe this should happen after we've confirmed the rebase has succeeded
280
+ mark_commit_reachable ( & repo, extracted_commit_oid)
281
+ . wrap_err ( "Marking commit as reachable for GC purposes." ) ?;
282
+
283
+ event_log_db. add_events ( vec ! [ Event :: CommitEvent {
284
+ timestamp: now. duration_since( UNIX_EPOCH ) ?. as_secs_f64( ) ,
285
+ event_tx_id,
286
+ commit_oid: extracted_commit_oid,
287
+ } ] ) ?;
288
+
289
+ Some ( extracted_commit_oid)
290
+ } ;
282
291
283
292
// push the new commits into the dag for the rebase planner
284
293
dag. sync_from_oids (
285
294
effects,
286
295
& repo,
287
296
CommitSet :: empty ( ) ,
288
- vec ! [ split_commit_oid, extracted_commit_oid]
289
- . into_iter ( )
290
- . collect ( ) ,
297
+ match extracted_commit_oid {
298
+ None => CommitSet :: from ( split_commit_oid) ,
299
+ Some ( extracted_commit_oid) => vec ! [ split_commit_oid, extracted_commit_oid]
300
+ . into_iter ( )
301
+ . collect ( ) ,
302
+ } ,
291
303
) ?;
292
304
293
305
let head_info = repo. get_head_info ( ) ?;
@@ -297,11 +309,11 @@ pub fn split(
297
309
ResolvedReferenceInfo {
298
310
oid : Some ( oid) ,
299
311
reference_name : Some ( _) ,
300
- } if oid == commit_to_split_oid && !detach => (
312
+ } if oid == commit_to_split_oid && !detach && extracted_commit_oid . is_some ( ) => (
301
313
None ,
302
314
vec ! [ (
303
315
commit_to_split_oid,
304
- MaybeZeroOid :: NonZero ( extracted_commit_oid) ,
316
+ MaybeZeroOid :: NonZero ( extracted_commit_oid. unwrap ( ) ) ,
305
317
) ] ,
306
318
) ,
307
319
@@ -353,10 +365,11 @@ pub fn split(
353
365
let mut builder = RebasePlanBuilder :: new ( & dag, permissions) ;
354
366
let children = dag. query_children ( CommitSet :: from ( commit_to_split_oid) ) ?;
355
367
for child in dag. commit_set_to_vec ( & children) ? {
356
- if detach {
357
- builder. move_subtree ( child, vec ! [ split_commit_oid] ) ?;
358
- } else {
359
- builder. move_subtree ( child, vec ! [ extracted_commit_oid] ) ?;
368
+ match ( detach, extracted_commit_oid) {
369
+ ( _, None ) | ( true , Some ( _) ) => builder. move_subtree ( child, vec ! [ split_commit_oid] ) ?,
370
+ ( _, Some ( extracted_commit_oid) ) => {
371
+ builder. move_subtree ( child, vec ! [ extracted_commit_oid] ) ?
372
+ }
360
373
}
361
374
}
362
375
let rebase_plan = builder. build ( effects, & pool, & repo_pool) ?;
0 commit comments