rewrite: take a MutableRepo instead of a Transaction

This commit is contained in:
Martin von Zweigbergk 2021-03-16 15:47:16 -07:00
parent ddee2e04b1
commit c3b9d1cd13
3 changed files with 14 additions and 15 deletions

View file

@ -538,7 +538,7 @@ pub fn evolve(
if ambiguous_new_parents {
listener.orphan_target_ambiguous(tx, &orphan);
} else {
let new_commit = rebase_commit(user_settings, tx, &orphan, &new_parents);
let new_commit = rebase_commit(user_settings, tx.mut_repo(), &orphan, &new_parents);
listener.orphan_evolved(tx, &orphan, &new_commit);
}
}

View file

@ -14,10 +14,9 @@
use crate::commit::Commit;
use crate::commit_builder::CommitBuilder;
use crate::repo::RepoRef;
use crate::repo::{MutableRepo, RepoRef};
use crate::repo_path::DirRepoPath;
use crate::settings::UserSettings;
use crate::transaction::Transaction;
use crate::tree::Tree;
use crate::trees::merge_trees;
@ -45,13 +44,13 @@ pub fn merge_commit_trees(repo: RepoRef, commits: &[Commit]) -> Tree {
pub fn rebase_commit(
settings: &UserSettings,
tx: &mut Transaction,
mut_repo: &mut MutableRepo,
old_commit: &Commit,
new_parents: &[Commit],
) -> Commit {
let store = tx.store();
let old_base_tree = merge_commit_trees(tx.as_repo_ref(), &old_commit.parents());
let new_base_tree = merge_commit_trees(tx.as_repo_ref(), &new_parents);
let store = mut_repo.store();
let old_base_tree = merge_commit_trees(mut_repo.as_repo_ref(), &old_commit.parents());
let new_base_tree = merge_commit_trees(mut_repo.as_repo_ref(), &new_parents);
// TODO: pass in labels for the merge parts
let new_tree_id = merge_trees(&new_base_tree, &old_base_tree, &old_commit.tree()).unwrap();
let new_parent_ids = new_parents
@ -61,18 +60,18 @@ pub fn rebase_commit(
CommitBuilder::for_rewrite_from(settings, store, &old_commit)
.set_parents(new_parent_ids)
.set_tree(new_tree_id)
.write_to_transaction(tx)
.write_to_repo(mut_repo)
}
pub fn back_out_commit(
settings: &UserSettings,
tx: &mut Transaction,
mut_repo: &mut MutableRepo,
old_commit: &Commit,
new_parents: &[Commit],
) -> Commit {
let store = tx.store();
let old_base_tree = merge_commit_trees(tx.as_repo_ref(), &old_commit.parents());
let new_base_tree = merge_commit_trees(tx.as_repo_ref(), &new_parents);
let store = mut_repo.store();
let old_base_tree = merge_commit_trees(mut_repo.as_repo_ref(), &old_commit.parents());
let new_base_tree = merge_commit_trees(mut_repo.as_repo_ref(), &new_parents);
// TODO: pass in labels for the merge parts
let new_tree_id = merge_trees(&new_base_tree, &old_commit.tree(), &old_base_tree).unwrap();
let new_parent_ids = new_parents
@ -86,5 +85,5 @@ pub fn back_out_commit(
"backout of commit {}",
hex::encode(&old_commit.id().0)
))
.write_to_transaction(tx)
.write_to_repo(mut_repo)
}

View file

@ -1619,7 +1619,7 @@ fn cmd_rebase(
parents.push(resolve_single_rev(ui, mut_repo, revision_str)?);
}
let mut tx = repo.start_transaction(&format!("rebase commit {}", commit_to_rebase.id().hex()));
rebase_commit(ui.settings(), &mut tx, &commit_to_rebase, &parents);
rebase_commit(ui.settings(), tx.mut_repo(), &commit_to_rebase, &parents);
update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit();
update_working_copy(
@ -1648,7 +1648,7 @@ fn cmd_backout(
"back out commit {}",
commit_to_back_out.id().hex()
));
back_out_commit(ui.settings(), &mut tx, &commit_to_back_out, &parents);
back_out_commit(ui.settings(), tx.mut_repo(), &commit_to_back_out, &parents);
update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit();
update_working_copy(