@@ -8,6 +8,7 @@ use crate::projection::workspace;
8
8
use crate :: {
9
9
CommitFlags , CommitIndex , Graph , Segment , SegmentIndex ,
10
10
projection:: { Stack , StackCommit , StackCommitFlags , StackSegment } ,
11
+ segment,
11
12
} ;
12
13
use anyhow:: Context ;
13
14
use bstr:: { BStr , ByteSlice } ;
@@ -68,6 +69,17 @@ impl Workspace<'_> {
68
69
. iter ( )
69
70
. all ( |s| s. segments . iter ( ) . all ( |s| !s. is_entrypoint ) )
70
71
}
72
+
73
+ /// Return the `commit` at the tip of the workspace itself, and do so by following empty segments along the
74
+ /// first parent until the first commit is found.
75
+ /// This importantly is different from the [`Graph::lookup_entrypoint()`] `commit`, as the entrypoint could be anywhere
76
+ /// inside the workspace as well.
77
+ ///
78
+ /// Note that this commit could also be the base of the workspace, particularly if there is no commits in the workspace.
79
+ pub fn tip_commit ( & self ) -> Option < & segment:: Commit > {
80
+ self . graph . tip_skip_empty ( self . id )
81
+ }
82
+
71
83
/// Lookup a triple obtained by [`Self::find_owner_indexes_by_commit_id()`] or panic.
72
84
pub fn lookup_commit ( & self , ( stack_idx, seg_idx, cidx) : CommitOwnerIndexes ) -> & StackCommit {
73
85
& self . stacks [ stack_idx] . segments [ seg_idx] . commits [ cidx]
@@ -161,23 +173,28 @@ impl Workspace<'_> {
161
173
self . find_segment_and_stack_by_refname ( name) . is_some ( )
162
174
}
163
175
164
- /// Return `true` if the entrypoint.
176
+ /// Return `true` if `name` is in the ancestry of the workspace entrypoint, and is IN the workspace as well .
165
177
pub fn is_reachable_from_entrypoint ( & self , name : & gix:: refs:: FullNameRef ) -> bool {
178
+ if self . ref_name ( ) . filter ( |_| self . is_entrypoint ( ) ) == Some ( name) {
179
+ return true ;
180
+ }
166
181
if self . is_entrypoint ( ) {
167
182
self . refname_is_segment ( name)
168
183
} else {
169
- let Some ( ( stack, segment_idx) ) = self . stacks . iter ( ) . find_map ( |stack| {
170
- stack
171
- . segments
172
- . iter ( )
173
- . enumerate ( )
174
- . find_map ( |( idx, segment) | segment. is_entrypoint . then_some ( ( stack, idx) ) )
175
- } ) else {
184
+ let Some ( ( entrypoint_stack, entrypoint_segment_idx) ) =
185
+ self . stacks . iter ( ) . find_map ( |stack| {
186
+ stack
187
+ . segments
188
+ . iter ( )
189
+ . enumerate ( )
190
+ . find_map ( |( idx, segment) | segment. is_entrypoint . then_some ( ( stack, idx) ) )
191
+ } )
192
+ else {
176
193
return false ;
177
194
} ;
178
- stack
195
+ entrypoint_stack
179
196
. segments
180
- . get ( segment_idx ..)
197
+ . get ( entrypoint_segment_idx ..)
181
198
. into_iter ( )
182
199
. any ( |segments| {
183
200
segments
0 commit comments