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

commands: use MutableRepo directly more, starting with update_checkout_after_rewrite()

`Transaction` has a bunch of functions that are now simple
delegates. It probably makes sense to directly use a `&mut
MutableRepo` instead of `&mut Transaction` in most places. This patch
starts that migration.
This commit is contained in:
Martin von Zweigbergk 2021-03-16 15:22:49 -07:00
parent ee8423a69e
commit ddee2e04b1

View file

@ -37,7 +37,7 @@ use jujube_lib::git::GitFetchError;
use jujube_lib::index::{HexPrefix, PrefixResolution}; use jujube_lib::index::{HexPrefix, PrefixResolution};
use jujube_lib::op_store::{OpStore, OpStoreError, OperationId}; use jujube_lib::op_store::{OpStore, OpStoreError, OperationId};
use jujube_lib::operation::Operation; use jujube_lib::operation::Operation;
use jujube_lib::repo::{ReadonlyRepo, RepoLoadError, RepoLoader}; use jujube_lib::repo::{MutableRepo, ReadonlyRepo, RepoLoadError, RepoLoader};
use jujube_lib::repo_path::RepoPath; use jujube_lib::repo_path::RepoPath;
use jujube_lib::rewrite::{back_out_commit, merge_commit_trees, rebase_commit}; use jujube_lib::rewrite::{back_out_commit, merge_commit_trees, rebase_commit};
use jujube_lib::settings::UserSettings; use jujube_lib::settings::UserSettings;
@ -255,16 +255,18 @@ fn update_working_copy(
Ok(Some(stats)) Ok(Some(stats))
} }
fn update_checkout_after_rewrite(ui: &mut Ui, tx: &mut Transaction) { fn update_checkout_after_rewrite(ui: &mut Ui, mut_repo: &mut MutableRepo) {
// TODO: Perhaps this method should be in Transaction. // TODO: Perhaps this method should be in MutableRepo.
let new_checkout_candidates = tx.evolution().new_parent(tx.store(), tx.view().checkout()); let new_checkout_candidates = mut_repo
.evolution()
.new_parent(mut_repo.store(), mut_repo.view().checkout());
if new_checkout_candidates.is_empty() { if new_checkout_candidates.is_empty() {
return; return;
} }
// Filter out heads that already existed. // Filter out heads that already existed.
// TODO: Filter out *commits* that already existed (so we get updated to an // TODO: Filter out *commits* that already existed (so we get updated to an
// appropriate new non-head) // appropriate new non-head)
let old_heads = tx.base_repo().view().heads().clone(); let old_heads = mut_repo.base_repo().view().heads().clone();
let new_checkout_candidates: HashSet<_> = new_checkout_candidates let new_checkout_candidates: HashSet<_> = new_checkout_candidates
.difference(&old_heads) .difference(&old_heads)
.cloned() .cloned()
@ -278,8 +280,8 @@ fn update_checkout_after_rewrite(ui: &mut Ui, tx: &mut Transaction) {
); );
} }
let new_checkout = new_checkout_candidates.iter().min().unwrap(); let new_checkout = new_checkout_candidates.iter().min().unwrap();
let new_commit = tx.store().get_commit(new_checkout).unwrap(); let new_commit = mut_repo.store().get_commit(new_checkout).unwrap();
tx.check_out(ui.settings(), &new_commit); mut_repo.check_out(ui.settings(), &new_commit);
} }
fn get_app<'a, 'b>() -> App<'a, 'b> { fn get_app<'a, 'b>() -> App<'a, 'b> {
@ -1214,7 +1216,7 @@ fn cmd_describe(
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit) CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
.set_description(description) .set_description(description)
.write_to_transaction(&mut tx); .write_to_transaction(&mut tx);
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,
@ -1237,7 +1239,7 @@ fn cmd_open(
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit) CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &commit)
.set_open(true) .set_open(true)
.write_to_transaction(&mut tx); .write_to_transaction(&mut tx);
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,
@ -1269,7 +1271,7 @@ fn cmd_close(
commit_builder = commit_builder.set_description(description); commit_builder = commit_builder.set_description(description);
let mut tx = repo.start_transaction(&format!("close commit {}", commit.id().hex())); let mut tx = repo.start_transaction(&format!("close commit {}", commit.id().hex()));
commit_builder.write_to_transaction(&mut tx); commit_builder.write_to_transaction(&mut tx);
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,
@ -1316,7 +1318,7 @@ fn cmd_prune(
CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &predecessor) CommitBuilder::for_rewrite_from(ui.settings(), repo.store(), &predecessor)
.set_pruned(true) .set_pruned(true)
.write_to_transaction(&mut tx); .write_to_transaction(&mut tx);
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,
@ -1388,7 +1390,7 @@ fn cmd_squash(
.set_parents(vec![squashed_commit.id().clone()]) .set_parents(vec![squashed_commit.id().clone()])
.set_pruned(true) .set_pruned(true)
.write_to_transaction(&mut tx); .write_to_transaction(&mut tx);
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,
@ -1470,7 +1472,7 @@ fn cmd_restore(
ui.write("Created "); ui.write("Created ");
ui.write_commit_summary(tx.as_repo_ref(), &new_commit); ui.write_commit_summary(tx.as_repo_ref(), &new_commit);
ui.write("\n"); ui.write("\n");
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,
@ -1502,7 +1504,7 @@ fn cmd_edit(
ui.write("Created "); ui.write("Created ");
ui.write_commit_summary(tx.as_repo_ref(), &new_commit); ui.write_commit_summary(tx.as_repo_ref(), &new_commit);
ui.write("\n"); ui.write("\n");
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,
@ -1547,7 +1549,7 @@ fn cmd_split(
ui.write("Second part: "); ui.write("Second part: ");
ui.write_commit_summary(tx.as_repo_ref(), &second_commit); ui.write_commit_summary(tx.as_repo_ref(), &second_commit);
ui.write("\n"); ui.write("\n");
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,
@ -1592,7 +1594,7 @@ fn cmd_merge(
.set_description(description) .set_description(description)
.set_open(false) .set_open(false)
.write_to_transaction(&mut tx); .write_to_transaction(&mut tx);
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,
@ -1618,7 +1620,7 @@ fn cmd_rebase(
} }
let mut tx = repo.start_transaction(&format!("rebase commit {}", commit_to_rebase.id().hex())); 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(), &mut tx, &commit_to_rebase, &parents);
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,
@ -1647,7 +1649,7 @@ fn cmd_backout(
commit_to_back_out.id().hex() commit_to_back_out.id().hex()
)); ));
back_out_commit(ui.settings(), &mut tx, &commit_to_back_out, &parents); back_out_commit(ui.settings(), &mut tx, &commit_to_back_out, &parents);
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,
@ -1728,7 +1730,7 @@ fn cmd_evolve<'s>(
let mut listener = Listener { ui }; let mut listener = Listener { ui };
let mut tx = repo.start_transaction("evolve"); let mut tx = repo.start_transaction("evolve");
evolve(&user_settings, &mut tx, &mut listener); evolve(&user_settings, &mut tx, &mut listener);
update_checkout_after_rewrite(ui, &mut tx); update_checkout_after_rewrite(ui, tx.mut_repo());
tx.commit(); tx.commit();
update_working_copy( update_working_copy(
ui, ui,