-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Create new 'init' top-level module
Over time we've accrued a number of pieces of logic for pieces of global state that needs to be initialized right at the start of execution. These pieces all init-related but scattered around modules in a way that meant more clutter at the top-level of the crate, and a general lack of clarity about how init was done. This refactoring groups all init-related logic under an `init` function in the `init` module, which is just called right at the top of the `main` function. Signed-off-by: Andrew Lilley Brinker <[email protected]>
- Loading branch information
1 parent
7a23a93
commit 1362405
Showing
5 changed files
with
52 additions
and
33 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
hipcheck/src/log_bridge.rs → hipcheck/src/init/indicatif_log_bridge.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
mod git2_log_shim; | ||
mod git2_rustls_transport; | ||
mod indicatif_log_bridge; | ||
|
||
use crate::shell::verbosity::Verbosity; | ||
use crate::shell::Shell; | ||
use env_logger::Env; | ||
use rustls::crypto::ring; | ||
use rustls::crypto::CryptoProvider; | ||
|
||
/// Initialize global state for the program. | ||
/// | ||
/// **NOTE:** The order in which these operations are done is precise, and | ||
/// should not be changed! | ||
pub fn init() { | ||
init_shell(); | ||
init_logging(); | ||
init_libgit2(); | ||
init_cryptography(); | ||
} | ||
|
||
fn init_shell() { | ||
Shell::init(Verbosity::Normal); | ||
} | ||
|
||
fn init_logging() { | ||
let env = Env::new().filter("HC_LOG").write_style("HC_LOG_STYLE"); | ||
let logger = env_logger::Builder::from_env(env).build(); | ||
indicatif_log_bridge::LogWrapper(logger) | ||
.try_init() | ||
.expect("logging initialization must succeed"); | ||
} | ||
|
||
fn init_libgit2() { | ||
// Tell the `git2` crate to pass its tracing messages to the log crate. | ||
git2_log_shim::git2_set_trace_log_shim(); | ||
|
||
// Make libgit2 use a rustls + ureq based transport for executing the git | ||
// protocol over http(s). I would normally just let libgit2 use its own | ||
// implementation but have seen that this rustls/ureq transport is 2-3 times | ||
// faster on my machine — enough of a performance bump to warrant using this. | ||
git2_rustls_transport::register(); | ||
} | ||
|
||
fn init_cryptography() { | ||
// Install a process-wide default crypto provider. | ||
CryptoProvider::install_default(ring::default_provider()) | ||
.expect("installed process-wide default crypto provider"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters