mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 07:46:28 +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,
|
"only_detached": true,
|
||||||
"style": "green bold",
|
"style": "green bold",
|
||||||
"tag_disabled": true,
|
"tag_disabled": true,
|
||||||
|
"tag_max_candidates": 0,
|
||||||
"tag_symbol": " 🏷 "
|
"tag_symbol": " 🏷 "
|
||||||
},
|
},
|
||||||
"allOf": [
|
"allOf": [
|
||||||
@ -2799,6 +2800,12 @@
|
|||||||
"tag_disabled": {
|
"tag_disabled": {
|
||||||
"default": true,
|
"default": true,
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"tag_max_candidates": {
|
||||||
|
"default": 0,
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint",
|
||||||
|
"minimum": 0.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1558,15 +1558,16 @@ The `git_commit` module shows the current commit hash and also the tag (if any)
|
|||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| -------------------- | ------------------------------ | ------------------------------------------------------- |
|
| -------------------- | ------------------------------ | ------------------------------------------------------------------------------------ |
|
||||||
| `commit_hash_length` | `7` | The length of the displayed git commit hash. |
|
| `commit_hash_length` | `7` | The length of the displayed git commit hash. |
|
||||||
| `format` | `"[\\($hash$tag\\)]($style) "` | The format for the module. |
|
| `format` | `"[\\($hash$tag\\)]($style) "` | The format for the module. |
|
||||||
| `style` | `"bold green"` | The style for the module. |
|
| `style` | `"bold green"` | The style for the module. |
|
||||||
| `only_detached` | `true` | Only show git commit hash when in detached `HEAD` state |
|
| `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_disabled` | `true` | Disables showing tag info in `git_commit` module. |
|
||||||
| `tag_symbol` | `" 🏷 "` | Tag symbol prefixing the info shown |
|
| `tag_max_candidates` | `0` | How many commits to consider for tag display. The default only allows exact matches. |
|
||||||
| `disabled` | `false` | Disables the `git_commit` module. |
|
| `tag_symbol` | `" 🏷 "` | Tag symbol prefixing the info shown |
|
||||||
|
| `disabled` | `false` | Disables the `git_commit` module. |
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ pub struct GitCommitConfig<'a> {
|
|||||||
pub disabled: bool,
|
pub disabled: bool,
|
||||||
pub tag_symbol: &'a str,
|
pub tag_symbol: &'a str,
|
||||||
pub tag_disabled: bool,
|
pub tag_disabled: bool,
|
||||||
|
pub tag_max_candidates: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Default for GitCommitConfig<'a> {
|
impl<'a> Default for GitCommitConfig<'a> {
|
||||||
@ -24,6 +25,7 @@ impl<'a> Default for GitCommitConfig<'a> {
|
|||||||
disabled: false,
|
disabled: false,
|
||||||
tag_symbol: " 🏷 ",
|
tag_symbol: " 🏷 ",
|
||||||
tag_disabled: true,
|
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!(
|
"tag" => Some(Ok(format!(
|
||||||
"{}{}",
|
"{}{}",
|
||||||
config.tag_symbol,
|
config.tag_symbol,
|
||||||
git_tag(context.get_repo().ok()?)?
|
git_tag(context.get_repo().ok()?, &config)?
|
||||||
))),
|
))),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
@ -50,13 +50,17 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
Some(module)
|
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
|
// 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();
|
let mut git_repo = repo.open().apply_environment();
|
||||||
git_repo.object_cache_size_if_unset(4 * 1024 * 1024);
|
git_repo.object_cache_size_if_unset(4 * 1024 * 1024);
|
||||||
let head_commit = git_repo.head_commit().ok()?;
|
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()??;
|
let formatter = describe_platform.try_format().ok()??;
|
||||||
|
|
||||||
Some(formatter.name?.to_string())
|
Some(formatter.name?.to_string())
|
||||||
|
Loading…
Reference in New Issue
Block a user