Skip to content

Commit 2d0d19b

Browse files
committed
replace Chunk/Markers with LaneSlot enum
1 parent 62b4e19 commit 2d0d19b

1 file changed

Lines changed: 56 additions & 10 deletions

File tree

asyncgit/src/graph/chunk.rs

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,61 @@
1-
use super::AliasId;
1+
use super::{CommitAlias, UnwalkedAlias};
22

3+
/// A lane's occupant at one point in the walk.
34
#[derive(Clone, Debug, PartialEq, Eq)]
4-
pub enum Markers {
5-
Uncommitted,
6-
Commit,
5+
pub enum LaneSlot {
6+
/// A walked commit flowing down to its first parent.
7+
Flowing {
8+
alias: CommitAlias,
9+
parent: UnwalkedAlias,
10+
},
11+
12+
/// A flowing lane that still owes a bridge to a second parent
13+
FlowingMerge {
14+
alias: CommitAlias,
15+
parent: UnwalkedAlias,
16+
second: UnwalkedAlias,
17+
},
18+
19+
/// A root commit: draws its node, nothing continues below.
20+
Settled { alias: CommitAlias },
21+
22+
/// Reserved for a merge's second parent that hasn't been reached
23+
/// by the walk yet. Once that parent is processed, the
24+
/// reservation is replaced by the parent's own slot.
25+
Reserved { parent: UnwalkedAlias },
726
}
827

9-
#[derive(Clone, Debug, PartialEq, Eq)]
10-
pub struct Chunk {
11-
pub alias: Option<AliasId>,
12-
pub parent_a: Option<AliasId>,
13-
pub parent_b: Option<AliasId>,
14-
pub marker: Markers,
28+
impl LaneSlot {
29+
/// The commit this lane currently belongs to, `None` for a
30+
/// reserved placeholder.
31+
pub const fn alias(&self) -> Option<CommitAlias> {
32+
match self {
33+
Self::Flowing { alias, .. }
34+
| Self::FlowingMerge { alias, .. }
35+
| Self::Settled { alias } => Some(*alias),
36+
Self::Reserved { .. } => None,
37+
}
38+
}
39+
40+
/// The parent whose placement this lane waits on; the lane stays
41+
/// open (drawing a vertical line) until that commit is walked.
42+
pub const fn awaits(&self) -> Option<CommitAlias> {
43+
match self {
44+
Self::Flowing { parent, .. }
45+
| Self::FlowingMerge { parent, .. }
46+
| Self::Reserved { parent } => Some(parent.get()),
47+
Self::Settled { .. } => None,
48+
}
49+
}
50+
51+
/// The pending second parent of a merge that hasn't been given
52+
/// its own lane.
53+
pub const fn second(&self) -> Option<CommitAlias> {
54+
match self {
55+
Self::FlowingMerge { second, .. } => Some(second.get()),
56+
Self::Flowing { .. }
57+
| Self::Settled { .. }
58+
| Self::Reserved { .. } => None,
59+
}
60+
}
1561
}

0 commit comments

Comments
 (0)