Skip to content

Commit 57eeb14

Browse files
committed
Use git_features path methods.
1 parent 6857563 commit 57eeb14

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ include = ["src/**/*", "LICENSE-*", "README.md", "CHANGELOG.md"]
1414
# serde = ["serde_crate"]
1515

1616
[dependencies]
17+
git-features = { version = "^0.19.1", path = "../git-features", features = ["walkdir", "bstr"]}
1718
dirs = "4"
1819
nom = { version = "7", default_features = false, features = [ "std" ] }
1920
memchr = "2"

git-config/src/values.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,20 @@ impl Path<'_> {
307307
const PREFIX: &[u8] = b"%(prefix)/";
308308
const SLASH: u8 = b'/';
309309
if val.starts_with(PREFIX) {
310-
let mut expanded = git_install_dir.ok_or(())?.to_str().ok_or(())?.as_bytes().to_owned();
310+
let mut expanded = git_features::path::into_bytes(git_install_dir.ok_or(())?)
311+
.ok_or(())?
312+
.into_owned();
311313
let (_prefix, val) = val.split_at(PREFIX.len() - 1);
312314
expanded.extend(val);
313315
Ok(Path {
314316
value: Cow::Owned(expanded),
315317
})
316318
} else if val.starts_with(b"~/") {
317-
let home = dirs::home_dir().ok_or(())?.to_str().ok_or(())?.to_owned();
318-
#[cfg(target_os = "windows")]
319-
let mut home = home.replace("\\", "/");
320-
let mut expanded = home.as_bytes().to_owned();
319+
let mut expanded = dirs::home_dir().ok_or(())?.to_str().ok_or(())?.as_bytes().to_owned();
321320
let (_prefix, val) = val.split_at(SLASH.len());
322321
expanded.extend(val);
323-
Ok(Path {
324-
value: Cow::Owned(expanded),
325-
})
322+
let expanded = git_features::path::convert::to_native_separators(expanded);
323+
Ok(Path { value: expanded })
326324
} else if val.starts_with(b"~") && val.contains(&SLASH) {
327325
Self::interpolate_user(val, SLASH)
328326
} else {
@@ -331,7 +329,7 @@ impl Path<'_> {
331329
}
332330

333331
#[cfg(target_os = "windows")]
334-
fn interpolate_user(val: Cow<[u8]>, slash: u8) -> Result<Path, ()> {
332+
fn interpolate_user(_val: Cow<[u8]>, _slash: u8) -> Result<Path, ()> {
335333
Err(())
336334
}
337335

@@ -340,10 +338,8 @@ impl Path<'_> {
340338
let (_prefix, val) = val.split_at(slash.len());
341339
let i = val.iter().position(|&e| e == slash).ok_or(())?;
342340
let (username, val) = val.split_at(i);
343-
let home = Passwd::from_name(std::str::from_utf8(username).map_err(|_| ())?)
344-
.map_err(|_| ())?
345-
.ok_or(())?
346-
.dir;
341+
let path = git_features::path::from_bytes(username).ok_or(())?;
342+
let home = Passwd::from_name(path.to_str().ok_or(())?).map_err(|_|())?.ok_or(())?.dir;
347343
let mut expanded = home.as_bytes().to_owned();
348344
expanded.extend(val);
349345
Ok(Path {

0 commit comments

Comments
 (0)