From df716888c9a15e9a1cd3b4dcb4bd64ff17ebc3a9 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 4 Oct 2023 00:07:45 +0900 Subject: [PATCH] cli: reorder working-copy commit lookup bits in finish_transaction() Just to make the next commit look slightly nicer. tx.mut_repo() is no longer assigned to local variable to narrow scope of mutable borrow. --- cli/src/cli_util.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index b4da16cab..7723749bb 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -1440,31 +1440,30 @@ See https://github.com/martinvonz/jj/blob/main/docs/working-copy.md#stale-workin } fn finish_transaction(&mut self, ui: &mut Ui, mut tx: Transaction) -> Result<(), CommandError> { - let mut_repo = tx.mut_repo(); - let store = mut_repo.store().clone(); - if !mut_repo.has_changes() { + if !tx.mut_repo().has_changes() { writeln!(ui, "Nothing changed.")?; return Ok(()); } - let num_rebased = mut_repo.rebase_descendants(&self.settings)?; + let num_rebased = tx.mut_repo().rebase_descendants(&self.settings)?; if num_rebased > 0 { writeln!(ui, "Rebased {num_rebased} descendant commits")?; } - if self.working_copy_shared_with_git { - let git_repo = self.git_backend().unwrap().open_git_repo()?; - self.export_head_to_git(mut_repo, &git_repo)?; - let failed_branches = git::export_refs(mut_repo, &git_repo)?; - print_failed_git_export(ui, &failed_branches)?; - } - let maybe_old_commit = tx + + let maybe_old_wc_commit = tx .base_repo() .view() .get_wc_commit_id(self.workspace_id()) - .map(|commit_id| store.get_commit(commit_id)) + .map(|commit_id| tx.base_repo().store().get_commit(commit_id)) .transpose()?; + if self.working_copy_shared_with_git { + let git_repo = self.git_backend().unwrap().open_git_repo()?; + self.export_head_to_git(tx.mut_repo(), &git_repo)?; + let failed_branches = git::export_refs(tx.mut_repo(), &git_repo)?; + print_failed_git_export(ui, &failed_branches)?; + } self.user_repo = ReadonlyUserRepo::new(tx.commit()); if self.may_update_working_copy { - self.update_working_copy(ui, maybe_old_commit.as_ref())?; + self.update_working_copy(ui, maybe_old_wc_commit.as_ref())?; } let settings = &self.settings; if settings.user_name().is_empty() || settings.user_email().is_empty() {