Skip to content

Commit

Permalink
feat!: Make realpath() easier to use by introducing realpath_opt().
Browse files Browse the repository at this point in the history
That way there is consistency about how many symlinks to follow.
  • Loading branch information
Byron committed May 28, 2022
1 parent e521d39 commit 266d437
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion git-config/src/file/resolve_includes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn is_match(
if !result {
if let Some(target_config_path) = target_config_path {
if let Ok(expanded_git_dir_value) =
git_path::realpath(git_path::from_byte_slice(&git_dir_value), target_config_path, 32)
git_path::realpath(git_path::from_byte_slice(&git_dir_value), target_config_path)
{
let git_dir_value = git_path::into_bstr(expanded_git_dir_value).replace("\\", "/");
dbg!(&condition_path.as_bstr(), git_dir_value.as_bstr(),);
Expand Down
2 changes: 1 addition & 1 deletion git-discover/src/upwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn parse_ceiling_dirs(ceiling_dirs: &[u8]) -> Vec<PathBuf> {
}

if should_normalize {
if let Ok(normalized) = git_path::realpath(&dir, "", 32) {
if let Ok(normalized) = git_path::realpath(&dir, "") {
dir = Cow::Owned(normalized);
}
}
Expand Down
4 changes: 2 additions & 2 deletions git-discover/tests/upwards/ceiling_dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn no_matching_ceiling_dirs_errors_by_default() -> crate::Result {
fn ceilings_are_adjusted_to_match_search_dir() -> crate::Result {
let relative_work_dir = repo_path()?;
let cwd = std::env::current_dir()?;
let absolute_ceiling_dir = git_path::realpath(&relative_work_dir, &cwd, 8)?;
let absolute_ceiling_dir = git_path::realpath_opts(&relative_work_dir, &cwd, 8)?;
let dir = relative_work_dir.join("some");
assert!(dir.is_relative());
let (repo_path, _trust) = git_discover::upwards_opts(
Expand All @@ -152,7 +152,7 @@ fn ceilings_are_adjusted_to_match_search_dir() -> crate::Result {
assert_repo_is_current_workdir(repo_path, &relative_work_dir);

assert!(relative_work_dir.is_relative());
let absolute_dir = git_path::realpath(relative_work_dir.join("some"), cwd, 8)?;
let absolute_dir = git_path::realpath_opts(relative_work_dir.join("some"), cwd, 8)?;
let (repo_path, _trust) = git_discover::upwards_opts(
absolute_dir,
Options {
Expand Down
2 changes: 1 addition & 1 deletion git-path/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use tempfile::tempdir_in;

///
pub mod realpath;
pub use realpath::function::realpath;
pub use realpath::function::{realpath, realpath_opts};

pub fn create_symlink(from: &Path, to: &Path) {
create_dir_all(from.parent().unwrap()).unwrap();
Expand Down
12 changes: 10 additions & 2 deletions git-path/src/realpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ pub(crate) mod function {
use std::path::Component::{CurDir, Normal, ParentDir, Prefix, RootDir};
use std::path::{Path, PathBuf};

/// TODO
pub fn realpath(path: impl AsRef<Path>, cwd: impl AsRef<Path>, max_symlinks: u8) -> Result<PathBuf, Error> {
// TODO
#[allow(missing_docs)]
pub fn realpath(path: impl AsRef<Path>, cwd: impl AsRef<Path>) -> Result<PathBuf, Error> {
let git_default = 32;
realpath_opts(path, cwd, git_default)
}

// TODO
#[allow(missing_docs)]
pub fn realpath_opts(path: impl AsRef<Path>, cwd: impl AsRef<Path>, max_symlinks: u8) -> Result<PathBuf, Error> {
let path = path.as_ref();
if path.as_os_str().is_empty() {
return Err(Error::EmptyPath);
Expand Down
2 changes: 1 addition & 1 deletion git-repository/src/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl ReplacementObjects {
}
}

/// The options used in [`Repository::open_opts
/// The options used in [`Repository::open_opts`]
#[derive(Default, Clone)]
pub struct Options {
object_store_slots: git_odb::store::init::Slots,
Expand Down
2 changes: 1 addition & 1 deletion git-sec/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod impl_ {
// Ignore errors here and just do the regular checks below
if std::env::current_dir()
.ok()
.and_then(|cwd| git_path::realpath(path, cwd, 8).ok())
.and_then(|cwd| git_path::realpath(path, cwd).ok())
== dirs::home_dir()
{
return Ok(true);
Expand Down

0 comments on commit 266d437

Please sign in to comment.