@@ -246,9 +246,11 @@ pub mod ui {
246246 /// Read-only metadata with additional information about the branch naming the segment,
247247 /// or `None` if nothing was present.
248248 pub metadata : Option < ref_metadata:: Branch > ,
249- /// This is `true` for exactly one segment in a workspace if the entrypoint of [the traversal](Graph::from_commit_traversal())
249+ /// This is `true` a segment in a workspace if the entrypoint of [the traversal](Graph::from_commit_traversal())
250250 /// is this segment, and the surrounding workspace is provided for context.
251+ ///
251252 /// This means one will see the entire workspace, while knowing the focus is on one specific segment.
253+ /// *Note* that this segment can be listed in *multiple stacks* as it's reachable from multiple 'ahead' segments.
252254 pub is_entrypoint : bool ,
253255 }
254256
@@ -272,7 +274,7 @@ pub mod ui {
272274 is_entrypoint,
273275 } = self ;
274276 f. debug_struct ( & format ! (
275- "{ep}StackSegment " ,
277+ "{ep}ref_info::ui::Segment " ,
276278 ep = if * is_entrypoint { "👉" } else { "" }
277279 ) )
278280 . field ( "id" , & id)
@@ -365,7 +367,8 @@ pub(crate) mod function {
365367 stash_status: None ,
366368 } ] ,
367369 is_entrypoint : true ,
368- is_managed,
370+ is_managed_ref : is_managed,
371+ is_managed_commit : false ,
369372 } ) ;
370373 }
371374 gix:: head:: Kind :: Detached { .. } => {
@@ -374,7 +377,8 @@ pub(crate) mod function {
374377 stacks : vec ! [ ] ,
375378 target_ref : None ,
376379 is_entrypoint : true ,
377- is_managed : false ,
380+ is_managed_ref : false ,
381+ is_managed_commit : false ,
378382 } ) ;
379383 }
380384 gix:: head:: Kind :: Symbolic ( name) => name. attach ( repo) ,
@@ -438,13 +442,28 @@ pub(crate) mod function {
438442 let cache = repo. commit_graph_if_enabled ( ) ?;
439443 let mut graph_cache = repo. revision_graph ( cache. as_ref ( ) ) ;
440444
445+ let ( workspace_ref_name, is_managed_commit) = match head {
446+ HeadLocation :: Workspace { ref_name } => {
447+ let is_managed = try_refname_to_id ( repo, ref_name. as_ref ( ) ) ?
448+ . map ( |id| WorkspaceCommit :: from_id ( id. attach ( repo) ) )
449+ . transpose ( ) ?
450+ . is_some_and ( |wsc| wsc. is_managed ( ) ) ;
451+ ( Some ( ref_name) , is_managed)
452+ }
453+ HeadLocation :: Segment { segment_index } => {
454+ ( graph[ segment_index] . ref_name . clone ( ) , false )
455+ }
456+ } ;
441457 Ok ( RefInfo {
442- workspace_ref_name : match head {
443- HeadLocation :: Workspace { ref_name } => Some ( ref_name) ,
444- HeadLocation :: Segment { segment_index } => graph[ segment_index] . ref_name . clone ( ) ,
445- } ,
458+ workspace_ref_name,
446459 stacks : stacks
447460 . into_iter ( )
461+ // `but-graph` produces the order as seen by the merge commit,
462+ // but GB traditionally shows it the other way around.
463+ // TODO: validate that this is still correct to do here if the workspace
464+ // was generated from 'virtual' stacks only, i.e. stacks not from real
465+ // merges.
466+ . rev ( )
448467 . map ( |stack| {
449468 branch:: Stack :: try_from_graph_stack (
450469 stack,
@@ -458,7 +477,8 @@ pub(crate) mod function {
458477 } )
459478 . collect :: < anyhow:: Result < _ > > ( ) ?,
460479 target_ref : target. map ( |t| t. ref_name ) ,
461- is_managed : metadata. is_some ( ) ,
480+ is_managed_ref : metadata. is_some ( ) ,
481+ is_managed_commit,
462482 is_entrypoint : graph. lookup_entrypoint ( ) ?. segment_index == id,
463483 } )
464484 }
@@ -928,7 +948,8 @@ pub(crate) mod function {
928948 stacks,
929949 target_ref,
930950 is_entrypoint : false ,
931- is_managed,
951+ is_managed_commit : false ,
952+ is_managed_ref : is_managed,
932953 } )
933954 }
934955
0 commit comments