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

cleanup: avoid some unnecessary uses of mutable repo reference

This commit is contained in:
Martin von Zweigbergk 2024-09-06 09:20:24 -07:00 committed by Martin von Zweigbergk
parent 5bae3eaa74
commit 5fbc819fc1
7 changed files with 16 additions and 20 deletions

View file

@ -698,7 +698,7 @@ impl WorkspaceCommandHelper {
let command = self.command.clone(); let command = self.command.clone();
let mut tx = self.start_transaction(); let mut tx = self.start_transaction();
git::import_head(tx.mut_repo())?; git::import_head(tx.mut_repo())?;
if !tx.mut_repo().has_changes() { if !tx.repo().has_changes() {
return Ok(()); return Ok(());
} }
@ -714,10 +714,10 @@ impl WorkspaceCommandHelper {
let mut tx = tx.into_inner(); let mut tx = tx.into_inner();
let old_git_head = self.repo().view().git_head().clone(); let old_git_head = self.repo().view().git_head().clone();
let new_git_head = tx.mut_repo().view().git_head().clone(); let new_git_head = tx.repo().view().git_head().clone();
if let Some(new_git_head_id) = new_git_head.as_normal() { if let Some(new_git_head_id) = new_git_head.as_normal() {
let workspace_id = self.workspace_id().to_owned(); let workspace_id = self.workspace_id().to_owned();
let new_git_head_commit = tx.mut_repo().store().get_commit(new_git_head_id)?; let new_git_head_commit = tx.repo().store().get_commit(new_git_head_id)?;
tx.mut_repo() tx.mut_repo()
.check_out(workspace_id, command.settings(), &new_git_head_commit)?; .check_out(workspace_id, command.settings(), &new_git_head_commit)?;
let mut locked_ws = self.workspace.start_working_copy_mutation()?; let mut locked_ws = self.workspace.start_working_copy_mutation()?;
@ -759,7 +759,7 @@ impl WorkspaceCommandHelper {
let stats = git::import_some_refs(tx.mut_repo(), &git_settings, |ref_name| { let stats = git::import_some_refs(tx.mut_repo(), &git_settings, |ref_name| {
!git::is_reserved_git_remote_ref(ref_name) !git::is_reserved_git_remote_ref(ref_name)
})?; })?;
if !tx.mut_repo().has_changes() { if !tx.repo().has_changes() {
return Ok(()); return Ok(());
} }
@ -1463,7 +1463,7 @@ See https://martinvonz.github.io/jj/latest/working-copy/#stale-working-copy \
mut tx: Transaction, mut tx: Transaction,
description: impl Into<String>, description: impl Into<String>,
) -> Result<(), CommandError> { ) -> Result<(), CommandError> {
if !tx.mut_repo().has_changes() { if !tx.repo().has_changes() {
writeln!(ui.status(), "Nothing changed.")?; writeln!(ui.status(), "Nothing changed.")?;
return Ok(()); return Ok(());
} }
@ -1472,8 +1472,7 @@ See https://martinvonz.github.io/jj/latest/working-copy/#stale-working-copy \
writeln!(ui.status(), "Rebased {num_rebased} descendant commits")?; writeln!(ui.status(), "Rebased {num_rebased} descendant commits")?;
} }
for (workspace_id, wc_commit_id) in for (workspace_id, wc_commit_id) in tx.repo().view().wc_commit_ids().clone().iter().sorted()
tx.mut_repo().view().wc_commit_ids().clone().iter().sorted()
//sorting otherwise non deterministic order (bad for tests) //sorting otherwise non deterministic order (bad for tests)
{ {
if self if self

View file

@ -65,7 +65,7 @@ pub(crate) fn cmd_backout(
to_back_out.len() - 1 to_back_out.len() - 1
) )
}; };
let mut new_base_tree = merge_commit_trees(tx.mut_repo(), &parents)?; let mut new_base_tree = merge_commit_trees(tx.repo(), &parents)?;
for commit_to_back_out in to_back_out { for commit_to_back_out in to_back_out {
let commit_to_back_out_subject = commit_to_back_out let commit_to_back_out_subject = commit_to_back_out
.description() .description()
@ -77,7 +77,7 @@ pub(crate) fn cmd_backout(
commit_to_back_out_subject, commit_to_back_out_subject,
&commit_to_back_out.id().hex() &commit_to_back_out.id().hex()
); );
let old_base_tree = commit_to_back_out.parent_tree(tx.mut_repo())?; let old_base_tree = commit_to_back_out.parent_tree(tx.repo())?;
let old_tree = commit_to_back_out.tree()?; let old_tree = commit_to_back_out.tree()?;
let new_tree = new_base_tree.merge(&old_tree, &old_base_tree)?; let new_tree = new_base_tree.merge(&old_tree, &old_base_tree)?;
let new_parent_ids = parents.iter().map(|commit| commit.id().clone()).collect(); let new_parent_ids = parents.iter().map(|commit| commit.id().clone()).collect();

View file

@ -120,10 +120,7 @@ new working-copy commit.
commit_builder.set_description(description); commit_builder.set_description(description);
let new_commit = commit_builder.write(tx.mut_repo())?; let new_commit = commit_builder.write(tx.mut_repo())?;
let workspace_ids = tx let workspace_ids = tx.repo().view().workspaces_for_wc_commit_id(commit.id());
.mut_repo()
.view()
.workspaces_for_wc_commit_id(commit.id());
if !workspace_ids.is_empty() { if !workspace_ids.is_empty() {
let new_wc_commit = tx let new_wc_commit = tx
.mut_repo() .mut_repo()

View file

@ -175,11 +175,11 @@ pub fn do_init(
if !workspace_command.working_copy_shared_with_git() { if !workspace_command.working_copy_shared_with_git() {
let mut tx = workspace_command.start_transaction(); let mut tx = workspace_command.start_transaction();
jj_lib::git::import_head(tx.mut_repo())?; jj_lib::git::import_head(tx.mut_repo())?;
if let Some(git_head_id) = tx.mut_repo().view().git_head().as_normal().cloned() { if let Some(git_head_id) = tx.repo().view().git_head().as_normal().cloned() {
let git_head_commit = tx.mut_repo().store().get_commit(&git_head_id)?; let git_head_commit = tx.repo().store().get_commit(&git_head_id)?;
tx.check_out(&git_head_commit)?; tx.check_out(&git_head_commit)?;
} }
if tx.mut_repo().has_changes() { if tx.repo().has_changes() {
tx.finish(ui, "import git head")?; tx.finish(ui, "import git head")?;
} }
} }
@ -213,7 +213,7 @@ fn init_git_refs(
// Initial import shouldn't fail because of reserved remote name. // Initial import shouldn't fail because of reserved remote name.
|ref_name| !git::is_reserved_git_remote_ref(ref_name), |ref_name| !git::is_reserved_git_remote_ref(ref_name),
)?; )?;
if !tx.mut_repo().has_changes() { if !tx.repo().has_changes() {
return Ok(repo); return Ok(repo);
} }
print_git_import_stats(ui, tx.repo(), &stats, false)?; print_git_import_stats(ui, tx.repo(), &stats, false)?;

View file

@ -37,7 +37,7 @@ pub fn cmd_git_remote_remove(
let git_repo = get_git_repo(repo.store())?; let git_repo = get_git_repo(repo.store())?;
let mut tx = workspace_command.start_transaction(); let mut tx = workspace_command.start_transaction();
git::remove_remote(tx.mut_repo(), &git_repo, &args.remote)?; git::remove_remote(tx.mut_repo(), &git_repo, &args.remote)?;
if tx.mut_repo().has_changes() { if tx.repo().has_changes() {
tx.finish(ui, format!("remove git remote {}", &args.remote)) tx.finish(ui, format!("remove git remote {}", &args.remote))
} else { } else {
Ok(()) // Do not print "Nothing changed." Ok(()) // Do not print "Nothing changed."

View file

@ -39,7 +39,7 @@ pub fn cmd_git_remote_rename(
let git_repo = get_git_repo(repo.store())?; let git_repo = get_git_repo(repo.store())?;
let mut tx = workspace_command.start_transaction(); let mut tx = workspace_command.start_transaction();
git::rename_remote(tx.mut_repo(), &git_repo, &args.old, &args.new)?; git::rename_remote(tx.mut_repo(), &git_repo, &args.old, &args.new)?;
if tx.mut_repo().has_changes() { if tx.repo().has_changes() {
tx.finish( tx.finish(
ui, ui,
format!("rename git remote {} to {}", &args.old, &args.new), format!("rename git remote {} to {}", &args.old, &args.new),

View file

@ -292,7 +292,7 @@ from the source will be moved into the destination.
// changes will disappear. // changes will disappear.
let rebase_map = tx.mut_repo().rebase_descendants_return_map(settings)?; let rebase_map = tx.mut_repo().rebase_descendants_return_map(settings)?;
let rebased_destination_id = rebase_map.get(destination.id()).unwrap().clone(); let rebased_destination_id = rebase_map.get(destination.id()).unwrap().clone();
rewritten_destination = tx.mut_repo().store().get_commit(&rebased_destination_id)?; rewritten_destination = tx.repo().store().get_commit(&rebased_destination_id)?;
} }
// Apply the selected changes onto the destination // Apply the selected changes onto the destination
let mut destination_tree = rewritten_destination.tree()?; let mut destination_tree = rewritten_destination.tree()?;