Skip to content

Commit 12313f2

Browse files
committed
Merge branch 'improvements'
2 parents ca90e9c + ae2b733 commit 12313f2

File tree

13 files changed

+65
-29
lines changed

13 files changed

+65
-29
lines changed

clippy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
msrv = "1.70.0"
1+
msrv = "1.74.0"

gix-credentials/src/helper/invoke.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl Action {
99
Action::Get(ctx) => ctx.write_to(write),
1010
Action::Store(last) | Action::Erase(last) => {
1111
write.write_all(last).ok();
12-
write.write_all(&[b'\n']).ok();
12+
write.write_all(b"\n").ok();
1313
Ok(())
1414
}
1515
}

gix-date/tests/time/format.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,20 @@ fn unix() {
1717

1818
#[test]
1919
fn raw() {
20-
let expected = "123456789 +0230";
21-
assert_eq!(time().format(Format::Raw), expected);
22-
assert_eq!(time().format(format::RAW), expected);
20+
for (time, expected) in [
21+
(time(), "123456789 +0230"),
22+
(
23+
Time {
24+
seconds: 1112911993,
25+
offset: 3600,
26+
sign: Sign::Plus,
27+
},
28+
"1112911993 +0100",
29+
),
30+
] {
31+
assert_eq!(time.format(Format::Raw), expected);
32+
assert_eq!(time.format(format::RAW), expected);
33+
}
2334
}
2435

2536
#[test]

gix-date/tests/time/parse.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ fn raw() {
6767
},
6868
);
6969

70+
assert_eq!(
71+
gix_date::parse("1112911993 +0100", None).unwrap(),
72+
Time {
73+
seconds: 1112911993,
74+
offset: 3600,
75+
sign: Sign::Plus,
76+
},
77+
);
78+
7079
let expected = Time {
7180
seconds: 1660874655,
7281
offset: -28800,

gix-object/src/tree/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl crate::WriteTo for Tree {
4747
.into());
4848
}
4949
out.write_all(filename)?;
50-
out.write_all(&[b'\0'])?;
50+
out.write_all(b"\0")?;
5151

5252
out.write_all(oid.as_bytes())?;
5353
}
@@ -94,7 +94,7 @@ impl<'a> crate::WriteTo for TreeRef<'a> {
9494
.into());
9595
}
9696
out.write_all(filename)?;
97-
out.write_all(&[b'\0'])?;
97+
out.write_all(b"\0")?;
9898

9999
out.write_all(oid.as_bytes())?;
100100
}

