Skip to content

Commit

Permalink
feat: Implement newline normalization. (#228)
Browse files Browse the repository at this point in the history
This should ensure consistent Artifact IDs whether on Windows or
Unix systems. It works by normalizing all CRLF newlines into LF
newlines unconditionally. Since we don't care about roundtripping
data (we don't store data at all, unlike Git), we can do this
and in fact *have* to do it unconditionally to make the ID
system work.

Signed-off-by: Andrew Lilley Brinker <[email protected]>
  • Loading branch information
alilleybrinker authored Jan 29, 2025
1 parent b9c2ad0 commit 083f0f4
Show file tree
Hide file tree
Showing 24 changed files with 699 additions and 578 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Windows test file that should _always_ use DOS-style newlines,
# regardless of the current system. Used for tests to validate
# newline normalization is working.
windows_line.txt text eol=crlf

10 changes: 2 additions & 8 deletions gitoid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ sha2 = { version = "0.10.8", default-features = false, optional = true }

# std-requiring dependencies.

format-bytes = { version = "0.3.0", optional = true }
hex = { version = "0.4.3", optional = true }
serde = { version = "1.0.197", optional = true }
tokio = { version = "1.36.0", features = ["io-util"], optional = true }
url = { version = "2.4.1", optional = true }
boring = { version = "4.6.0", optional = true }
openssl = { version = "0.10.66", optional = true }
bytecount = "0.6.8"

[dev-dependencies]

Expand Down Expand Up @@ -101,13 +101,7 @@ sha256 = ["dep:sha2"]
#
# This feature is enabled by default. You can disable it to run in
# environments without `std`, usually embedded environments.
std = [
"digest/std",
"sha1?/std",
"sha1collisiondetection?/std",
"sha2?/std",
"dep:format-bytes",
]
std = ["digest/std", "sha1?/std", "sha1collisiondetection?/std", "sha2?/std"]

# Get the ability to construct and get out URLs.
#
Expand Down
18 changes: 6 additions & 12 deletions gitoid/src/backend/boringssl.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
//! BoringSSL-based cryptography backend.
use crate::impl_hash_algorithm;
use crate::sealed::Sealed;
use crate::HashAlgorithm;
use crate::{impl_hash_algorithm, sealed::Sealed, HashAlgorithm};
use boring::sha;
use digest::consts::U20;
use digest::consts::U32;
use digest::generic_array::GenericArray;
use digest::Digest;
use digest::FixedOutput;
use digest::HashMarker;
use digest::Output;
use digest::OutputSizeUser;
use digest::Update;
use digest::{
consts::{U20, U32},
generic_array::GenericArray,
Digest, FixedOutput, HashMarker, Output, OutputSizeUser, Update,
};

#[cfg(feature = "sha1")]
/// SHA-1 algorithm
Expand Down
18 changes: 6 additions & 12 deletions gitoid/src/backend/openssl.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
//! OpenSSL-based cryptography backend.
use crate::impl_hash_algorithm;
use crate::sealed::Sealed;
use crate::HashAlgorithm;
use digest::consts::U20;
use digest::consts::U32;
use digest::generic_array::GenericArray;
use digest::Digest;
use digest::FixedOutput;
use digest::HashMarker;
use digest::Output;
use digest::OutputSizeUser;
use digest::Update;
use crate::{impl_hash_algorithm, sealed::Sealed, HashAlgorithm};
use digest::{
consts::{U20, U32},
generic_array::GenericArray,
Digest, FixedOutput, HashMarker, Output, OutputSizeUser, Update,
};
use openssl::sha;

#[cfg(feature = "sha1")]
Expand Down
9 changes: 3 additions & 6 deletions gitoid/src/backend/rustcrypto.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
//! RustCrypto-based cryptography backend.
use crate::impl_hash_algorithm;
use crate::sealed::Sealed;
use crate::{impl_hash_algorithm, sealed::Sealed, HashAlgorithm};
use digest::{generic_array::GenericArray, Digest, OutputSizeUser};

#[cfg(doc)]
use crate::GitOid;
use crate::HashAlgorithm;
use digest::generic_array::GenericArray;
use digest::Digest;
use digest::OutputSizeUser;

#[cfg(feature = "sha1")]
/// SHA-1 algorithm,
Expand Down
19 changes: 9 additions & 10 deletions gitoid/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
//! Error arising from `GitOid` construction or use.
use core::fmt::Display;
use core::fmt::Formatter;
use core::fmt::Result as FmtResult;
use core::result::Result as StdResult;
use core::{
fmt::{Display, Formatter, Result as FmtResult},
result::Result as StdResult,
};

#[cfg(feature = "hex")]
use hex::FromHexError as HexError;

#[cfg(feature = "std")]
use std::error::Error as StdError;
#[cfg(feature = "std")]
use std::io::Error as IoError;
#[cfg(feature = "url")]
use url::ParseError as UrlError;
use std::{error::Error as StdError, io::Error as IoError};

#[cfg(feature = "url")]
use url::Url;
use url::{ParseError as UrlError, Url};

/// A `Result` with `gitoid::Error` as the error type.
pub(crate) type Result<T> = StdResult<T, Error>;
Expand Down
Loading

0 comments on commit 083f0f4

Please sign in to comment.