From 650c1f6521f37d408e36744e5f4da41391e3ddc7 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 11 Jan 2024 19:46:57 +0900 Subject: [PATCH] cli: inline CommandHelper::workspace_helper_internal() The control flow is pretty simple. We don't need a inner function that implements the both. --- cli/src/cli_util.rs | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index f93c17758..18a46bfd7 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -591,31 +591,25 @@ impl CommandHelper { self.maybe_workspace_loader.as_ref().map_err(Clone::clone) } + /// Loads workspace and repo, then snapshots the working copy if allowed. #[instrument(skip(self, ui))] - fn workspace_helper_internal( - &self, - ui: &mut Ui, - snapshot: bool, - ) -> Result { - let workspace = self.load_workspace()?; - let op_head = self.resolve_operation(ui, workspace.repo_loader())?; - let repo = workspace.repo_loader().load_at(&op_head)?; - let mut workspace_command = self.for_loaded_repo(ui, workspace, repo)?; - if snapshot { - workspace_command.snapshot(ui)?; - } + pub fn workspace_helper(&self, ui: &mut Ui) -> Result { + let mut workspace_command = self.workspace_helper_no_snapshot(ui)?; + workspace_command.snapshot(ui)?; Ok(workspace_command) } - pub fn workspace_helper(&self, ui: &mut Ui) -> Result { - self.workspace_helper_internal(ui, true) - } - + /// Loads workspace and repo, but never snapshots the working copy. Most + /// commands should use `workspace_helper()` instead. + #[instrument(skip(self, ui))] pub fn workspace_helper_no_snapshot( &self, ui: &mut Ui, ) -> Result { - self.workspace_helper_internal(ui, false) + let workspace = self.load_workspace()?; + let op_head = self.resolve_operation(ui, workspace.repo_loader())?; + let repo = workspace.repo_loader().load_at(&op_head)?; + self.for_loaded_repo(ui, workspace, repo) } #[instrument(skip_all)]