diff --git a/src/cli_util.rs b/src/cli_util.rs index 18d532e1f..d64a293b5 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -1037,8 +1037,9 @@ impl WorkspaceCommandHelper { let mut locked_wc = self.workspace.working_copy_mut().start_mutation(); let old_op_id = locked_wc.old_operation_id().clone(); let wc_commit = repo.store().get_commit(&wc_commit_id)?; - let repo = match check_stale_working_copy(&locked_wc, &wc_commit, repo.clone()) { - Ok(repo) => repo, + let repo = match check_stale_working_copy(&locked_wc, &wc_commit, &repo) { + Ok(None) => repo, + Ok(Some(wc_operation)) => repo.reload_at(&wc_operation), Err(StaleWorkingCopyError::WorkingCopyStale) => { locked_wc.discard(); return Err(user_error_with_hint( @@ -1430,12 +1431,13 @@ pub enum StaleWorkingCopyError { pub fn check_stale_working_copy( locked_wc: &LockedWorkingCopy, wc_commit: &Commit, - repo: Arc, -) -> Result, StaleWorkingCopyError> { + repo: &ReadonlyRepo, +) -> Result, StaleWorkingCopyError> { // Check if the working copy's tree matches the repo's view let wc_tree_id = locked_wc.old_tree_id().clone(); if *wc_commit.tree_id() == wc_tree_id { - Ok(repo) + // The working copy isn't stale, and no need to reload the repo. + Ok(None) } else { let wc_operation_data = repo .op_store() @@ -1455,9 +1457,9 @@ pub fn check_stale_working_copy( ); if let Some(ancestor_op) = maybe_ancestor_op { if ancestor_op.id() == repo_operation.id() { - // The working copy was updated since we loaded the repo. We reload the repo - // at the working copy's operation. - Ok(repo.reload_at(&wc_operation)) + // The working copy was updated since we loaded the repo. The repo must be + // reloaded at the working copy's operation. + Ok(Some(wc_operation)) } else if ancestor_op.id() == wc_operation.id() { // The working copy was not updated when some repo operation committed, // meaning that it's stale compared to the repo view. diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 1a71b2307..331478bb6 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -3436,7 +3436,7 @@ fn cmd_workspace_update_stale( let repo = workspace_command.repo().clone(); let (mut locked_wc, desired_wc_commit) = workspace_command.unsafe_start_working_copy_mutation()?; - match check_stale_working_copy(&locked_wc, &desired_wc_commit, repo.clone()) { + match check_stale_working_copy(&locked_wc, &desired_wc_commit, &repo) { Ok(_) => { locked_wc.discard(); ui.write("Nothing to do (the working copy is not stale).\n")?;