cli: make squash and unsquash commands record abandoned commits

This change makes `jj squash` and `jj unsquash` record the child or
parent (respectively) as abandoned if it becomes empty. We need to do
that because it won't get automatically recorded by
`CommitBuilder`. We could make `CommitBuilder` record abandoned
commits when `set_pruned()` was called, but that would be
short-sighted since we're about to delete that function as part of
removing support for evolution (#32).
This commit is contained in:
Martin von Zweigbergk 2021-09-29 15:30:33 -07:00
parent 76352564ad
commit 6949dab389

View file

@ -2323,6 +2323,9 @@ from the source will be moved into the parent.
.set_parents(vec![new_parent.id().clone()])
.set_pruned(abandon_child)
.write_to_repo(mut_repo);
if abandon_child {
mut_repo.record_abandoned_commit(commit.id().clone());
}
repo_command.finish_transaction(ui, tx)?;
Ok(())
}
@ -2380,10 +2383,18 @@ aborted.
.set_predecessors(vec![parent.id().clone(), commit.id().clone()])
.set_pruned(abandon_parent)
.write_to_repo(mut_repo);
// Commit the new child on top of the new parent.
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
.set_parents(vec![new_parent.id().clone()])
.write_to_repo(mut_repo);
if abandon_parent {
mut_repo.record_abandoned_commit(parent.id().clone());
// Commit the new child on top of the parent's parents.
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
.set_parents(parent.parent_ids())
.write_to_repo(mut_repo);
} else {
// Commit the new child on top of the new parent.
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
.set_parents(vec![new_parent.id().clone()])
.write_to_repo(mut_repo);
}
repo_command.finish_transaction(ui, tx)?;
Ok(())
}