Skip to content

Commit e10554d

Browse files
committed
Merge branch 'filter-refs'
2 parents cfe46b5 + 9e4e4c4 commit e10554d

File tree

72 files changed

+689
-981
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+689
-981
lines changed

Cargo.lock

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-chunk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ doctest = false
1414
test = false
1515

1616
[dependencies]
17-
quick-error = "2.0.0"
17+
thiserror = "1.0.34"

git-chunk/src/file/decode.rs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
use std::{convert::TryInto, ops::Range};
22

3-
pub use error::Error;
4-
53
mod error {
6-
use quick_error::quick_error;
7-
quick_error! {
8-
/// The value returned by [crate::FileRef::from_bytes()
9-
#[derive(Debug)]
10-
#[allow(missing_docs)]
11-
pub enum Error {
12-
EarlySentinelValue {
13-
display("Sentinel value encountered while still processing chunks.")
14-
}
15-
MissingSentinelValue { actual: crate::Id } {
16-
display("Sentinel value wasn't found, saw {:?}", std::str::from_utf8(actual.as_ref()).unwrap_or("<non-ascii>"))
17-
}
18-
ChunkSizeOutOfBounds { offset: crate::file::Offset, file_length: u64 } {
19-
display("The chunk offset {} went past the file of length {} - was it truncated?", offset, file_length)
20-
}
21-
NonIncrementalChunkOffsets {
22-
display("All chunk offsets must be incrementing.")
23-
}
24-
DuplicateChunk(kind: crate::Id) {
25-
display("The chunk of kind {:?} was encountered more than once", std::str::from_utf8(kind.as_ref()).unwrap_or("<non-ascii>"))
26-
}
27-
TocTooSmall { actual: usize, expected: usize } {
28-
display("The table of contents would be {} bytes, but got only {}", expected, actual)
29-
}
30-
Empty {
31-
display("Empty chunk indices are not allowed as the point of chunked files is to have chunks.")
32-
}
33-
}
4+
/// The value returned by [crate::FileRef::from_bytes()
5+
#[derive(Debug, thiserror::Error)]
6+
#[allow(missing_docs)]
7+
pub enum Error {
8+
#[error("Sentinel value encountered while still processing chunks.")]
9+
EarlySentinelValue,
10+
#[error("Sentinel value wasn't found, saw {:?}", std::str::from_utf8(actual.as_ref()).unwrap_or("<non-ascii>"))]
11+
MissingSentinelValue { actual: crate::Id },
12+
#[error("The chunk offset {offset} went past the file of length {file_length} - was it truncated?")]
13+
ChunkSizeOutOfBounds {
14+
offset: crate::file::Offset,
15+
file_length: u64,
16+
},
17+
#[error("All chunk offsets must be incrementing.")]
18+
NonIncrementalChunkOffsets,
19+
#[error("The chunk of kind {:?} was encountered more than once", std::str::from_utf8(kind.as_ref()).unwrap_or("<non-ascii>"))]
20+
DuplicateChunk { kind: crate::Id },
21+
#[error("The table of contents would be {expected} bytes, but got only {actual}")]
22+
TocTooSmall { actual: usize, expected: usize },
23+
#[error("Empty chunk indices are not allowed as the point of chunked files is to have chunks.")]
24+
Empty,
3425
}
3526
}
27+
pub use error::Error;
3628

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

@@ -62,7 +54,7 @@ impl file::Index {
6254
return Err(Error::EarlySentinelValue);
6355
}
6456
if chunks.iter().any(|c: &index::Entry| c.kind == kind) {
65-
return Err(Error::DuplicateChunk(kind));
57+
return Err(Error::DuplicateChunk { kind });
6658
}
6759

6860
let offset = be_u64(offset);

git-chunk/src/file/index.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,14 @@ pub mod offset_by_kind {
2828

2929
///
3030
pub mod data_by_kind {
31-
use quick_error::quick_error;
32-
quick_error! {
33-
/// The error returned by [Index::data_by_kind()][super::Index::data_by_id()].
34-
#[derive(Debug)]
35-
#[allow(missing_docs)]
36-
pub enum Error {
37-
NotFound(err: super::offset_by_kind::Error) {
38-
display("The chunk wasn't found in the file index")
39-
from()
40-
source(err)
41-
}
42-
FileTooLarge {
43-
display("The offsets into the file couldn't be represented by usize")
44-
}
45-
}
31+
/// The error returned by [Index::data_by_kind()][super::Index::data_by_id()].
32+
#[derive(Debug, thiserror::Error)]
33+
#[allow(missing_docs)]
34+
pub enum Error {
35+
#[error("The chunk wasn't found in the file index")]
36+
NotFound(#[from] super::offset_by_kind::Error),
37+
#[error("The offsets into the file couldn't be represented by usize")]
38+
FileTooLarge,
4639
}
4740
}
4841

git-discover/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include = ["src/**/*", "CHANGELOG.md"]
1212
doctest = false
1313

1414
[dependencies]
15-
git-sec = { version = "^0.3.1", path = "../git-sec", features = ["thiserror"] }
15+
git-sec = { version = "^0.3.1", path = "../git-sec" }
1616
git-path = { version = "^0.4.2", path = "../git-path" }
1717
git-ref = { version = "^0.15.2", path = "../git-ref" }
1818
git-hash = { version = "^0.9.9", path = "../git-hash" }

git-object/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ git-actor = { version = "^0.11.3", path = "../git-actor" }
2828

2929
btoi = "0.4.2"
3030
itoa = "1.0.1"
31-
quick-error = "2.0.0"
31+
thiserror = "1.0.34"
3232
hex = "0.4.2"
3333
bstr = { version = "0.2.13", default-features = false, features = ["std", "unicode"] }
3434
nom = { version = "7", default-features = false, features = ["std"]}

git-object/src/data.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,16 @@ impl<'a> Data<'a> {
5151

5252
/// Types supporting object hash verification
5353
pub mod verify {
54-
use quick_error::quick_error;
5554

56-
quick_error! {
57-
/// Returned by [`crate::Data::verify_checksum()`]
58-
#[derive(Debug)]
59-
#[allow(missing_docs)]
60-
pub enum Error {
61-
ChecksumMismatch {desired: git_hash::ObjectId, actual: git_hash::ObjectId} {
62-
display("Object expected to have id {}, but actual id was {}", desired, actual)
63-
}
64-
}
55+
/// Returned by [`crate::Data::verify_checksum()`]
56+
#[derive(Debug, thiserror::Error)]
57+
#[allow(missing_docs)]
58+
pub enum Error {
59+
#[error("Object expected to have id {desired}, but actual id was {actual}")]
60+
ChecksumMismatch {
61+
desired: git_hash::ObjectId,
62+
actual: git_hash::ObjectId,
63+
},
6564
}
6665

6766
impl crate::Data<'_> {

git-object/src/encode.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
use std::io::{self, Write};
33

44
use bstr::{BString, ByteSlice};
5-
use quick_error::quick_error;
65

7-
quick_error! {
8-
#[derive(Debug)]
9-
enum Error {
10-
NewlineInHeaderValue(value: BString) {
11-
display("Newlines are not allowed in header values: {:?}", value)
12-
}
13-
EmptyValue {
14-
display("Header values must not be empty")
15-
}
16-
}
6+
/// An error returned when object encoding fails.
7+
#[derive(Debug, thiserror::Error)]
8+
#[allow(missing_docs)]
9+
pub enum Error {
10+
#[error("Newlines are not allowed in header values: {value:?}")]
11+
NewlineInHeaderValue { value: BString },
12+
#[error("Header values must not be empty")]
13+
EmptyValue,
1714
}
1815

1916
macro_rules! check {
@@ -78,7 +75,7 @@ pub(crate) fn header_field(name: &[u8], value: &[u8], out: impl io::Write) -> io
7875
return Err(Error::EmptyValue.into());
7976
}
8077
if value.find(NL).is_some() {
81-
return Err(Error::NewlineInHeaderValue(value.into()).into());
78+
return Err(Error::NewlineInHeaderValue { value: value.into() }.into());
8279
}
8380
trusted_header_field(name, value, out)
8481
}

git-object/src/kind.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
use std::fmt;
22

3-
use quick_error::quick_error;
4-
53
use crate::Kind;
64

7-
quick_error! {
8-
/// The Error used in [`Kind::from_bytes()`].
9-
#[derive(Debug, Clone)]
10-
#[allow(missing_docs)]
11-
pub enum Error {
12-
InvalidObjectKind(kind: crate::BString) {
13-
display("Unknown object kind: {:?}", kind)
14-
}
15-
}
5+
/// The Error used in [`Kind::from_bytes()`].
6+
#[derive(Debug, Clone, thiserror::Error)]
7+
#[allow(missing_docs)]
8+
pub enum Error {
9+
#[error("Unknown object kind: {kind:?}")]
10+
InvalidObjectKind { kind: bstr::BString },
1611
}
1712

1813
impl Kind {
@@ -23,7 +18,7 @@ impl Kind {
2318
b"blob" => Kind::Blob,
2419
b"commit" => Kind::Commit,
2520
b"tag" => Kind::Tag,
26-
_ => return Err(Error::InvalidObjectKind(s.into())),
21+
_ => return Err(Error::InvalidObjectKind { kind: s.into() }),
2722
})
2823
}
2924

git-object/src/lib.rs

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -336,28 +336,20 @@ pub mod decode {
336336
pub use _decode::{Error, ParseError, ParseErrorOwned};
337337
impl std::error::Error for Error {}
338338

339-
use quick_error::quick_error;
340-
quick_error! {
341-
/// Returned by [`loose_header()`]
342-
#[derive(Debug)]
343-
#[allow(missing_docs)]
344-
pub enum LooseHeaderDecodeError {
345-
ParseIntegerError(
346-
source: btoi::ParseIntegerError,
347-
message: &'static str,
348-
number: Vec<u8>
349-
) {
350-
display("{}: {:?}", message, std::str::from_utf8(number))
351-
}
352-
InvalidHeader(s: &'static str) {
353-
display("{}", s)
354-
}
355-
ObjectHeader(err: super::kind::Error) {
356-
display("The object header contained an unknown object kind.")
357-
from()
358-
source(err)
359-
}
360-
}
339+
/// Returned by [`loose_header()`]
340+
#[derive(Debug, thiserror::Error)]
341+
#[allow(missing_docs)]
342+
pub enum LooseHeaderDecodeError {
343+
#[error("{message}: {number:?}")]
344+
ParseIntegerError {
345+
source: btoi::ParseIntegerError,
346+
message: &'static str,
347+
number: bstr::BString,
348+
},
349+
#[error("{message}")]
350+
InvalidHeader { message: &'static str },
351+
#[error("The object header contained an unknown object kind.")]
352+
ObjectHeader(#[from] super::kind::Error),
361353
}
362354

363355
use bstr::ByteSlice;
@@ -367,18 +359,18 @@ pub mod decode {
367359
/// `size` is the uncompressed size of the payload in bytes.
368360
pub fn loose_header(input: &[u8]) -> Result<(super::Kind, usize, usize), LooseHeaderDecodeError> {
369361
use LooseHeaderDecodeError::*;
370-
let kind_end = input.find_byte(0x20).ok_or(InvalidHeader("Expected '<type> <size>'"))?;
362+
let kind_end = input.find_byte(0x20).ok_or(InvalidHeader {
363+
message: "Expected '<type> <size>'",
364+
})?;
371365
let kind = super::Kind::from_bytes(&input[..kind_end])?;
372-
let size_end = input
373-
.find_byte(0x0)
374-
.ok_or(InvalidHeader("Did not find 0 byte in header"))?;
366+
let size_end = input.find_byte(0x0).ok_or(InvalidHeader {
367+
message: "Did not find 0 byte in header",
368+
})?;
375369
let size_bytes = &input[kind_end + 1..size_end];
376-
let size = btoi::btoi(size_bytes).map_err(|source| {
377-
ParseIntegerError(
378-
source,
379-
"Object size in header could not be parsed",
380-
size_bytes.to_owned(),
381-
)
370+
let size = btoi::btoi(size_bytes).map_err(|source| ParseIntegerError {
371+
source,
372+
message: "Object size in header could not be parsed",
373+
number: size_bytes.into(),
382374
})?;
383375
Ok((kind, size, size_end + 1))
384376
}

git-object/src/object/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,18 @@ impl Object {
162162
}
163163
}
164164

165-
use quick_error::quick_error;
166-
167165
use crate::{
168166
decode::{loose_header, Error as DecodeError, LooseHeaderDecodeError},
169167
BlobRef, CommitRef, Kind, ObjectRef, TagRef, TreeRef,
170168
};
171169

172-
quick_error! {
173-
#[derive(Debug)]
174-
#[allow(missing_docs)]
175-
pub enum LooseDecodeError {
176-
InvalidHeader(err: LooseHeaderDecodeError) { from() }
177-
InvalidContent(err: DecodeError) { from() }
178-
}
170+
#[derive(Debug, thiserror::Error)]
171+
#[allow(missing_docs)]
172+
pub enum LooseDecodeError {
173+
#[error(transparent)]
174+
InvalidHeader(#[from] LooseHeaderDecodeError),
175+
#[error(transparent)]
176+
InvalidContent(#[from] DecodeError),
179177
}
180178

181179
impl<'a> ObjectRef<'a> {

0 commit comments

Comments
 (0)