From 38bd5fbf32a7a2f9cb69e215291939b37ac8b81e Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 1 Sep 2024 13:52:52 +0900 Subject: [PATCH] rewrite: use intersperse() to interleave new/old commit ids This is stricter than from_legacy_from() in that wrong number of add/remove terms will panic. --- lib/src/repo.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index 9f87bdb5e..2819398f9 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -20,7 +20,6 @@ use std::collections::HashSet; use std::fmt::Debug; use std::fmt::Formatter; use std::fs; -use std::iter; use std::path::Path; use std::path::PathBuf; use std::slice; @@ -57,6 +56,7 @@ use crate::index::IndexStore; use crate::index::MutableIndex; use crate::index::ReadonlyIndex; use crate::local_backend::LocalBackend; +use crate::merge::MergeBuilder; use crate::object_id::HexPrefix; use crate::object_id::ObjectId; use crate::object_id::PrefixResolution; @@ -1115,10 +1115,12 @@ impl MutableRepo { .collect_vec(); for (branch_name, (old_commit_id, new_commit_ids)) in changed_branches { let old_target = RefTarget::normal(old_commit_id.clone()); - assert!(!new_commit_ids.is_empty()); - let new_target = RefTarget::from_legacy_form( - iter::repeat(old_commit_id.clone()).take(new_commit_ids.len() - 1), - new_commit_ids.iter().cloned(), + let new_target = RefTarget::from_merge( + MergeBuilder::from_iter( + itertools::intersperse(new_commit_ids, old_commit_id) + .map(|id| Some(id.clone())), + ) + .build(), ); self.merge_local_branch(&branch_name, &old_target, &new_target); }