Skip to content

Commit aa857d9

Browse files
committed
Prepare centralization of bstr as optional component
1 parent f806647 commit aa857d9

File tree

18 files changed

+52
-50
lines changed

18 files changed

+52
-50
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ All feature toggles are additive.
201201

202202
* **with-serde**
203203
* Data structures implement `serde::Serialize` and `serde::Deserialize`
204+
* **with-miniserde**
205+
* Data structures implement `miniserde::Serialize` and `miniserde::Deserialize`
204206

205207
The features above are provided by the crates
206208

git-object/src/borrowed/commit.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::borrowed::{
44
util::{parse_header_field, parse_hex_sha1, parse_signature, NL},
55
Signature,
66
};
7-
use bstr::{BStr, ByteSlice};
7+
use crate::{ByteSlice, Bytes};
88
use nom::{
99
branch::alt,
1010
bytes::{complete::is_not, complete::tag},
@@ -17,18 +17,18 @@ use smallvec::SmallVec;
1717
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
1818
pub struct Commit<'data> {
1919
// SHA1 of tree object we point to
20-
pub tree: &'data BStr,
20+
pub tree: &'data Bytes,
2121
// SHA1 of each parent commit. Empty for first commit in repository.
22-
pub parents: SmallVec<[&'data BStr; 1]>,
22+
pub parents: SmallVec<[&'data Bytes; 1]>,
2323
pub author: Signature<'data>,
2424
pub committer: Signature<'data>,
2525
// The name of the message encoding, otherwise UTF-8 should be assumed.
26-
pub encoding: Option<&'data BStr>,
27-
pub message: &'data BStr,
28-
pub pgp_signature: Option<&'data BStr>,
26+
pub encoding: Option<&'data Bytes>,
27+
pub message: &'data Bytes,
28+
pub pgp_signature: Option<&'data Bytes>,
2929
}
3030

31-
pub fn parse_message(i: &[u8]) -> IResult<&[u8], &BStr, Error> {
31+
pub fn parse_message(i: &[u8]) -> IResult<&[u8], &Bytes, Error> {
3232
if i.is_empty() {
3333
// newline + [message]
3434
return Err(nom::Err::Error(Error::NomDetail(i.into(), "commit message is missing")));

git-object/src/borrowed/object/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use quick_error::quick_error;
33
quick_error! {
44
#[derive(Debug)]
55
pub enum Error {
6-
ParseIntegerError(msg: &'static str, number: bstr::BString, err: btoi::ParseIntegerError) {
6+
ParseIntegerError(msg: &'static str, number: crate::BytesOwned, err: btoi::ParseIntegerError) {
77
display("{}: {:?}", msg, number)
88
cause(err)
99
}
1010
Nom(err_msg: String) {
1111
display("{}", err_msg)
1212
}
13-
NomDetail(input: bstr::BString, msg: &'static str) {
13+
NomDetail(input: crate::BytesOwned, msg: &'static str) {
1414
display("{}: '{}' could not be parsed", msg, input)
1515
}
1616
ParseKindError(err: crate::types::Error) {

git-object/src/borrowed/object/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
mod error;
22
pub use error::Error;
33

4+
use crate::Bytes;
45
use crate::{
56
borrowed,
67
borrowed::{Blob, Commit, Tag, Tree},
78
Time,
89
};
9-
use bstr::BStr;
1010

1111
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
1212
pub struct Signature<'data> {
13-
pub name: &'data BStr,
14-
pub email: &'data BStr,
13+
pub name: &'data Bytes,
14+
pub email: &'data Bytes,
1515
pub time: Time,
1616
}
1717

git-object/src/borrowed/tag.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::borrowed::{
33
util::{parse_header_field, parse_hex_sha1, parse_signature, NL},
44
Signature,
55
};
6-
use bstr::{BStr, ByteSlice};
6+
use crate::{ByteSlice, Bytes};
77
use nom::{
88
branch::alt,
99
bytes::complete::{tag, take_until, take_while1},
@@ -18,13 +18,13 @@ use nom::{
1818
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
1919
pub struct Tag<'data> {
2020
// Target SHA1 in hex, always 40 lower case characters from 0-9 and a-f
21-
pub target: &'data BStr,
21+
pub target: &'data Bytes,
2222
// The name of the tag, e.g. "v1.0"
23-
pub name: &'data BStr,
23+
pub name: &'data Bytes,
2424
pub target_kind: crate::Kind,
25-
pub message: &'data BStr,
25+
pub message: &'data Bytes,
2626
pub signature: Signature<'data>,
27-
pub pgp_signature: Option<&'data BStr>,
27+
pub pgp_signature: Option<&'data Bytes>,
2828
}
2929

3030
fn parse(i: &[u8]) -> IResult<&[u8], Tag, Error> {
@@ -54,7 +54,7 @@ fn parse(i: &[u8]) -> IResult<&[u8], Tag, Error> {
5454
))
5555
}
5656

57-
fn parse_message(i: &[u8]) -> IResult<&[u8], (&BStr, Option<&BStr>), Error> {
57+
fn parse_message(i: &[u8]) -> IResult<&[u8], (&Bytes, Option<&Bytes>), Error> {
5858
const PGP_SIGNATURE_BEGIN: &[u8] = b"\n-----BEGIN PGP SIGNATURE-----";
5959
const PGP_SIGNATURE_END: &[u8] = b"-----END PGP SIGNATURE-----";
6060

git-object/src/borrowed/tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{borrowed::util::SPACE, borrowed::Error};
2-
use bstr::{BStr, ByteSlice};
2+
use crate::{ByteSlice, Bytes};
33
use nom::{
44
bytes::complete::{tag, take, take_while1, take_while_m_n},
55
character::is_digit,
@@ -18,7 +18,7 @@ pub struct Tree<'data> {
1818
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
1919
pub struct Entry<'data> {
2020
pub mode: Mode,
21-
pub filename: &'data BStr,
21+
pub filename: &'data Bytes,
2222
// 20 bytes SHA1
2323
pub oid: &'data [u8],
2424
}

git-object/src/borrowed/util/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::borrowed::{Error, Signature};
2-
use crate::{Sign, Time};
3-
use bstr::{BStr, ByteSlice};
1+
use crate::{
2+
borrowed::{Error, Signature},
3+
ByteSlice, Bytes, Sign, Time,
4+
};
45
use btoi::btoi;
56
use nom::{
67
branch::alt,
@@ -46,7 +47,7 @@ fn is_hex_digit_lc(b: u8) -> bool {
4647
}
4748
}
4849

49-
pub(crate) fn parse_hex_sha1(i: &[u8]) -> IResult<&[u8], &BStr, Error> {
50+
pub(crate) fn parse_hex_sha1(i: &[u8]) -> IResult<&[u8], &Bytes, Error> {
5051
take_while_m_n(40usize, 40, is_hex_digit_lc)(i).map(|(i, o)| (i, o.as_bstr()))
5152
}
5253

git-object/src/borrowed/util/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
mod parse_signature {
22
use crate::borrowed::util::parse_signature;
33
use crate::borrowed::Signature;
4+
use crate::ByteSlice;
45
use crate::{Sign, Time};
5-
use bstr::ByteSlice;
66

77
fn signature(name: &'static str, email: &'static str, time: u32, sign: Sign, offset: i32) -> Signature<'static> {
88
Signature {

git-object/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#![forbid(unsafe_code)]
22

3+
pub type BytesOwned = bstr::BString;
4+
pub type Bytes = bstr::BStr;
5+
pub use bstr::ByteSlice;
6+
37
pub mod borrowed;
48
mod types;
59

git-object/src/types.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
use bstr::ByteSlice;
2-
use nom::lib::std::fmt::Formatter;
3-
use nom::lib::std::ops::Deref;
1+
use crate::ByteSlice;
2+
use nom::{lib::std::fmt::Formatter, lib::std::ops::Deref};
43
use quick_error::quick_error;
54

6-
#[cfg(feature = "with-serde")]
7-
use serde::{Deserialize, Serialize};
8-
95
#[cfg(feature = "with-miniserde")]
106
use miniserde::{Deserialize as MiniDeserialize, Serialize as MiniSerialize};
7+
#[cfg(feature = "with-serde")]
8+
use serde::{Deserialize, Serialize};
119

1210
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
1311
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
@@ -93,7 +91,7 @@ pub enum Kind {
9391
quick_error! {
9492
#[derive(Debug)]
9593
pub enum Error {
96-
InvalidObjectKind(kind: bstr::BString) {
94+
InvalidObjectKind(kind: crate::BytesOwned) {
9795
display("Unknown object kind: {:?}", std::str::from_utf8(&kind))
9896
}
9997
}

0 commit comments

Comments
 (0)