Skip to content

Commit 06e96a4

Browse files
committed
refactor
- re-use method name based on similar semantics used elsewhere - cleanup EnvironmentOverrides::from_env
1 parent b555bda commit 06e96a4

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

git-discover/src/upwards.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ impl Default for Options {
6565

6666
impl Options {
6767
/// Loads discovery options overrides from the environment.
68+
///
6869
/// The environment variables are:
6970
/// - `GIT_CEILING_DIRECTORIES` for `ceiling_dirs`
7071
/// - `GIT_DISCOVERY_ACROSS_FILESYSTEM` for `cross_fs`
7172
// TODO: test
72-
pub fn load_env_overrides(&mut self) {
73+
pub fn apply_environment(&mut self) {
7374
/// Gets the values of an environment variable as bytes.
7475
fn get_env_bytes(name: &str) -> Option<Vec<u8>> {
7576
env::var_os(name).and_then(|c| Vec::from_os_string(c).ok())

git-repository/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ pub mod discover {
421421
Self::discover_with_environment_overrides_opts(directory, Default::default(), Default::default())
422422
}
423423

424-
/// Try to open a git repository directly from the environment.
425-
/// If that fails, discover upwards from `directory` until one is found,
424+
/// Try to open a git repository directly from the environment, which reads `GIT_DIR`
425+
/// if it is set. If unset, discover upwards from `directory` until one is found,
426426
/// while applying `options` with overrides from the environment.
427427
///
428428
/// Then use the `trust_map` to determine which of our own repository options to use.
@@ -434,7 +434,7 @@ pub mod discover {
434434
if std::env::var_os("GIT_DIR").is_some() {
435435
return Self::open_with_environment_overrides(directory.as_ref(), trust_map).map_err(Error::Open);
436436
}
437-
options.load_env_overrides();
437+
options.apply_environment();
438438
Self::discover_opts(directory, options, trust_map)
439439
}
440440
}

git-repository/src/open.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,14 @@ pub(crate) struct EnvironmentOverrides {
8282
}
8383

8484
impl EnvironmentOverrides {
85-
// TODO: tests
86-
fn from_env(
87-
git_prefix: crate::permission::env_var::Resource,
88-
) -> Result<Self, crate::permission::env_var::resource::Error> {
85+
fn from_env() -> Result<Self, crate::permission::env_var::resource::Error> {
8986
let mut worktree_dir = None;
9087
if let Some(path) = std::env::var_os("GIT_WORK_TREE") {
91-
worktree_dir = git_prefix.check(PathBuf::from(path))?;
88+
worktree_dir = PathBuf::from(path).into();
9289
}
9390
let mut git_dir = None;
9491
if let Some(path) = std::env::var_os("GIT_DIR") {
95-
git_dir = git_prefix.check(PathBuf::from(path))?;
92+
git_dir = PathBuf::from(path).into();
9693
}
9794
Ok(EnvironmentOverrides { worktree_dir, git_dir })
9895
}
@@ -198,7 +195,7 @@ impl crate::ThreadSafeRepository {
198195
fallback_directory: impl Into<PathBuf>,
199196
trust_map: git_sec::trust::Mapping<Options>,
200197
) -> Result<Self, Error> {
201-
let overrides = EnvironmentOverrides::from_env(git_sec::Access::resource(git_sec::Permission::Allow))?;
198+
let overrides = EnvironmentOverrides::from_env()?;
202199
let (path, path_kind): (PathBuf, _) = match overrides.git_dir {
203200
Some(git_dir) => git_discover::is_git(&git_dir).map(|kind| (git_dir, kind))?,
204201
None => {

0 commit comments

Comments
 (0)