Skip to content

Commit

Permalink
Enforce path conversion on windows gnu, it doesn't seem to like slash…
Browse files Browse the repository at this point in the history
…es (#298)
  • Loading branch information
Byron committed Apr 6, 2022
1 parent 9a06fe1 commit 4d55a8f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
17 changes: 17 additions & 0 deletions git-features/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ pub mod convert {
p
}

/// Convert paths with slashes to backslashes on windows and do nothing on unix.
pub fn to_windows_separators_on_windows_or_panic<'a>(path: &std::path::Path) -> Cow<'_, std::path::Path> {
#[cfg(not(windows))]
{
path.into()
}
#[cfg(windows)]
{
crate::path::from_byte_slice_or_panic_on_windows(
crate::path::convert::to_windows_separators(crate::path::into_bytes_or_panic_on_windows(path.as_ref()))
.as_ref(),
)
.to_owned()
.into()
}
}

/// Replaces windows path separators with slashes.
pub fn to_unix_separators<'a>(path: impl Into<Cow<'a, [u8]>>) -> Cow<'a, [u8]> {
replace(path, b'\\', b'/')
Expand Down
9 changes: 5 additions & 4 deletions git-ref/src/store/file/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl file::Store {
packed: Option<&packed::Buffer>,
transform: Transform,
) -> Result<Option<Reference>, Error> {
let (base, is_definitely_absolute) = match transform {
let (base, is_definitely_full_path) = match transform {
Transform::EnforceRefsPrefix => (
if relative_path.starts_with("refs") {
PathBuf::new()
Expand All @@ -124,14 +124,15 @@ impl file::Store {
};
let relative_path = base.join(inbetween).join(relative_path);

let path_to_open = git_features::path::convert::to_windows_separators_on_windows_or_panic(&relative_path);
let contents = match self
.ref_contents(&relative_path)
.ref_contents(&path_to_open)
.map_err(|err| Error::ReadFileContents {
err,
path: relative_path.to_owned(),
path: path_to_open.into_owned(),
})? {
None => {
if is_definitely_absolute {
if is_definitely_full_path {
if let Some(packed) = packed {
let full_name = path_to_name(match &self.namespace {
None => relative_path,
Expand Down
3 changes: 0 additions & 3 deletions git-ref/src/store/file/loose/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ impl Iterator for SortedLoosePaths {
};

if git_validate::reference::name_partial(full_name.as_bstr()).is_ok() {
#[cfg(not(windows))]
let name = FullName(full_name.into());
#[cfg(windows)]
let name = FullName(full_name.into());
return Some(Ok((full_path, name)));
} else {
Expand Down

0 comments on commit 4d55a8f

Please sign in to comment.