Skip to content

filter refs by spec #526

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 23 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bc45906
replace `quick-error` with `thiserror` (#450)
Byron Sep 5, 2022
5a74999
chore!: replace quick-error with thiserror (#450)
Byron Sep 7, 2022
9c8a36f
chore!: remove quick-error in favor of thiserror (#450)
Byron Sep 7, 2022
9aadac3
adjust to changes in git-object (#450)
Byron Sep 7, 2022
4d6ce80
chore!: replace `quick-error` with `thiserror` (#450)
Byron Sep 7, 2022
4eac45f
adjust to changes in `git-validate` (#450)
Byron Sep 7, 2022
725210d
chore!: replace `quick-error` with `thiserror` (#450)
Byron Sep 7, 2022
1d85564
thanks clippy
Byron Sep 7, 2022
296f23f
adjust to changes in `git-ref` (#450)
Byron Sep 7, 2022
dad9cbe
fix docs (#450)
Byron Sep 7, 2022
5ac6fee
fix journey tests (#450)
Byron Sep 7, 2022
140e690
fix windows tests (#450)
Byron Sep 7, 2022
0f0bca3
change!: Remove `Access` without replacement. (#450)
Byron Sep 11, 2022
129bc87
refactor (#450)
Byron Sep 11, 2022
ac3823d
change!: remove `thiserror` optional feature. (#450)
Byron Sep 11, 2022
515e521
feat: `Permissions::check_opt()` for those who don't need an error ca…
Byron Sep 11, 2022
0ce21b1
adapt to changes in `git-sec` (#450)
Byron Sep 11, 2022
51c721c
change!: `permission::Error<R>` with only one generic parameter (#450)
Byron Sep 11, 2022
b42a64d
Manually implement `permission::Error` to save on `thiserror` depende…
Byron Sep 11, 2022
33f8b92
change!: remove `Perrmission::fmt()` (Display) (#450)
Byron Sep 11, 2022
fe24b41
feat: `Permission::is_allowed()` as convenience method (#450)
Byron Sep 11, 2022
d6ef2ce
adjust to changes in `git-sec` (#450)
Byron Sep 11, 2022
9e4e4c4
refactor (#450)
Byron Sep 11, 2022
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
11 changes: 5 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion git-chunk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ doctest = false
test = false

[dependencies]
quick-error = "2.0.0"
thiserror = "1.0.34"
54 changes: 23 additions & 31 deletions git-chunk/src/file/decode.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
use std::{convert::TryInto, ops::Range};

pub use error::Error;

mod error {
use quick_error::quick_error;
quick_error! {
/// The value returned by [crate::FileRef::from_bytes()
#[derive(Debug)]
#[allow(missing_docs)]
pub enum Error {
EarlySentinelValue {
display("Sentinel value encountered while still processing chunks.")
}
MissingSentinelValue { actual: crate::Id } {
display("Sentinel value wasn't found, saw {:?}", std::str::from_utf8(actual.as_ref()).unwrap_or("<non-ascii>"))
}
ChunkSizeOutOfBounds { offset: crate::file::Offset, file_length: u64 } {
display("The chunk offset {} went past the file of length {} - was it truncated?", offset, file_length)
}
NonIncrementalChunkOffsets {
display("All chunk offsets must be incrementing.")
}
DuplicateChunk(kind: crate::Id) {
display("The chunk of kind {:?} was encountered more than once", std::str::from_utf8(kind.as_ref()).unwrap_or("<non-ascii>"))
}
TocTooSmall { actual: usize, expected: usize } {
display("The table of contents would be {} bytes, but got only {}", expected, actual)
}
Empty {
display("Empty chunk indices are not allowed as the point of chunked files is to have chunks.")
}
}
/// The value returned by [crate::FileRef::from_bytes()
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Sentinel value encountered while still processing chunks.")]
EarlySentinelValue,
#[error("Sentinel value wasn't found, saw {:?}", std::str::from_utf8(actual.as_ref()).unwrap_or("<non-ascii>"))]
MissingSentinelValue { actual: crate::Id },
#[error("The chunk offset {offset} went past the file of length {file_length} - was it truncated?")]
ChunkSizeOutOfBounds {
offset: crate::file::Offset,
file_length: u64,
},
#[error("All chunk offsets must be incrementing.")]
NonIncrementalChunkOffsets,
#[error("The chunk of kind {:?} was encountered more than once", std::str::from_utf8(kind.as_ref()).unwrap_or("<non-ascii>"))]
DuplicateChunk { kind: crate::Id },
#[error("The table of contents would be {expected} bytes, but got only {actual}")]
TocTooSmall { actual: usize, expected: usize },
#[error("Empty chunk indices are not allowed as the point of chunked files is to have chunks.")]
Empty,
}
}
pub use error::Error;

use crate::{file, file::index};

Expand Down Expand Up @@ -62,7 +54,7 @@ impl file::Index {
return Err(Error::EarlySentinelValue);
}
if chunks.iter().any(|c: &index::Entry| c.kind == kind) {
return Err(Error::DuplicateChunk(kind));
return Err(Error::DuplicateChunk { kind });
}

let offset = be_u64(offset);
Expand Down
23 changes: 8 additions & 15 deletions git-chunk/src/file/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,14 @@ pub mod offset_by_kind {

///
pub mod data_by_kind {
use quick_error::quick_error;
quick_error! {
/// The error returned by [Index::data_by_kind()][super::Index::data_by_id()].
#[derive(Debug)]
#[allow(missing_docs)]
pub enum Error {
NotFound(err: super::offset_by_kind::Error) {
display("The chunk wasn't found in the file index")
from()
source(err)
}
FileTooLarge {
display("The offsets into the file couldn't be represented by usize")
}
}
/// The error returned by [Index::data_by_kind()][super::Index::data_by_id()].
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("The chunk wasn't found in the file index")]
NotFound(#[from] super::offset_by_kind::Error),
#[error("The offsets into the file couldn't be represented by usize")]
FileTooLarge,
}
}

Expand Down
2 changes: 1 addition & 1 deletion git-discover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include = ["src/**/*", "CHANGELOG.md"]
doctest = false

[dependencies]
git-sec = { version = "^0.3.1", path = "../git-sec", features = ["thiserror"] }
git-sec = { version = "^0.3.1", path = "../git-sec" }
git-path = { version = "^0.4.2", path = "../git-path" }
git-ref = { version = "^0.15.2", path = "../git-ref" }
git-hash = { version = "^0.9.9", path = "../git-hash" }
Expand Down
2 changes: 1 addition & 1 deletion git-object/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ git-actor = { version = "^0.11.3", path = "../git-actor" }

btoi = "0.4.2"
itoa = "1.0.1"
quick-error = "2.0.0"
thiserror = "1.0.34"
hex = "0.4.2"
bstr = { version = "0.2.13", default-features = false, features = ["std", "unicode"] }
nom = { version = "7", default-features = false, features = ["std"]}
Expand Down
19 changes: 9 additions & 10 deletions git-object/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,16 @@ impl<'a> Data<'a> {

/// Types supporting object hash verification
pub mod verify {
use quick_error::quick_error;

quick_error! {
/// Returned by [`crate::Data::verify_checksum()`]
#[derive(Debug)]
#[allow(missing_docs)]
pub enum Error {
ChecksumMismatch {desired: git_hash::ObjectId, actual: git_hash::ObjectId} {
display("Object expected to have id {}, but actual id was {}", desired, actual)
}
}
/// Returned by [`crate::Data::verify_checksum()`]
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Object expected to have id {desired}, but actual id was {actual}")]
ChecksumMismatch {
desired: git_hash::ObjectId,
actual: git_hash::ObjectId,
},
}

impl crate::Data<'_> {
Expand Down
21 changes: 9 additions & 12 deletions git-object/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
use std::io::{self, Write};

use bstr::{BString, ByteSlice};
use quick_error::quick_error;

quick_error! {
#[derive(Debug)]
enum Error {
NewlineInHeaderValue(value: BString) {
display("Newlines are not allowed in header values: {:?}", value)
}
EmptyValue {
display("Header values must not be empty")
}
}
/// An error returned when object encoding fails.
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Newlines are not allowed in header values: {value:?}")]
NewlineInHeaderValue { value: BString },
#[error("Header values must not be empty")]
EmptyValue,
}

macro_rules! check {
Expand Down Expand Up @@ -78,7 +75,7 @@ pub(crate) fn header_field(name: &[u8], value: &[u8], out: impl io::Write) -> io
return Err(Error::EmptyValue.into());
}
if value.find(NL).is_some() {
return Err(Error::NewlineInHeaderValue(value.into()).into());
return Err(Error::NewlineInHeaderValue { value: value.into() }.into());
}
trusted_header_field(name, value, out)
}
Expand Down
19 changes: 7 additions & 12 deletions git-object/src/kind.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
use std::fmt;

use quick_error::quick_error;

use crate::Kind;

quick_error! {
/// The Error used in [`Kind::from_bytes()`].
#[derive(Debug, Clone)]
#[allow(missing_docs)]
pub enum Error {
InvalidObjectKind(kind: crate::BString) {
display("Unknown object kind: {:?}", kind)
}
}
/// The Error used in [`Kind::from_bytes()`].
#[derive(Debug, Clone, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Unknown object kind: {kind:?}")]
InvalidObjectKind { kind: bstr::BString },
}

impl Kind {
Expand All @@ -23,7 +18,7 @@ impl Kind {
b"blob" => Kind::Blob,
b"commit" => Kind::Commit,
b"tag" => Kind::Tag,
_ => return Err(Error::InvalidObjectKind(s.into())),
_ => return Err(Error::InvalidObjectKind { kind: s.into() }),
})
}

Expand Down
56 changes: 24 additions & 32 deletions git-object/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,28 +336,20 @@ pub mod decode {
pub use _decode::{Error, ParseError, ParseErrorOwned};
impl std::error::Error for Error {}

use quick_error::quick_error;
quick_error! {
/// Returned by [`loose_header()`]
#[derive(Debug)]
#[allow(missing_docs)]
pub enum LooseHeaderDecodeError {
ParseIntegerError(
source: btoi::ParseIntegerError,
message: &'static str,
number: Vec<u8>
) {
display("{}: {:?}", message, std::str::from_utf8(number))
}
InvalidHeader(s: &'static str) {
display("{}", s)
}
ObjectHeader(err: super::kind::Error) {
display("The object header contained an unknown object kind.")
from()
source(err)
}
}
/// Returned by [`loose_header()`]
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum LooseHeaderDecodeError {
#[error("{message}: {number:?}")]
ParseIntegerError {
source: btoi::ParseIntegerError,
message: &'static str,
number: bstr::BString,
},
#[error("{message}")]
InvalidHeader { message: &'static str },
#[error("The object header contained an unknown object kind.")]
ObjectHeader(#[from] super::kind::Error),
}

use bstr::ByteSlice;
Expand All @@ -367,18 +359,18 @@ pub mod decode {
/// `size` is the uncompressed size of the payload in bytes.
pub fn loose_header(input: &[u8]) -> Result<(super::Kind, usize, usize), LooseHeaderDecodeError> {
use LooseHeaderDecodeError::*;
let kind_end = input.find_byte(0x20).ok_or(InvalidHeader("Expected '<type> <size>'"))?;
let kind_end = input.find_byte(0x20).ok_or(InvalidHeader {
message: "Expected '<type> <size>'",
})?;
let kind = super::Kind::from_bytes(&input[..kind_end])?;
let size_end = input
.find_byte(0x0)
.ok_or(InvalidHeader("Did not find 0 byte in header"))?;
let size_end = input.find_byte(0x0).ok_or(InvalidHeader {
message: "Did not find 0 byte in header",
})?;
let size_bytes = &input[kind_end + 1..size_end];
let size = btoi::btoi(size_bytes).map_err(|source| {
ParseIntegerError(
source,
"Object size in header could not be parsed",
size_bytes.to_owned(),
)
let size = btoi::btoi(size_bytes).map_err(|source| ParseIntegerError {
source,
message: "Object size in header could not be parsed",
number: size_bytes.into(),
})?;
Ok((kind, size, size_end + 1))
}
Expand Down
16 changes: 7 additions & 9 deletions git-object/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,18 @@ impl Object {
}
}

use quick_error::quick_error;

use crate::{
decode::{loose_header, Error as DecodeError, LooseHeaderDecodeError},
BlobRef, CommitRef, Kind, ObjectRef, TagRef, TreeRef,
};

quick_error! {
#[derive(Debug)]
#[allow(missing_docs)]
pub enum LooseDecodeError {
InvalidHeader(err: LooseHeaderDecodeError) { from() }
InvalidContent(err: DecodeError) { from() }
}
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum LooseDecodeError {
#[error(transparent)]
InvalidHeader(#[from] LooseHeaderDecodeError),
#[error(transparent)]
InvalidContent(#[from] DecodeError),
}

impl<'a> ObjectRef<'a> {
Expand Down
Loading