Skip to content

improvements #1480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.70.0"
msrv = "1.74.0"
2 changes: 1 addition & 1 deletion gix-credentials/src/helper/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl Action {
Action::Get(ctx) => ctx.write_to(write),
Action::Store(last) | Action::Erase(last) => {
write.write_all(last).ok();
write.write_all(&[b'\n']).ok();
write.write_all(b"\n").ok();
Ok(())
}
}
Expand Down
17 changes: 14 additions & 3 deletions gix-date/tests/time/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@ fn unix() {

#[test]
fn raw() {
let expected = "123456789 +0230";
assert_eq!(time().format(Format::Raw), expected);
assert_eq!(time().format(format::RAW), expected);
for (time, expected) in [
(time(), "123456789 +0230"),
(
Time {
seconds: 1112911993,
offset: 3600,
sign: Sign::Plus,
},
"1112911993 +0100",
),
] {
assert_eq!(time.format(Format::Raw), expected);
assert_eq!(time.format(format::RAW), expected);
}
}

#[test]
Expand Down
9 changes: 9 additions & 0 deletions gix-date/tests/time/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ fn raw() {
},
);

assert_eq!(
gix_date::parse("1112911993 +0100", None).unwrap(),
Time {
seconds: 1112911993,
offset: 3600,
sign: Sign::Plus,
},
);

let expected = Time {
seconds: 1660874655,
offset: -28800,
Expand Down
4 changes: 2 additions & 2 deletions gix-object/src/tree/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl crate::WriteTo for Tree {
.into());
}
out.write_all(filename)?;
out.write_all(&[b'\0'])?;
out.write_all(b"\0")?;

out.write_all(oid.as_bytes())?;
}
Expand Down Expand Up @@ -94,7 +94,7 @@ impl<'a> crate::WriteTo for TreeRef<'a> {
.into());
}
out.write_all(filename)?;
out.write_all(&[b'\0'])?;
out.write_all(b"\0")?;

