mirror of
https://github.com/nushell/nushell.git
synced 2025-06-19 17:38:14 +02:00
(gstat): add config option to disable tag calculation (#15893)
<!-- if this PR closes one or more issues, you can automatically link the PR with them by using one of the [*linking keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword), e.g. - this PR should close #xxxx - fixes #xxxx you can also mention related issues, PRs or discussions! --> # Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> Fixes #15884. Adds `--disable-tag` flag to the `gstat` plugin that disables expensive calculations. Instead `gstat` reports `no_tag`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking 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.
This commit is contained in:
parent
42fc9f52a1
commit
74e0e4f092
@ -21,6 +21,7 @@ impl GStat {
|
|||||||
value: &Value,
|
value: &Value,
|
||||||
current_dir: &str,
|
current_dir: &str,
|
||||||
path: Option<Spanned<String>>,
|
path: Option<Spanned<String>>,
|
||||||
|
calculate_tag: bool,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Result<Value, LabeledError> {
|
) -> Result<Value, LabeledError> {
|
||||||
// use std::any::Any;
|
// use std::any::Any;
|
||||||
@ -92,14 +93,14 @@ impl GStat {
|
|||||||
.map(|p| p.to_string_lossy().to_string())
|
.map(|p| p.to_string_lossy().to_string())
|
||||||
.unwrap_or_else(|| "".to_string());
|
.unwrap_or_else(|| "".to_string());
|
||||||
|
|
||||||
let mut desc_opts = DescribeOptions::new();
|
let tag = calculate_tag
|
||||||
desc_opts.describe_tags();
|
.then(|| {
|
||||||
|
let mut desc_opts = DescribeOptions::new();
|
||||||
let tag = if let Ok(Ok(s)) = repo.describe(&desc_opts).map(|d| d.format(None)) {
|
desc_opts.describe_tags();
|
||||||
s
|
repo.describe(&desc_opts).ok()?.format(None).ok()
|
||||||
} else {
|
})
|
||||||
"no_tag".to_string()
|
.flatten()
|
||||||
};
|
.unwrap_or_else(|| "no_tag".to_string());
|
||||||
|
|
||||||
// Leave this in case we want to turn it into a table instead of a list
|
// Leave this in case we want to turn it into a table instead of a list
|
||||||
// Ok(Value::List {
|
// Ok(Value::List {
|
||||||
|
@ -27,6 +27,7 @@ impl SimplePluginCommand for GStat {
|
|||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build(PluginCommand::name(self))
|
Signature::build(PluginCommand::name(self))
|
||||||
|
.switch("no-tag", "Disable git tag resolving", None)
|
||||||
.optional("path", SyntaxShape::Filepath, "path to repo")
|
.optional("path", SyntaxShape::Filepath, "path to repo")
|
||||||
.category(Category::Custom("prompt".to_string()))
|
.category(Category::Custom("prompt".to_string()))
|
||||||
}
|
}
|
||||||
@ -41,6 +42,8 @@ impl SimplePluginCommand for GStat {
|
|||||||
let repo_path: Option<Spanned<String>> = call.opt(0)?;
|
let repo_path: Option<Spanned<String>> = call.opt(0)?;
|
||||||
// eprintln!("input value: {:#?}", &input);
|
// eprintln!("input value: {:#?}", &input);
|
||||||
let current_dir = engine.get_current_dir()?;
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user