use std::collections::HashMap;
use std::collections::HashSet;
use crate::jj::types::Signature;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SegmentCommit {
pub commit_id: String,
pub change_id: String,
pub description: String,
pub author: Signature,
pub committer: Signature,
pub short_change_id: String,
pub files: Vec<String>,
pub is_immutable: bool,
pub local_bookmark_names: Vec<String>,
pub remote_bookmark_names: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BookmarkSegment {
pub bookmark_names: Vec<String>,
pub change_id: String,
pub commits: Vec<SegmentCommit>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RemoteState {
Unpushed,
Diverged,
Synced,
}
impl RemoteState {
pub fn as_str(self) -> &'static str {
match self {
Self::Unpushed => "unpushed",
Self::Diverged => "diverged",
Self::Synced => "synced",
}
}
}
#[derive(Debug, Clone)]
pub struct BranchStack {
pub segments: Vec<BookmarkSegment>,
}
impl BranchStack {
pub fn commits_trunk_to_tip(&self) -> impl Iterator<Item = &SegmentCommit> {
self.segments
.iter()
.flat_map(|seg| seg.commits.iter().rev())
}
pub fn tip_commit(&self) -> Option<&SegmentCommit> {
self.segments.last().and_then(|seg| seg.commits.first())
}
}
#[derive(Debug)]
pub struct ChangeGraph {
#[cfg_attr(
not(test),
expect(
dead_code,
reason = "the graph-construction tests read it to pin which bookmarked change stacks \
on which"
)
)]
pub adjacency_list: HashMap<String, String>,
#[cfg_attr(
not(test),
expect(
dead_code,
reason = "the graph-construction tests read it to pin which changes end a stack"
)
)]
pub stack_leaves: HashSet<String>,
#[cfg_attr(
not(test),
expect(
dead_code,
reason = "the graph-construction tests read it to pin how commits are grouped into \
per-change segments"
)
)]
pub segments: HashMap<String, BookmarkSegment>,
#[cfg_attr(
not(test),
expect(
dead_code,
reason = "the merge-commit tests read it to pin that taint propagates from a merge to \
its descendants"
)
)]
pub tainted_change_ids: HashSet<String>,
pub bookmark_remote_states: HashMap<String, RemoteState>,
pub excluded_bookmarks: Vec<String>,
pub excluded_head_count: usize,
pub stacks: Vec<BranchStack>,
}