git_stack/legacy/graph/
node.rs

1use std::collections::BTreeSet;
2
3#[derive(Clone, Debug, PartialEq, Eq)]
4pub struct Node {
5    pub commit: std::rc::Rc<crate::legacy::git::Commit>,
6    pub branches: Vec<crate::legacy::git::Branch>,
7    pub action: crate::legacy::graph::Action,
8    pub pushable: bool,
9    pub children: BTreeSet<git2::Oid>,
10}
11
12impl Node {
13    pub fn new(commit: std::rc::Rc<crate::legacy::git::Commit>) -> Self {
14        let branches = Vec::new();
15        let children = BTreeSet::new();
16        Self {
17            commit,
18            branches,
19            action: crate::legacy::graph::Action::Pick,
20            pushable: false,
21            children,
22        }
23    }
24
25    pub fn with_branches(mut self, possible_branches: &mut crate::legacy::git::Branches) -> Self {
26        self.branches = possible_branches.remove(self.commit.id).unwrap_or_default();
27        self
28    }
29
30    pub fn update(&mut self, mut other: Self) {
31        assert_eq!(self.commit.id, other.commit.id);
32
33        let mut branches = Vec::new();
34        std::mem::swap(&mut other.branches, &mut branches);
35        self.branches.extend(branches);
36
37        if other.action != crate::legacy::graph::Action::Pick {
38            self.action = other.action;
39        }
40
41        if other.pushable {
42            self.pushable = true;
43        }
44
45        self.children.extend(other.children);
46    }
47}