mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-24 13:47:38 +00:00
perf(git_commit): only use exact match for tag by default (#4281)
This commit is contained in:
parent
56f8c0be7c
commit
5984f0829e
7
.github/config-schema.json
vendored
7
.github/config-schema.json
vendored
@ -525,6 +525,7 @@
|
||||
"only_detached": true,
|
||||
"style": "green bold",
|
||||
"tag_disabled": true,
|
||||
"tag_max_candidates": 0,
|
||||
"tag_symbol": " 🏷 "
|
||||
},
|
||||
"allOf": [
|
||||
@ -2799,6 +2800,12 @@
|
||||
"tag_disabled": {
|
||||
"default": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"tag_max_candidates": {
|
||||
"default": 0,
|
||||
"type": "integer",
|
||||
"format": "uint",
|
||||
"minimum": 0.0
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1559,12 +1559,13 @@ The `git_commit` module shows the current commit hash and also the tag (if any)
|
||||
### Options
|
||||
|
||||
| Option | Default | Description |
|
||||
| -------------------- | ------------------------------ | ------------------------------------------------------- |
|
||||
| -------------------- | ------------------------------ | ------------------------------------------------------------------------------------ |
|
||||
| `commit_hash_length` | `7` | The length of the displayed git commit hash. |
|
||||
| `format` | `"[\\($hash$tag\\)]($style) "` | The format for the module. |
|
||||
| `style` | `"bold green"` | The style for the module. |
|
||||
| `only_detached` | `true` | Only show git commit hash when in detached `HEAD` state |
|
||||
| `tag_disabled` | `true` | Disables showing tag info in `git_commit` module. |
|
||||
| `tag_max_candidates` | `0` | How many commits to consider for tag display. The default only allows exact matches. |
|
||||
| `tag_symbol` | `" 🏷 "` | Tag symbol prefixing the info shown |
|
||||
| `disabled` | `false` | Disables the `git_commit` module. |
|
||||
|
||||
|
@ -11,6 +11,7 @@ pub struct GitCommitConfig<'a> {
|
||||
pub disabled: bool,
|
||||
pub tag_symbol: &'a str,
|
||||
pub tag_disabled: bool,
|
||||
pub tag_max_candidates: usize,
|
||||
}
|
||||
|
||||
impl<'a> Default for GitCommitConfig<'a> {
|
||||
@ -24,6 +25,7 @@ impl<'a> Default for GitCommitConfig<'a> {
|
||||
disabled: false,
|
||||
tag_symbol: " 🏷 ",
|
||||
tag_disabled: true,
|
||||
tag_max_candidates: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
"tag" => Some(Ok(format!(
|
||||
"{}{}",
|
||||
config.tag_symbol,
|
||||
git_tag(context.get_repo().ok()?)?
|
||||
git_tag(context.get_repo().ok()?, &config)?
|
||||
))),
|
||||
_ => None,
|
||||
})
|
||||
@ -50,13 +50,17 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
Some(module)
|
||||
}
|
||||
|
||||
fn git_tag(repo: &Repo) -> Option<String> {
|
||||
fn git_tag(repo: &Repo, config: &GitCommitConfig) -> Option<String> {
|
||||
// allow environment variables like GITOXIDE_OBJECT_CACHE_MEMORY and GITOXIDE_DISABLE_PACK_CACHE to speed up operation for some repos
|
||||
let mut git_repo = repo.open().apply_environment();
|
||||
git_repo.object_cache_size_if_unset(4 * 1024 * 1024);
|
||||
let head_commit = git_repo.head_commit().ok()?;
|
||||
|
||||
let describe_platform = head_commit.describe().names(AnnotatedTags);
|
||||
let describe_platform = head_commit
|
||||
.describe()
|
||||
.names(AnnotatedTags)
|
||||
.max_candidates(config.tag_max_candidates)
|
||||
.traverse_first_parent(true);
|
||||
let formatter = describe_platform.try_format().ok()??;
|
||||
|
||||
Some(formatter.name?.to_string())
|
||||
|
Loading…
Reference in New Issue
Block a user