ok/jj
1
0
Fork 0
forked from mirrors/jj

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.
This commit is contained in:
Yuya Nishihara 2024-09-01 13:52:52 +09:00
parent 1b6617bbd7
commit 38bd5fbf32

View file

@ -20,7 +20,6 @@ use std::collections::HashSet;
use std::fmt::Debug; use std::fmt::Debug;
use std::fmt::Formatter; use std::fmt::Formatter;
use std::fs; use std::fs;
use std::iter;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::slice; use std::slice;
@ -57,6 +56,7 @@ use crate::index::IndexStore;
use crate::index::MutableIndex; use crate::index::MutableIndex;
use crate::index::ReadonlyIndex; use crate::index::ReadonlyIndex;
use crate::local_backend::LocalBackend; use crate::local_backend::LocalBackend;
use crate::merge::MergeBuilder;
use crate::object_id::HexPrefix; use crate::object_id::HexPrefix;
use crate::object_id::ObjectId; use crate::object_id::ObjectId;
use crate::object_id::PrefixResolution; use crate::object_id::PrefixResolution;
@ -1115,10 +1115,12 @@ impl MutableRepo {
.collect_vec(); .collect_vec();
for (branch_name, (old_commit_id, new_commit_ids)) in changed_branches { for (branch_name, (old_commit_id, new_commit_ids)) in changed_branches {
let old_target = RefTarget::normal(old_commit_id.clone()); let old_target = RefTarget::normal(old_commit_id.clone());
assert!(!new_commit_ids.is_empty()); let new_target = RefTarget::from_merge(
let new_target = RefTarget::from_legacy_form( MergeBuilder::from_iter(
iter::repeat(old_commit_id.clone()).take(new_commit_ids.len() - 1), itertools::intersperse(new_commit_ids, old_commit_id)
new_commit_ids.iter().cloned(), .map(|id| Some(id.clone())),
)
.build(),
); );
self.merge_local_branch(&branch_name, &old_target, &new_target); self.merge_local_branch(&branch_name, &old_target, &new_target);
} }