1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use super::policy::BranchKind;
use super::time::Timestamp;
use crate::ids::ShardId;
use crate::tree::Hash;
/// One shard's entry in a branch ref record: where the branch diverged and
/// where its committed head currently is.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BranchShardRef {
/// Shard this entry pins roots for.
pub shard_id: ShardId,
/// Divergence point used as the three-way-merge ancestor. It is immutable
/// for the branch's durable lifetime.
pub fork_anchor: Hash,
/// Current committed root for this shard.
pub head: Hash,
}
/// Durable truth for one named branch.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BranchRefRecord {
/// Full branch name (the on-disk file name is only its hash).
pub name: String,
/// Creation identity, immutable for this branch generation.
pub created: Timestamp,
/// Immutable branch kind. Pre-marker records decode as [`BranchKind::Work`].
pub kind: BranchKind,
/// Namespace lineage inherited by a Work branch at fork time.
///
/// Namespace records resolve to their own name and store `None` here. A
/// directly-created or legacy Work branch has no namespace lineage.
pub namespace_lineage: Option<String>,
/// Durable commit sequence; `0` means created and never committed.
pub seq: u64,
/// When this record was installed, in caller-supplied nanoseconds.
pub timestamp: Timestamp,
/// Per-shard anchor/head pairs, strictly ascending by shard id.
pub shards: Vec<BranchShardRef>,
/// Tree roots of this head commit's parents.
pub parents: Vec<Hash>,
}
impl BranchRefRecord {
/// Resolves the namespace boundary from durable record state only.
#[must_use]
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub fn resolved_namespace_lineage(&self) -> Option<&str> {
match self.kind {
BranchKind::Namespace => Some(&self.name),
BranchKind::Work => self.namespace_lineage.as_deref(),
}
}
}