mirror of
https://github.com/starship/starship.git
synced 2026-06-24 02:01:36 +07:00
fix: Lazy load git repo and only run module if not disabled (#306)
A couple of optimizations are done in this PR. One, we now will check config ahead of time to see if a module is disabled before running any module code. Also, we won't try to discover a git repository unless the module requests access to it.
This commit is contained in:
committed by
Matan Kushner
parent
dc8409333e
commit
9f70ffb7a7
@@ -30,11 +30,12 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
const GIT_STATUS_RENAMED: &str = "»";
|
||||
const GIT_STATUS_DELETED: &str = "✘";
|
||||
|
||||
let branch_name = context.branch_name.as_ref()?;
|
||||
let repo_root = context.repo_root.as_ref()?;
|
||||
let repo = context.get_repo().ok()?;
|
||||
let branch_name = repo.branch.as_ref()?;
|
||||
let repo_root = repo.root.as_ref()?;
|
||||
let repository = Repository::open(repo_root).ok()?;
|
||||
|
||||
let mut module = context.new_module("git_status")?;
|
||||
let mut module = context.new_module("git_status");
|
||||
let show_sync_count = module.config_value_bool("show_sync_count").unwrap_or(false);
|
||||
let module_style = module
|
||||
.config_value_style("style")
|
||||
@@ -133,10 +134,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
}
|
||||
|
||||
if module.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(module)
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(module)
|
||||
}
|
||||
|
||||
/// Gets the bitflags associated with the repo's git status
|
||||
|
||||
Reference in New Issue
Block a user