@@ -317,13 +317,6 @@ impl Graph {
317
317
. iter ( )
318
318
. filter_map ( |s| {
319
319
s. base_segment_id ( ) . and_then ( |sidx| {
320
- let base_is_directly_connected_to_workspace = self
321
- . inner
322
- . neighbors_directed ( sidx, Direction :: Incoming )
323
- . any ( |above_sidx| above_sidx == ws_sidx) ;
324
- if base_is_directly_connected_to_workspace {
325
- return None ;
326
- }
327
320
let base_segment = & self [ sidx] ;
328
321
// These are naturally in the workspace.
329
322
base_segment
@@ -410,61 +403,6 @@ impl Graph {
410
403
return Ok ( ( ) ) ;
411
404
} ;
412
405
413
- // If the target branch made it into a stack segment which can also be named differently by preferably a ref with metadata,
414
- // then do that instead. Let's prevent it from showing up as its own node as this leads to undesirable workspaces.
415
- if let Some ( ( target_segment_id, local_tracking_segment_of_target) ) =
416
- ws_target. as_ref ( ) . and_then ( |t| {
417
- self [ t. segment_index ]
418
- . sibling_segment_id
419
- . map ( |sidx| ( t. segment_index , sidx) )
420
- } )
421
- && let Some ( segment_id) = ws_stacks. iter ( ) . find_map ( |s| {
422
- s. segments . iter ( ) . find_map ( |s| {
423
- if s. id != local_tracking_segment_of_target {
424
- return None ;
425
- }
426
- let first_commit = s. commits . first ( ) ?;
427
- ( !first_commit. refs . is_empty ( ) ) . then_some ( s. id )
428
- } )
429
- } )
430
- {
431
- let s = & mut self [ segment_id] ;
432
- let c = s
433
- . commits
434
- . first_mut ( )
435
- . expect ( "segment was chosen because it has at least one commit" ) ;
436
- let mut candidates = c. refs . clone ( ) ;
437
- candidates. sort_by ( |a, b| {
438
- meta. branch_opt ( a. as_ref ( ) )
439
- . ok ( )
440
- . map ( |md| md. is_some ( ) )
441
- . cmp ( & meta. branch_opt ( b. as_ref ( ) ) . ok ( ) . map ( |md| md. is_some ( ) ) )
442
- . then_with ( || a. cmp ( b) )
443
- } ) ;
444
- let candidate = candidates
445
- . pop ( )
446
- . expect ( "at least one ref or we wouldn't be here" ) ;
447
- let current_name = s. ref_name . take ( ) ;
448
- let index_to_replace = c
449
- . refs
450
- . iter ( )
451
- . position ( |rn| rn == & candidate)
452
- . expect ( "candidate is from a clone of 'refs', so must be contained" ) ;
453
- // effectively swap the names
454
- s. metadata = meta
455
- . branch_opt ( candidate. as_ref ( ) ) ?
456
- . map ( SegmentMetadata :: Branch ) ;
457
- s. ref_name = Some ( candidate) ;
458
- if let Some ( rn) = current_name {
459
- c. refs [ index_to_replace] = rn;
460
- }
461
-
462
- // Make sure we dissolve the sibling relationship for correctness, the node is now not related
463
- // to the target branch anymore.
464
- s. sibling_segment_id = None ;
465
- self [ target_segment_id] . sibling_segment_id = None ;
466
- }
467
-
468
406
// Setup independent stacks, first by looking at potential bases.
469
407
let candidates = self . candidates_for_independent_branches_in_workspace (
470
408
ws_sidx,
@@ -479,10 +417,14 @@ impl Graph {
479
417
let base_segment_name = base_segment. ref_name . clone ( ) ;
480
418
let matching_refs_per_stack: Vec < _ > = find_all_desired_stack_refs_in_commit (
481
419
& ws_data,
482
- base_segment_name
483
- . as_ref ( )
484
- . into_iter ( )
485
- . chain ( base_segment. commits [ 0 ] . refs . iter ( ) ) ,
420
+ base_segment_name. as_ref ( ) . into_iter ( ) . chain (
421
+ base_segment
422
+ . commits
423
+ . first ( )
424
+ . map ( |c| c. refs . iter ( ) )
425
+ . into_iter ( )
426
+ . flatten ( ) ,
427
+ ) ,
486
428
Some ( ( & self . inner , ws_sidx, & ws_stacks, & candidates) ) ,
487
429
)
488
430
. collect ( ) ;
@@ -568,10 +510,17 @@ impl Graph {
568
510
Some ( ( last_created_segment. unwrap_or ( s. id ) , base_sidx, c) )
569
511
} )
570
512
{
571
- let Some ( refs_for_dependent_branches) =
572
- find_all_desired_stack_refs_in_commit ( & ws_data, commit. refs . iter ( ) , None )
573
- . next ( )
574
- else {
513
+ let Some ( refs_for_dependent_branches) = find_all_desired_stack_refs_in_commit (
514
+ & ws_data,
515
+ self [ base_sidx]
516
+ . ref_name
517
+ . as_ref ( )
518
+ . filter ( |_| !commit. refs . is_empty ( ) )
519
+ . into_iter ( )
520
+ . chain ( commit. refs . iter ( ) ) ,
521
+ None ,
522
+ )
523
+ . next ( ) else {
575
524
continue ;
576
525
} ;
577
526
@@ -593,12 +542,34 @@ impl Graph {
593
542
) ?;
594
543
595
544
// As we didn't allow the previous function to deal with the commit, we do it.
596
- self [ base_sidx]
597
- . commits
545
+ let s = & mut self [ base_sidx] ;
546
+ s . commits
598
547
. first_mut ( )
599
548
. expect ( "we know there is one already" )
600
549
. refs
601
550
. retain ( |rn| !refs_for_dependent_branches. contains ( rn) ) ;
551
+ s. ref_name
552
+ . take_if ( |rn| refs_for_dependent_branches. contains ( rn) ) ;
553
+ if s. ref_name . is_none ( ) {
554
+ s. metadata = None ;
555
+ if let Some ( sibling) = s. sibling_segment_id . take ( ) {
556
+ self [ sibling] . sibling_segment_id = None ;
557
+ }
558
+ }
559
+
560
+ let s = & mut self [ base_sidx] ;
561
+ if let Some ( refs) = s
562
+ . commits
563
+ . first_mut ( )
564
+ . filter ( |c| !c. refs . is_empty ( ) )
565
+ . map ( |c| & mut c. refs )
566
+ && let Some ( ( name, md) ) =
567
+ disambiguate_refs_by_branch_metadata ( refs. iter ( ) , meta)
568
+ {
569
+ refs. retain ( |rn| rn != & name) ;
570
+ s. ref_name = Some ( name) ;
571
+ s. metadata = md;
572
+ }
602
573
reconnect_edges (
603
574
self ,
604
575
edges_from_segment_above,
@@ -790,6 +761,8 @@ impl Graph {
790
761
s. sibling_segment_id = Some ( remote_sidx) ;
791
762
let rn = s. ref_name . as_ref ( ) . expect ( "just set it" ) ;
792
763
s. commits . first_mut ( ) . unwrap ( ) . refs . retain ( |crn| crn != rn) ;
764
+ // Assure the remote is also paired up!
765
+ self [ remote_sidx] . sibling_segment_id = Some ( s. id ) ;
793
766
}
794
767
795
768
// NOTE: setting this directly at iteration time isn't great as the post-processing then
0 commit comments