@@ -145,7 +145,7 @@ impl Graph {
145
145
// It's OK to default-initialise this here as overlays are only used when redoing
146
146
// the traversal.
147
147
let ( _repo, meta, _entrypoint) = Overlay :: default ( ) . into_parts ( repo, meta) ;
148
- graph. insert_root ( branch_segment_from_name_and_meta (
148
+ graph. insert_segment_set_entrypoint ( branch_segment_from_name_and_meta (
149
149
Some ( ( ref_name, None ) ) ,
150
150
& meta,
151
151
None ,
@@ -242,8 +242,10 @@ impl Graph {
242
242
meta : & OverlayMetadata < ' _ , T > ,
243
243
options : Options ,
244
244
) -> anyhow:: Result < Self > {
245
+ let ref_name = ref_name. into ( ) ;
245
246
let mut graph = Graph {
246
247
options : options. clone ( ) ,
248
+ entrypoint_ref : ref_name. clone ( ) ,
247
249
..Graph :: default ( )
248
250
} ;
249
251
let Options {
@@ -256,7 +258,6 @@ impl Graph {
256
258
} = options;
257
259
258
260
let max_limit = Limit :: new ( limit) ;
259
- let ref_name = ref_name. into ( ) ;
260
261
if ref_name
261
262
. as_ref ( )
262
263
. is_some_and ( |name| name. category ( ) == Some ( Category :: RemoteBranch ) )
@@ -271,6 +272,8 @@ impl Graph {
271
272
272
273
let configured_remote_tracking_branches =
273
274
remotes:: configured_remote_tracking_branches ( repo) ?;
275
+ let ( workspaces, target_refs) =
276
+ obtain_workspace_infos ( repo, ref_name. as_ref ( ) . map ( |rn| rn. as_ref ( ) ) , meta) ?;
274
277
let refs_by_id = repo. collect_ref_mapping_by_prefix (
275
278
[
276
279
"refs/heads/" ,
@@ -287,9 +290,11 @@ impl Graph {
287
290
} else {
288
291
None
289
292
} ) ,
293
+ & workspaces
294
+ . iter ( )
295
+ . map ( |( _, ref_name, _) | ref_name. as_ref ( ) )
296
+ . collect :: < Vec < _ > > ( ) ,
290
297
) ?;
291
- let ( workspaces, target_refs) =
292
- obtain_workspace_infos ( repo, ref_name. as_ref ( ) . map ( |rn| rn. as_ref ( ) ) , meta) ?;
293
298
let mut seen = gix:: revwalk:: graph:: IdMap :: < SegmentIndex > :: default ( ) ;
294
299
let mut goals = Goals :: default ( ) ;
295
300
// The tip transports itself.
@@ -332,8 +337,8 @@ impl Graph {
332
337
dangerously_skip_postprocessing_for_debugging,
333
338
} ;
334
339
if tip_is_not_workspace_commit {
335
- let current = graph. insert_root ( branch_segment_from_name_and_meta (
336
- ref_name . clone ( ) . map ( |rn| ( rn , None ) ) ,
340
+ let current = graph. insert_segment_set_entrypoint ( branch_segment_from_name_and_meta (
341
+ None ,
337
342
meta,
338
343
Some ( ( & ctx. refs_by_id , tip) ) ,
339
344
) ?) ;
@@ -352,10 +357,7 @@ impl Graph {
352
357
let target = ws_meta. target_ref . as_ref ( ) . and_then ( |trn| {
353
358
let tid = try_refname_to_id ( repo, trn. as_ref ( ) )
354
359
. map_err ( |err| {
355
- tracing:: warn!(
356
- "Ignoring non-existing target branch {trn}: {err}" ,
357
- trn = trn. as_bstr( )
358
- ) ;
360
+ tracing:: warn!( "Ignoring non-existing target branch {trn}: {err}" ) ;
359
361
err
360
362
} )
361
363
. ok ( ) ??;
@@ -386,7 +388,16 @@ impl Graph {
386
388
// The limits for the target ref and the worktree ref are synced so they can always find each other,
387
389
// while being able to stop when the entrypoint is included.
388
390
ws_segment. metadata = Some ( SegmentMetadata :: Workspace ( ws_meta) ) ;
389
- let ws_segment = graph. insert_root ( ws_segment) ;
391
+ let ws_segment = graph. insert_segment ( ws_segment) ;
392
+ if graph. entrypoint . is_none ( )
393
+ && graph
394
+ . entrypoint_ref
395
+ . as_ref ( )
396
+ . zip ( ref_name. as_ref ( ) )
397
+ . is_some_and ( |( a, b) | a == b)
398
+ {
399
+ graph. entrypoint = Some ( ( ws_segment, None ) ) ;
400
+ }
390
401
// As workspaces typically have integration branches which can help us to stop the traversal,
391
402
// pick these up first.
392
403
_ = next. push_front_exhausted ( (
@@ -401,45 +412,45 @@ impl Graph {
401
412
) ) ;
402
413
403
414
if let Some ( ( target_ref, target_ref_id, local_tip_info) ) = target {
404
- let target_segment = graph. insert_root ( branch_segment_from_name_and_meta (
415
+ let target_segment = graph. insert_segment ( branch_segment_from_name_and_meta (
405
416
Some ( ( target_ref, None ) ) ,
406
417
meta,
407
418
None ,
408
419
) ?) ;
409
- let ( local_sidx, local_goal) = if let Some ( ( local_ref_name, target_local_tip) ) =
410
- local_tip_info
411
- {
412
- let local_sidx = graph. insert_root ( branch_segment_from_name_and_meta_sibling (
413
- None ,
414
- Some ( target_segment) ,
415
- meta,
416
- Some ( ( & ctx. refs_by_id , target_local_tip) ) ,
417
- ) ?) ;
418
- // We use auto-naming based on ambiguity - if the name ends up something else,
419
- // remove the nodes sibling link.
420
- let has_sibling_link = {
421
- let s = & mut graph[ local_sidx] ;
422
- if s. ref_name . as_ref ( ) . is_none_or ( |rn| rn != & local_ref_name) {
423
- s. sibling_segment_id = None ;
424
- false
425
- } else {
426
- true
427
- }
420
+ let ( local_sidx, local_goal) =
421
+ if let Some ( ( local_ref_name, target_local_tip) ) = local_tip_info {
422
+ let local_sidx =
423
+ graph. insert_segment ( branch_segment_from_name_and_meta_sibling (
424
+ None ,
425
+ Some ( target_segment) ,
426
+ meta,
427
+ Some ( ( & ctx. refs_by_id , target_local_tip) ) ,
428
+ ) ?) ;
429
+ // We use auto-naming based on ambiguity - if the name ends up something else,
430
+ // remove the nodes sibling link.
431
+ let has_sibling_link = {
432
+ let s = & mut graph[ local_sidx] ;
433
+ if s. ref_name . as_ref ( ) . is_none_or ( |rn| rn != & local_ref_name) {
434
+ s. sibling_segment_id = None ;
435
+ false
436
+ } else {
437
+ true
438
+ }
439
+ } ;
440
+ let goal = goals. flag_for ( target_local_tip) . unwrap_or_default ( ) ;
441
+ _ = next. push_front_exhausted ( (
442
+ target_local_tip,
443
+ CommitFlags :: NotInRemote | goal,
444
+ Instruction :: CollectCommit { into : local_sidx } ,
445
+ max_limit
446
+ . with_indirect_goal ( tip, & mut goals)
447
+ . without_allowance ( ) ,
448
+ ) ) ;
449
+ next. add_goal_to ( tip, goal) ;
450
+ ( has_sibling_link. then_some ( local_sidx) , goal)
451
+ } else {
452
+ ( None , CommitFlags :: empty ( ) )
428
453
} ;
429
- let goal = goals. flag_for ( target_local_tip) . unwrap_or_default ( ) ;
430
- _ = next. push_front_exhausted ( (
431
- target_local_tip,
432
- CommitFlags :: NotInRemote | goal,
433
- Instruction :: CollectCommit { into : local_sidx } ,
434
- max_limit
435
- . with_indirect_goal ( tip, & mut goals)
436
- . without_allowance ( ) ,
437
- ) ) ;
438
- next. add_goal_to ( tip, goal) ;
439
- ( has_sibling_link. then_some ( local_sidx) , goal)
440
- } else {
441
- ( None , CommitFlags :: empty ( ) )
442
- } ;
443
454
_ = next. push_front_exhausted ( (
444
455
target_ref_id,
445
456
CommitFlags :: Integrated ,
@@ -466,7 +477,7 @@ impl Graph {
466
477
// have to adjust the existing queue item.
467
478
existing_segment
468
479
} else {
469
- let extra_target_sidx = graph. insert_root ( branch_segment_from_name_and_meta (
480
+ let extra_target_sidx = graph. insert_segment ( branch_segment_from_name_and_meta (
470
481
None ,
471
482
meta,
472
483
Some ( ( & ctx. refs_by_id , extra_target) ) ,
@@ -515,7 +526,7 @@ impl Graph {
515
526
meta,
516
527
Some ( ( & ctx. refs_by_id , segment_tip. detach ( ) ) ) ,
517
528
) ?;
518
- let segment = graph. insert_root ( segment) ;
529
+ let segment = graph. insert_segment ( segment) ;
519
530
_ = next. push_back_exhausted ( (
520
531
segment_tip. detach ( ) ,
521
532
CommitFlags :: NotInRemote ,
0 commit comments