Skip to content

Commit

Permalink
fix merge logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Jan 5, 2024
1 parent db7220e commit 721635d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 9 additions & 8 deletions helix-core/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl History {
/// E -> F
/// ```
pub fn merge(&mut self, mut other: History) -> anyhow::Result<()> {
let after_n = self
let n = self
.revisions
.iter()
.zip(other.revisions.iter())
Expand All @@ -275,14 +275,15 @@ impl History {
})
.count();

let revisions = self.revisions.split_off(after_n);
other.revisions.reserve_exact(revisions.len());
let new_revs = self.revisions.split_off(n);
if new_revs.is_empty() {
return Ok(());
}

// Converts the number of new elements to an index offset
let offset = (other.revisions.len() - after_n) - 1;
for mut r in revisions {
// Update parents of new revisions
if r.parent >= after_n {
// Only unique revisions in `self` matter, so saturating_sub(1) is sound as it going to 0 means there are no new revisions in the other history that aren't in `self`
let offset = (other.revisions.len() - n).saturating_sub(1);
for mut r in new_revs {
if r.parent >= n {
r.parent += offset;
}
debug_assert!(r.parent < other.revisions.len());
Expand Down
4 changes: 1 addition & 3 deletions helix-core/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,7 @@ impl ChangeSet {
macro_rules! map {
($map: expr, $i: expr) => {
loop {
let Some((pos, assoc)) = positions.peek_mut() else {
return;
};
let Some((pos, assoc)) = positions.peek_mut() else { return; };
if **pos < old_pos {
// Positions are not sorted, revert to the last Operation that
// contains this position and continue iterating from there.
Expand Down

0 comments on commit 721635d

Please sign in to comment.