Skip to content

Commit 1076375

Browse files
committed
thanks clippy
1 parent a67d82d commit 1076375

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

gix-validate/src/path.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn component(
8383
if input.find_byteset(b"/\\").is_some() {
8484
return Err(component::Error::PathSeparator);
8585
}
86-
if input.chars().skip(1).next() == Some(':') {
86+
if input.chars().nth(1) == Some(':') {
8787
return Err(component::Error::WindowsPathPrefix);
8888
}
8989
} else if input.find_byte(b'/').is_some() {
@@ -142,7 +142,7 @@ fn check_win_devices_and_illegal_characters(input: &BStr) -> Option<component::E
142142
return Some(component::Error::WindowsReservedName);
143143
}
144144
if in3.eq_ignore_ascii_case(b"lpt")
145-
&& input.get(3).map_or(false, |n| n.is_ascii_digit())
145+
&& input.get(3).map_or(false, u8::is_ascii_digit)
146146
&& is_done_windows(input.get(4..))
147147
{
148148
return Some(component::Error::WindowsReservedName);
@@ -153,7 +153,7 @@ fn check_win_devices_and_illegal_characters(input: &BStr) -> Option<component::E
153153
{
154154
return Some(component::Error::WindowsReservedName);
155155
}
156-
if input.iter().find(|b| **b < 0x20 || b":<>\"|?*".contains(b)).is_some() {
156+
if input.iter().any(|b| *b < 0x20 || b":<>\"|?*".contains(b)) {
157157
return Some(component::Error::WindowsIllegalCharacter);
158158
}
159159
if input.ends_with(b".") || input.ends_with(b" ") {
@@ -221,7 +221,7 @@ fn is_dot_git_ntfs(input: &BStr) -> bool {
221221
}
222222

223223
fn is_dot_ntfs(input: &BStr, search_case_insensitive: &str, ntfs_shortname_prefix: &str) -> bool {
224-
if input.get(0) == Some(&b'.') {
224+
if input.first() == Some(&b'.') {
225225
let end_pos = 1 + search_case_insensitive.len();
226226
if input.get(1..end_pos).map_or(false, |input| {
227227
input.eq_ignore_ascii_case(search_case_insensitive.as_bytes())
@@ -238,7 +238,7 @@ fn is_dot_ntfs(input: &BStr, search_case_insensitive: &str, ntfs_shortname_prefi
238238
.map_or(false, |(ntfs_prefix, first_6_of_input)| {
239239
first_6_of_input.eq_ignore_ascii_case(ntfs_prefix)
240240
&& input.get(6) == Some(&b'~')
241-
&& input.get(7).map_or(false, |num| num >= &b'1' && num <= &b'4')
241+
&& input.get(7).map_or(false, |num| (b'1'..=b'4').contains(num))
242242
})
243243
{
244244
return is_done_ntfs(input.get(8..));
@@ -252,7 +252,7 @@ fn is_dot_ntfs(input: &BStr, search_case_insensitive: &str, ntfs_shortname_prefi
252252
return false;
253253
};
254254
if saw_tilde {
255-
if b < b'0' || b > b'9' {
255+
if !b.is_ascii_digit() {
256256
return false;
257257
}
258258
} else if b == b'~' {
@@ -261,16 +261,14 @@ fn is_dot_ntfs(input: &BStr, search_case_insensitive: &str, ntfs_shortname_prefi
261261
let Some(b) = input.get(pos).copied() else {
262262
return false;
263263
};
264-
if b < b'1' || b > b'9' {
264+
if !(b'1'..=b'9').contains(&b) {
265265
return false;
266266
}
267-
} else if pos >= 6 {
268-
return false;
269-
} else if b & 0x80 == 0x80 {
270-
return false;
271-
} else if ntfs_shortname_prefix
272-
.get(pos)
273-
.map_or(true, |ob| !b.eq_ignore_ascii_case(ob))
267+
} else if pos >= 6
268+
|| b & 0x80 == 0x80
269+
|| ntfs_shortname_prefix
270+
.get(pos)
271+
.map_or(true, |ob| !b.eq_ignore_ascii_case(ob))
274272
{
275273
return false;
276274
}

gix-worktree/src/stack/delegate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn validate_last_component(
133133
mode: Option<gix_index::entry::Mode>,
134134
opts: gix_validate::path::component::Options,
135135
) -> std::io::Result<()> {
136-
let Some(last_component) = stack.current_relative().components().rev().next() else {
136+
let Some(last_component) = stack.current_relative().components().next_back() else {
137137
return Ok(());
138138
};
139139
let last_component =

gix-worktree/src/stack/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ impl Stack {
151151
let relative_path = gix_path::try_from_bstr(relative).map_err(|_err| {
152152
std::io::Error::new(
153153
std::io::ErrorKind::Other,
154-
format!(
155-
"The path \"{}\" contained invalid UTF-8 and could not be turned into a path",
156-
relative
157-
),
154+
format!("The path \"{relative}\" contained invalid UTF-8 and could not be turned into a path"),
158155
)
159156
})?;
160157

gix-worktree/tests/worktree/stack/attributes.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ fn baseline() -> crate::Result {
1717
let mut collection = gix_attributes::search::MetadataCollection::default();
1818
let state = gix_worktree::stack::State::for_checkout(
1919
false,
20-
Default::default(),
20+
gix_worktree::validate::path::component::Options {
21+
protect_windows: false,
22+
protect_ntfs: false,
23+
..Default::default()
24+
},
2125
state::Attributes::new(
2226
gix_attributes::Search::new_globals([base.join("user.attributes")], &mut buf, &mut collection)?,
2327
Some(git_dir.join("info").join("attributes")),

0 commit comments

Comments
 (0)