From 6fcd3b3af60cbcbc941b3f84fc2f5f0dea695a43 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 16 Jan 2022 17:35:16 -0800 Subject: [PATCH] cli: avoid an unnecessary read of the working copy commit --- src/commands.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 11cfcc7f9..55e8fe8a3 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -690,12 +690,13 @@ fn update_working_copy( wc: &mut WorkingCopy, ) -> Result, CommandError> { let old_commit_id = wc.current_commit_id(); - let new_commit = repo.store().get_commit(repo.view().checkout()).unwrap(); - if *new_commit.id() == old_commit_id { + let new_commit_id = repo.view().checkout(); + if *new_commit_id == old_commit_id { return Ok(None); } // TODO: CheckoutError::ConcurrentCheckout should probably just result in a // warning for most commands (but be an error for the checkout command) + let new_commit = repo.store().get_commit(new_commit_id).unwrap(); let stats = wc.check_out(new_commit.clone()).map_err(|err| { CommandError::InternalError(format!( "Failed to check out commit {}: {}",