From 5fbc819fc1b0a78ba06f34d0cbc8c4bb19dd590e Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 6 Sep 2024 09:20:24 -0700 Subject: [PATCH] cleanup: avoid some unnecessary uses of mutable repo reference --- cli/src/cli_util.rs | 13 ++++++------- cli/src/commands/backout.rs | 4 ++-- cli/src/commands/commit.rs | 5 +---- cli/src/commands/git/init.rs | 8 ++++---- cli/src/commands/git/remote/remove.rs | 2 +- cli/src/commands/git/remote/rename.rs | 2 +- cli/src/commands/squash.rs | 2 +- 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 4122a024f..9753ef44a 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -698,7 +698,7 @@ impl WorkspaceCommandHelper { let command = self.command.clone(); let mut tx = self.start_transaction(); git::import_head(tx.mut_repo())?; - if !tx.mut_repo().has_changes() { + if !tx.repo().has_changes() { return Ok(()); } @@ -714,10 +714,10 @@ impl WorkspaceCommandHelper { let mut tx = tx.into_inner(); 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() { 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() .check_out(workspace_id, command.settings(), &new_git_head_commit)?; 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| { !git::is_reserved_git_remote_ref(ref_name) })?; - if !tx.mut_repo().has_changes() { + if !tx.repo().has_changes() { return Ok(()); } @@ -1463,7 +1463,7 @@ See https://martinvonz.github.io/jj/latest/working-copy/#stale-working-copy \ mut tx: Transaction, description: impl Into, ) -> Result<(), CommandError> { - if !tx.mut_repo().has_changes() { + if !tx.repo().has_changes() { writeln!(ui.status(), "Nothing changed.")?; 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")?; } - for (workspace_id, wc_commit_id) in - tx.mut_repo().view().wc_commit_ids().clone().iter().sorted() + for (workspace_id, wc_commit_id) in tx.repo().view().wc_commit_ids().clone().iter().sorted() //sorting otherwise non deterministic order (bad for tests) { if self diff --git a/cli/src/commands/backout.rs b/cli/src/commands/backout.rs index 32c531d25..50ebdb0ba 100644 --- a/cli/src/commands/backout.rs +++ b/cli/src/commands/backout.rs @@ -65,7 +65,7 @@ pub(crate) fn cmd_backout( 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 { let commit_to_back_out_subject = commit_to_back_out .description() @@ -77,7 +77,7 @@ pub(crate) fn cmd_backout( commit_to_back_out_subject, &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 new_tree = new_base_tree.merge(&old_tree, &old_base_tree)?; let new_parent_ids = parents.iter().map(|commit| commit.id().clone()).collect(); diff --git a/cli/src/commands/commit.rs b/cli/src/commands/commit.rs index f810440c1..fb8c86625 100644 --- a/cli/src/commands/commit.rs +++ b/cli/src/commands/commit.rs @@ -120,10 +120,7 @@ new working-copy commit. commit_builder.set_description(description); let new_commit = commit_builder.write(tx.mut_repo())?; - let workspace_ids = tx - .mut_repo() - .view() - .workspaces_for_wc_commit_id(commit.id()); + let workspace_ids = tx.repo().view().workspaces_for_wc_commit_id(commit.id()); if !workspace_ids.is_empty() { let new_wc_commit = tx .mut_repo() diff --git a/cli/src/commands/git/init.rs b/cli/src/commands/git/init.rs index 824802c1a..9a1f79eca 100644 --- a/cli/src/commands/git/init.rs +++ b/cli/src/commands/git/init.rs @@ -175,11 +175,11 @@ pub fn do_init( if !workspace_command.working_copy_shared_with_git() { let mut tx = workspace_command.start_transaction(); jj_lib::git::import_head(tx.mut_repo())?; - if let Some(git_head_id) = tx.mut_repo().view().git_head().as_normal().cloned() { - let git_head_commit = tx.mut_repo().store().get_commit(&git_head_id)?; + if let Some(git_head_id) = tx.repo().view().git_head().as_normal().cloned() { + let git_head_commit = tx.repo().store().get_commit(&git_head_id)?; tx.check_out(&git_head_commit)?; } - if tx.mut_repo().has_changes() { + if tx.repo().has_changes() { tx.finish(ui, "import git head")?; } } @@ -213,7 +213,7 @@ fn init_git_refs( // Initial import shouldn't fail because of reserved remote 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); } print_git_import_stats(ui, tx.repo(), &stats, false)?; diff --git a/cli/src/commands/git/remote/remove.rs b/cli/src/commands/git/remote/remove.rs index 7a0125d7a..234e93cc8 100644 --- a/cli/src/commands/git/remote/remove.rs +++ b/cli/src/commands/git/remote/remove.rs @@ -37,7 +37,7 @@ pub fn cmd_git_remote_remove( let git_repo = get_git_repo(repo.store())?; let mut tx = workspace_command.start_transaction(); 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)) } else { Ok(()) // Do not print "Nothing changed." diff --git a/cli/src/commands/git/remote/rename.rs b/cli/src/commands/git/remote/rename.rs index b02534062..163c7af32 100644 --- a/cli/src/commands/git/remote/rename.rs +++ b/cli/src/commands/git/remote/rename.rs @@ -39,7 +39,7 @@ pub fn cmd_git_remote_rename( let git_repo = get_git_repo(repo.store())?; let mut tx = workspace_command.start_transaction(); 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( ui, format!("rename git remote {} to {}", &args.old, &args.new), diff --git a/cli/src/commands/squash.rs b/cli/src/commands/squash.rs index cd4135177..2f1881030 100644 --- a/cli/src/commands/squash.rs +++ b/cli/src/commands/squash.rs @@ -292,7 +292,7 @@ from the source will be moved into the destination. // changes will disappear. let rebase_map = tx.mut_repo().rebase_descendants_return_map(settings)?; 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 let mut destination_tree = rewritten_destination.tree()?;