out.write_all(oid.as_bytes())?;
}
Expand Down
2 changes: 1 addition & 1 deletion gix-packetline-blocking/src/encode/blocking_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn data_to_write(data: &[u8], out: impl io::Write) -> io::Result<usize> {

/// Write a `text` message to `out`, which is assured to end in a newline.
pub fn text_to_write(text: &[u8], out: impl io::Write) -> io::Result<usize> {
prefixed_and_suffixed_data_to_write(&[], text, &[b'\n'], out)
prefixed_and_suffixed_data_to_write(&[], text, b"\n", out)
}

fn prefixed_data_to_write(prefix: &[u8], data: &[u8], out: impl io::Write) -> io::Result<usize> {
Expand Down
2 changes: 1 addition & 1 deletion gix-packetline/src/encode/blocking_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn data_to_write(data: &[u8], out: impl io::Write) -> io::Result<usize> {

/// Write a `text` message to `out`, which is assured to end in a newline.
pub fn text_to_write(text: &[u8], out: impl io::Write) -> io::Result<usize> {
prefixed_and_suffixed_data_to_write(&[], text, &[b'\n'], out)
prefixed_and_suffixed_data_to_write(&[], text, b"\n", out)
}

fn prefixed_data_to_write(prefix: &[u8], data: &[u8], out: impl io::Write) -> io::Result<usize> {
Expand Down
16 changes: 8 additions & 8 deletions gix-refspec/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ impl Instruction<'_> {
allow_non_fast_forward,
}) => {
if *allow_non_fast_forward {
out.write_all(&[b'+'])?;
out.write_all(b"+")?;
}
out.write_all(src)?;
out.write_all(&[b':'])?;
out.write_all(b":")?;
out.write_all(dst)
}
Instruction::Push(Push::AllMatchingBranches { allow_non_fast_forward }) => {
if *allow_non_fast_forward {
out.write_all(&[b'+'])?;
out.write_all(b"+")?;
}
out.write_all(&[b':'])
out.write_all(b":")
}
Instruction::Push(Push::Delete { ref_or_pattern }) => {
out.write_all(&[b':'])?;
out.write_all(b":")?;
out.write_all(ref_or_pattern)
}
Instruction::Fetch(Fetch::Only { src }) => out.write_all(src),
Instruction::Fetch(Fetch::Exclude { src }) => {
out.write_all(&[b'^'])?;
out.write_all(b"^")?;
out.write_all(src)
}
Instruction::Fetch(Fetch::AndUpdate {
Expand All @@ -63,10 +63,10 @@ impl Instruction<'_> {
allow_non_fast_forward,
}) => {
if *allow_non_fast_forward {
out.write_all(&[b'+'])?;
out.write_all(b"+")?;
}
out.write_all(src)?;
out.write_all(&[b':'])?;
out.write_all(b":")?;
out.write_all(dst)
}
}
Expand Down
4 changes: 2 additions & 2 deletions gix-url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ impl Url {
(Some(user), Some(host)) => {
out.write_all(user.as_bytes())?;
if let Some(password) = &self.password {
out.write_all(&[b':'])?;
out.write_all(b":")?;
out.write_all(password.as_bytes())?;
}
out.write_all(&[b'@'])?;
out.write_all(b"@")?;
out.write_all(host.as_bytes())?;
}
(None, Some(host)) => {
Expand Down
12 changes: 5 additions & 7 deletions gix-validate/src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub mod name {
StartsWithSlash,
#[error("Multiple slashes in a row are not allowed as they may change the reference's meaning")]
RepeatedSlash,
#[error("Names must not be a single '.', but may contain it.")]
SingleDot,
#[error("Path components must not start with '.'")]
StartsWithDot,
}

impl From<Infallible> for Error {
Expand All @@ -28,8 +28,8 @@ pub mod name {

use bstr::BStr;

/// Validate a reference name running all the tests in the book. This disallows lower-case references, but allows
/// ones like `HEAD`.
/// Validate a reference name running all the tests in the book. This disallows lower-case references like `lower`, but also allows
/// ones like `HEAD`, and `refs/lower`.
pub fn name(path: &BStr) -> Result<&BStr, name::Error> {
validate(path, Mode::Complete)
}
Expand All @@ -51,19 +51,17 @@ fn validate(path: &BStr, mode: Mode) -> Result<&BStr, name::Error> {
return Err(name::Error::StartsWithSlash);
}
let mut previous = 0;
let mut one_before_previous = 0;
let mut saw_slash = false;
for byte in path.iter() {
match *byte {
b'/' if previous == b'.' && one_before_previous == b'/' => return Err(name::Error::SingleDot),
b'/' if previous == b'/' => return Err(name::Error::RepeatedSlash),
b'.' if previous == b'/' => return Err(name::Error::StartsWithDot),
_ => {}
}

if *byte == b'/' {
saw_slash = true;
}
one_before_previous = previous;
previous = *byte;
}

Expand Down
6 changes: 6 additions & 0 deletions gix-validate/src/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub mod name {
Asterisk,
#[error("A ref must not start with a '.'")]
StartsWithDot,
#[error("A ref must not end with a '.'")]
EndsWithDot,
#[error("A ref must not end with a '/'")]
EndsWithSlash,
#[error("A ref must not be empty")]
Expand All @@ -29,6 +31,7 @@ pub mod name {
}

/// Assure the given `input` resemble a valid git tag name, which is returned unchanged on success.
/// Tag names are provided as names, lik` v1.0` or `alpha-1`, without paths.
pub fn name(input: &BStr) -> Result<&BStr, name::Error> {
if input.is_empty() {
return Err(name::Error::Empty);
Expand All @@ -55,6 +58,9 @@ pub fn name(input: &BStr) -> Result<&BStr, name::Error> {
if input[0] == b'.' {
return Err(name::Error::StartsWithDot);
}
if input[input.len() - 1] == b'.' {
return Err(name::Error::EndsWithDot);
}
if input.ends_with(b".lock") {
return Err(name::Error::LockFileSuffix);
}
Expand Down
16 changes: 14 additions & 2 deletions gix-validate/tests/reference/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod name_partial {
mktest!(
refs_path_component_is_singular_dot,
b"refs/./still-inside-but-not-cool",
RefError::SingleDot
RefError::StartsWithDot
);
mktest!(any_path_starts_with_slash, b"/etc/foo", RefError::StartsWithSlash);
mktest!(empty_path, b"", RefError::Tag(TagError::Empty));
Expand Down Expand Up @@ -107,6 +107,7 @@ mod name {
mktest!(all_uppercase, b"MAIN");
mktest!(all_uppercase_with_underscore, b"NEW_HEAD");
mktest!(chinese_utf8, "refs/heads/你好吗".as_bytes());
mktest!(dot_in_directory_component, b"this./totally./works");
}

mod invalid {
Expand Down Expand Up @@ -136,10 +137,21 @@ mod name {
b".refs/somewhere",
RefError::Tag(TagError::StartsWithDot)
);

mktest!(
refs_path_name_starts_with_dot_in_name,
b"refs/.somewhere",
RefError::StartsWithDot
);
mktest!(
refs_path_name_ends_with_dot_in_name,
b"refs/somewhere.",
RefError::Tag(TagError::EndsWithDot)
);
mktest!(
refs_path_component_is_singular_dot,
b"refs/./still-inside-but-not-cool",
RefError::SingleDot
RefError::StartsWithDot
);
mktest!(capitalized_name_without_path, b"Main", RefError::SomeLowercase);
mktest!(lowercase_name_without_path, b"main", RefError::SomeLowercase);
Expand Down
2 changes: 1 addition & 1 deletion gix-validate/tests/tag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ mod name {
mktest!(contains_brackets, b"this_{is-fine}_too");
mktest!(contains_brackets_and_at, b"this_{@is-fine@}_too");
mktest!(dot_in_the_middle, b"token.other");
mktest!(dot_at_the_end, b"hello.");
mktest!(slash_inbetween, b"hello/world");
}

Expand Down Expand Up @@ -76,6 +75,7 @@ mod name {
mktestb!(contains_newline, b"prefix\nsuffix");
mktestb!(contains_carriage_return, b"prefix\rsuffix");
mktest!(starts_with_dot, b".with-dot", StartsWithDot);
mktest!(ends_with_dot, b"with-dot.", EndsWithDot);
mktest!(empty, b"", Empty);
}
}
Loading