@@ -36,6 +36,7 @@ pub struct Overlay {
3636 overriding_references : Vec < gix:: refs:: Reference > ,
3737 meta_branches : Vec < ( gix:: refs:: FullName , ref_metadata:: Branch ) > ,
3838 workspace : Option < ( gix:: refs:: FullName , ref_metadata:: Workspace ) > ,
39+ skip_out_of_workspace_stack_tracking_once : bool ,
3940}
4041
4142pub ( super ) type PetGraph = petgraph:: stable_graph:: StableGraph < Segment , Edge > ;
@@ -81,6 +82,12 @@ pub struct Options {
8182 /// the workspace.
8283 /// Typically, it's a past position of an existing target, or a target chosen by the user.
8384 pub extra_target_commit_id : Option < gix:: ObjectId > ,
85+ /// If `true`, we will not be able to find stacks that have advanced outside the workspace, along with their out-of-workspace commits.
86+ ///
87+ /// This is useful if you want to check for the presence of stacks in the workspace, for the purpose of adding them if they are not.
88+ /// Otherwise, if `false`, otherwise anonymous segments might appear like they are part of a stack, one that is known in the workspace
89+ /// metadata and reachable towards the descendants of these anonymous stacks.
90+ pub skip_out_of_workspace_stack_tracking : bool ,
8491 /// Enabling this will prevent the postprocessing step to run which is what makes the graph useful through clean-up
8592 /// and to make it more amenable to a workspace project.
8693 ///
@@ -155,7 +162,8 @@ impl Graph {
155162 let mut graph = Graph :: default ( ) ;
156163 // It's OK to default-initialise this here as overlays are only used when redoing
157164 // the traversal.
158- let ( _repo, meta, _entrypoint) = Overlay :: default ( ) . into_parts ( repo, meta) ;
165+ let ( _repo, meta, _entrypoint, _skip_stack_tracking) =
166+ Overlay :: default ( ) . into_parts ( repo, meta) ;
159167 let wt_by_branch = {
160168 // Assume linked worktrees are never unborn!
161169 let mut m = BTreeMap :: new ( ) ;
@@ -249,7 +257,8 @@ impl Graph {
249257 meta : & impl RefMetadata ,
250258 options : Options ,
251259 ) -> anyhow:: Result < Self > {
252- let ( repo, meta, _entrypoint) = Overlay :: default ( ) . into_parts ( tip. repo , meta) ;
260+ let ( repo, meta, _entrypoint, _skip_stack_tracking) =
261+ Overlay :: default ( ) . into_parts ( tip. repo , meta) ;
253262 Graph :: from_commit_traversal_inner ( tip. detach ( ) , & repo, ref_name. into ( ) , & meta, options)
254263 }
255264
@@ -277,6 +286,7 @@ impl Graph {
277286 commits_limit_hint : limit,
278287 commits_limit_recharge_location : mut max_commits_recharge_location,
279288 hard_limit,
289+ skip_out_of_workspace_stack_tracking : _,
280290 dangerously_skip_postprocessing_for_debugging,
281291 } = options;
282292
@@ -752,7 +762,8 @@ impl Graph {
752762 meta : & impl RefMetadata ,
753763 overlay : Overlay ,
754764 ) -> anyhow:: Result < Self > {
755- let ( repo, meta, entrypoint) = overlay. into_parts ( repo, meta) ;
765+ let ( repo, meta, entrypoint, skip_out_of_workspace_stack_tracking_once) =
766+ overlay. into_parts ( repo, meta) ;
756767 let ( tip, ref_name) = match entrypoint {
757768 Some ( t) => t,
758769 None => {
@@ -768,7 +779,15 @@ impl Graph {
768779 ( tip, ref_name)
769780 }
770781 } ;
771- Graph :: from_commit_traversal_inner ( tip, & repo, ref_name, & meta, self . options . clone ( ) )
782+ let mut opts = self . options . clone ( ) ;
783+ if skip_out_of_workspace_stack_tracking_once {
784+ opts. skip_out_of_workspace_stack_tracking = true ;
785+ }
786+ let mut graph = Graph :: from_commit_traversal_inner ( tip, & repo, ref_name, & meta, opts) ?;
787+ if skip_out_of_workspace_stack_tracking_once {
788+ graph. options . skip_out_of_workspace_stack_tracking = false ;
789+ }
790+ Ok ( graph)
772791 }
773792
774793 /// Like [`Self::redo_traversal_with_overlay()`], but replaces this instance, without overlay, and returns
0 commit comments