Attempt to merge a conflict group using token-level semantics. # Algorithm 1. Extract the two competing vertices (only 2-way supported). 2. Retrieve content bytes for both from the [`ChangeStore`]. 3. Find the common ancestor vertex — the dead vertex that both competing changes deleted. 4. Retrieve content bytes for the ancestor. 5. Tokenize all three byte sequences. 6. Run a three-way diff at t
(&self, group: &ConflictGroup)
| 128 | /// Returns [`SemanticMergeError`] when pristine graph access, ID mapping, |
| 129 | /// or change content retrieval fails. |
| 130 | pub fn try_merge(&self, group: &ConflictGroup) -> Result<MergeOutcome, SemanticMergeError> { |
| 131 | // ── Step 1: Read content for every vertex in the group ──────── |
| 132 | let mut vertex_contents: Vec<(GraphNode<NodeId>, Vec<u8>)> = Vec::new(); |
| 133 | for v in &group.vertices { |
| 134 | vertex_contents.push((*v, self.get_vertex_content(v)?)); |
| 135 | } |
| 136 | if vertex_contents.is_empty() { |
| 137 | return Ok(MergeOutcome::NoCrdtData); |
| 138 | } |
| 139 | |
| 140 | // ── Step 2: Deduplicate identical-content vertices ──────────── |
| 141 | // |
| 142 | // Collapse vertices that share byte-identical content into a |
| 143 | // single representative. This handles the common N-way fork |
| 144 | // where multiple concurrent changes insert the same whitespace |
| 145 | // or the same boilerplate line. Indices of surviving (unique) |
| 146 | // vertices are collected in `unique`; everything else lands in |
| 147 | // `skipped` so the caller can mark them. |
| 148 | let mut unique: Vec<usize> = vec![0]; |
| 149 | let mut skipped: Vec<usize> = Vec::new(); |
| 150 | for i in 1..vertex_contents.len() { |
| 151 | if unique |
| 152 | .iter() |
| 153 | .any(|&j| vertex_contents[j].1 == vertex_contents[i].1) |
| 154 | { |
| 155 | skipped.push(i); |
| 156 | } else { |
| 157 | unique.push(i); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | // All vertices identical — no conflict at all. |
| 162 | if unique.len() == 1 && !skipped.is_empty() { |
| 163 | log::info!( |
| 164 | "try_merge: all {} vertices identical ({} bytes), deduplicating", |
| 165 | vertex_contents.len(), |
| 166 | vertex_contents[0].1.len(), |
| 167 | ); |
| 168 | return Ok(MergeOutcome::AutoMerged { |
| 169 | content: vertex_contents[0].1.clone(), |
| 170 | sources: vec![MergeSource::new(vertex_contents[0].0.change, 0)], |
| 171 | }); |
| 172 | } |
| 173 | |
| 174 | // Partial dedup: log, but continue with the unique subset. |
| 175 | if !skipped.is_empty() { |
| 176 | log::info!( |
| 177 | "try_merge: dedup reduced {}-way fork to {}-way", |
| 178 | vertex_contents.len(), |
| 179 | unique.len(), |
| 180 | ); |
| 181 | } |
| 182 | |
| 183 | // After dedup we need exactly 2 unique sides for the merge |
| 184 | // pipeline below. If there are still >2 unique sides, return |
| 185 | // NoCrdtData and let the caller emit markers for what remains. |
| 186 | if unique.len() != 2 { |
| 187 | log::debug!( |