From 74e0e4f092aff8184f2b5cef14236327db5f2241 Mon Sep 17 00:00:00 2001 From: Dominik Pilipczuk <63516830+snickerdoodle2@users.noreply.github.com> Date: Thu, 5 Jun 2025 00:28:02 +0200 Subject: [PATCH] (gstat): add config option to disable tag calculation (#15893) # Description Fixes #15884. Adds `--disable-tag` flag to the `gstat` plugin that disables expensive calculations. Instead `gstat` reports `no_tag`. # User-Facing Changes There is no change in behaviour if the flag is not provided. If the flag is provided, it will behave like there is no tags in the repo, so no existing config will break. --- crates/nu_plugin_gstat/src/gstat.rs | 17 +++++++++-------- crates/nu_plugin_gstat/src/nu/mod.rs | 5 ++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/nu_plugin_gstat/src/gstat.rs b/crates/nu_plugin_gstat/src/gstat.rs index 92c2bc45ed..496032a293 100644 --- a/crates/nu_plugin_gstat/src/gstat.rs +++ b/crates/nu_plugin_gstat/src/gstat.rs @@ -21,6 +21,7 @@ impl GStat { value: &Value, current_dir: &str, path: Option>, + calculate_tag: bool, span: Span, ) -> Result { // use std::any::Any; @@ -92,14 +93,14 @@ impl GStat { .map(|p| p.to_string_lossy().to_string()) .unwrap_or_else(|| "".to_string()); - let mut desc_opts = DescribeOptions::new(); - desc_opts.describe_tags(); - - let tag = if let Ok(Ok(s)) = repo.describe(&desc_opts).map(|d| d.format(None)) { - s - } else { - "no_tag".to_string() - }; + let tag = calculate_tag + .then(|| { + let mut desc_opts = DescribeOptions::new(); + desc_opts.describe_tags(); + repo.describe(&desc_opts).ok()?.format(None).ok() + }) + .flatten() + .unwrap_or_else(|| "no_tag".to_string()); // Leave this in case we want to turn it into a table instead of a list // Ok(Value::List { diff --git a/crates/nu_plugin_gstat/src/nu/mod.rs b/crates/nu_plugin_gstat/src/nu/mod.rs index e89112c878..6e09f468f0 100644 --- a/crates/nu_plugin_gstat/src/nu/mod.rs +++ b/crates/nu_plugin_gstat/src/nu/mod.rs @@ -27,6 +27,7 @@ impl SimplePluginCommand for GStat { fn signature(&self) -> Signature { Signature::build(PluginCommand::name(self)) + .switch("no-tag", "Disable git tag resolving", None) .optional("path", SyntaxShape::Filepath, "path to repo") .category(Category::Custom("prompt".to_string())) } @@ -41,6 +42,8 @@ impl SimplePluginCommand for GStat { let repo_path: Option> = call.opt(0)?; // eprintln!("input value: {:#?}", &input); let current_dir = engine.get_current_dir()?; - self.gstat(input, ¤t_dir, repo_path, call.head) + let disable_tag = call.has_flag("no-tag")?; + + self.gstat(input, ¤t_dir, repo_path, !disable_tag, call.head) } }