gix-packetline-blocking/src/encode/blocking_io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn data_to_write(data: &[u8], out: impl io::Write) -> io::Result<usize> {
3737

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

4343
fn prefixed_data_to_write(prefix: &[u8], data: &[u8], out: impl io::Write) -> io::Result<usize> {

gix-packetline/src/encode/blocking_io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn data_to_write(data: &[u8], out: impl io::Write) -> io::Result<usize> {
3535

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

4141
fn prefixed_data_to_write(prefix: &[u8], data: &[u8], out: impl io::Write) -> io::Result<usize> {

gix-refspec/src/write.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,25 @@ impl Instruction<'_> {
3636
allow_non_fast_forward,
3737
}) => {
3838
if *allow_non_fast_forward {
39-
out.write_all(&[b'+'])?;
39+
out.write_all(b"+")?;
4040
}
4141
out.write_all(src)?;
42-
out.write_all(&[b':'])?;
42+
out.write_all(b":")?;
4343
out.write_all(dst)
4444
}
4545
Instruction::Push(Push::AllMatchingBranches { allow_non_fast_forward }) => {
4646
if *allow_non_fast_forward {
47-
out.write_all(&[b'+'])?;
47+
out.write_all(b"+")?;
4848
}
49-
out.write_all(&[b':'])
49+
out.write_all(b":")
5050
}
5151
Instruction::Push(Push::Delete { ref_or_pattern }) => {
52-
out.write_all(&[b':'])?;
52+
out.write_all(b":")?;
5353
out.write_all(ref_or_pattern)
5454
}
5555
Instruction::Fetch(Fetch::Only { src }) => out.write_all(src),
5656
Instruction::Fetch(Fetch::Exclude { src }) => {
57-
out.write_all(&[b'^'])?;
57+
out.write_all(b"^")?;
5858
out.write_all(src)
5959
}
6060
Instruction::Fetch(Fetch::AndUpdate {
@@ -63,10 +63,10 @@ impl Instruction<'_> {
6363
allow_non_fast_forward,
6464
}) => {
6565
if *allow_non_fast_forward {
66-
out.write_all(&[b'+'])?;
66+
out.write_all(b"+")?;
6767
}
6868
out.write_all(src)?;
69-
out.write_all(&[b':'])?;
69+
out.write_all(b":")?;
7070
out.write_all(dst)
7171
}
7272
}

gix-url/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,10 @@ impl Url {
322322
(Some(user), Some(host)) => {
323323
out.write_all(user.as_bytes())?;
324324
if let Some(password) = &self.password {
325-
out.write_all(&[b':'])?;
325+
out.write_all(b":")?;
326326
out.write_all(password.as_bytes())?;
327327
}
328-
out.write_all(&[b'@'])?;
328+
out.write_all(b"@")?;
329329
out.write_all(host.as_bytes())?;
330330
}
331331
(None, Some(host)) => {

gix-validate/src/reference.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub mod name {
1515
StartsWithSlash,
1616
#[error("Multiple slashes in a row are not allowed as they may change the reference's meaning")]
1717
RepeatedSlash,
18-
#[error("Names must not be a single '.', but may contain it.")]
19-
SingleDot,
18+
#[error("Path components must not start with '.'")]
19+
StartsWithDot,
2020
}
2121

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

2929
use bstr::BStr;
3030

31-
/// Validate a reference name running all the tests in the book. This disallows lower-case references, but allows
32-
/// ones like `HEAD`.
31+
/// Validate a reference name running all the tests in the book. This disallows lower-case references like `lower`, but also allows
32+
/// ones like `HEAD`, and `refs/lower`.
3333
pub fn name(path: &BStr) -> Result<&BStr, name::Error> {
3434
validate(path, Mode::Complete)
3535
}
@@ -51,19 +51,17 @@ fn validate(path: &BStr, mode: Mode) -> Result<&BStr, name::Error> {
5151
return Err(name::Error::StartsWithSlash);
5252
}
5353
let mut previous = 0;
54-
let mut one_before_previous = 0;
5554
let mut saw_slash = false;
5655
for byte in path.iter() {
5756
match *byte {
58-
b'/' if previous == b'.' && one_before_previous == b'/' => return Err(name::Error::SingleDot),
5957
b'/' if previous == b'/' => return Err(name::Error::RepeatedSlash),
58+
b'.' if previous == b'/' => return Err(name::Error::StartsWithDot),
6059
_ => {}
6160
}
6261

6362
if *byte == b'/' {
6463
saw_slash = true;
6564
}
66-
one_before_previous = previous;
6765
previous = *byte;
6866
}
6967

gix-validate/src/tag.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub mod name {
2121
Asterisk,
2222
#[error("A ref must not start with a '.'")]
2323
StartsWithDot,
24+
#[error("A ref must not end with a '.'")]
25+
EndsWithDot,
2426
#[error("A ref must not end with a '/'")]
2527
EndsWithSlash,
2628
#[error("A ref must not be empty")]
@@ -29,6 +31,7 @@ pub mod name {
2931
}
3032

3133
/// Assure the given `input` resemble a valid git tag name, which is returned unchanged on success.
34+
/// Tag names are provided as names, lik` v1.0` or `alpha-1`, without paths.
3235
pub fn name(input: &BStr) -> Result<&BStr, name::Error> {
3336
if input.is_empty() {
3437
return Err(name::Error::Empty);
@@ -55,6 +58,9 @@ pub fn name(input: &BStr) -> Result<&BStr, name::Error> {
5558
if input[0] == b'.' {
5659
return Err(name::Error::StartsWithDot);
5760
}
61+
if input[input.len() - 1] == b'.' {
62+
return Err(name::Error::EndsWithDot);
63+
}
5864
if input.ends_with(b".lock") {
5965
return Err(name::Error::LockFileSuffix);
6066
}

gix-validate/tests/reference/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ mod name_partial {
5555
mktest!(
5656
refs_path_component_is_singular_dot,
5757
b"refs/./still-inside-but-not-cool",
58-
RefError::SingleDot
58+
RefError::StartsWithDot
5959
);
6060
mktest!(any_path_starts_with_slash, b"/etc/foo", RefError::StartsWithSlash);
6161
mktest!(empty_path, b"", RefError::Tag(TagError::Empty));
@@ -107,6 +107,7 @@ mod name {
107107
mktest!(all_uppercase, b"MAIN");
108108
mktest!(all_uppercase_with_underscore, b"NEW_HEAD");
109109
mktest!(chinese_utf8, "refs/heads/你好吗".as_bytes());
110+
mktest!(dot_in_directory_component, b"this./totally./works");
110111
}
111112

112113
mod invalid {
@@ -136,10 +137,21 @@ mod name {
136137
b".refs/somewhere",
137138
RefError::Tag(TagError::StartsWithDot)
138139
);
140+
141+
mktest!(
142+
refs_path_name_starts_with_dot_in_name,
143+
b"refs/.somewhere",
144+
RefError::StartsWithDot
145+
);
146+
mktest!(
147+
refs_path_name_ends_with_dot_in_name,
148+
b"refs/somewhere.",
149+
RefError::Tag(TagError::EndsWithDot)
150+
);
139151
mktest!(
140152
refs_path_component_is_singular_dot,
141153
b"refs/./still-inside-but-not-cool",
142-
RefError::SingleDot
154+
RefError::StartsWithDot
143155
);
144156
mktest!(capitalized_name_without_path, b"Main", RefError::SomeLowercase);
145157
mktest!(lowercase_name_without_path, b"main", RefError::SomeLowercase);

gix-validate/tests/tag/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ mod name {
1919
mktest!(contains_brackets, b"this_{is-fine}_too");
2020
mktest!(contains_brackets_and_at, b"this_{@is-fine@}_too");
2121
mktest!(dot_in_the_middle, b"token.other");
22-
mktest!(dot_at_the_end, b"hello.");
2322
mktest!(slash_inbetween, b"hello/world");
2423
}
2524

@@ -76,6 +75,7 @@ mod name {
7675
mktestb!(contains_newline, b"prefix\nsuffix");
7776
mktestb!(contains_carriage_return, b"prefix\rsuffix");
7877
mktest!(starts_with_dot, b".with-dot", StartsWithDot);
78+
mktest!(ends_with_dot, b"with-dot.", EndsWithDot);
7979
mktest!(empty, b"", Empty);
8080
}
8181
}

0 commit comments

Comments
 (0)