mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 23:23:20 +00:00
rewrite: extract compute_commits_heads
function
This will be shared between `move_commits` and the new `duplicate_commits` function to be added.
This commit is contained in:
parent
43169680ce
commit
0a7f6bd8aa
1 changed files with 27 additions and 15 deletions
|
@ -587,21 +587,7 @@ pub fn move_commits(
|
|||
let new_children_parents: HashMap<_, _> = if !new_children.is_empty() {
|
||||
// Compute the heads of the target set, which will be used as the parents of
|
||||
// `new_children`.
|
||||
let mut target_heads: HashSet<CommitId> = HashSet::new();
|
||||
for commit in connected_target_commits.iter().rev() {
|
||||
target_heads.insert(commit.id().clone());
|
||||
for old_parent in commit.parent_ids() {
|
||||
target_heads.remove(old_parent);
|
||||
}
|
||||
}
|
||||
let target_heads = connected_target_commits
|
||||
.iter()
|
||||
.rev()
|
||||
.filter(|commit| {
|
||||
target_heads.contains(commit.id()) && target_commit_ids.contains(commit.id())
|
||||
})
|
||||
.map(|commit| commit.id().clone())
|
||||
.collect_vec();
|
||||
let target_heads = compute_commits_heads(&target_commit_ids, &connected_target_commits);
|
||||
|
||||
new_children
|
||||
.iter()
|
||||
|
@ -824,6 +810,32 @@ fn compute_internal_parents_within(
|
|||
internal_parents
|
||||
}
|
||||
|
||||
/// Computes the heads of commits in the target set, given the list of
|
||||
/// `target_commit_ids` and a connected graph of commits.
|
||||
///
|
||||
/// `connected_target_commits` should be in reverse topological order (children
|
||||
/// before parents).
|
||||
fn compute_commits_heads(
|
||||
target_commit_ids: &HashSet<CommitId>,
|
||||
connected_target_commits: &[Commit],
|
||||
) -> Vec<CommitId> {
|
||||
let mut target_head_ids: HashSet<CommitId> = HashSet::new();
|
||||
for commit in connected_target_commits.iter().rev() {
|
||||
target_head_ids.insert(commit.id().clone());
|
||||
for old_parent in commit.parent_ids() {
|
||||
target_head_ids.remove(old_parent);
|
||||
}
|
||||
}
|
||||
connected_target_commits
|
||||
.iter()
|
||||
.rev()
|
||||
.filter(|commit| {
|
||||
target_head_ids.contains(commit.id()) && target_commit_ids.contains(commit.id())
|
||||
})
|
||||
.map(|commit| commit.id().clone())
|
||||
.collect_vec()
|
||||
}
|
||||
|
||||
pub struct CommitToSquash {
|
||||
pub commit: Commit,
|
||||
pub selected_tree: MergedTree,
|
||||
|
|
Loading…
Reference in a new issue