MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / put_branch

Method put_branch

atomic-core/tests/crdt_integration_test.rs:126–146  ·  view source on GitHub ↗
(
        &mut self,
        branch: &Branch,
        after: Option<BranchId>,
    )

Source from the content-addressed store, hash-verified

124 }
125
126 fn put_branch(
127 &mut self,
128 branch: &Branch,
129 after: Option<BranchId>,
130 ) -> Result<bool, Self::Error> {
131 let id = branch.id();
132 let is_new = !self.branches.contains_key(&id);
133 self.branches.insert(id, branch.clone());
134
135 let branches = self.trunk_branches.entry(branch.trunk()).or_default();
136 if let Some(after_id) = after {
137 if let Some(pos) = branches.iter().position(|b| *b == after_id) {
138 branches.insert(pos + 1, id);
139 } else {
140 branches.push(id);
141 }
142 } else {
143 branches.insert(0, id);
144 }
145 Ok(is_new)
146 }
147
148 fn get_branch(&self, id: BranchId) -> Result<Option<Branch>, Self::Error> {
149 Ok(self.branches.get(&id).cloned())

Callers

nothing calls this directly

Calls 8

contains_keyMethod · 0.80
idMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45
trunkMethod · 0.45
positionMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected