Skip to content

Commit

Permalink
Merge branch 'btoi'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Feb 15, 2024
2 parents b8def77 + c5c69bd commit 5fc379d
Show file tree
Hide file tree
Showing 16 changed files with 432 additions and 39 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

13 changes: 9 additions & 4 deletions gix-actor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@ serde = ["dep:serde", "bstr/serde", "gix-date/serde"]
[dependencies]
gix-features = { version = "^0.38.0", path = "../gix-features", optional = true }
gix-date = { version = "^0.8.3", path = "../gix-date" }
gix-utils = { version = "^0.1.9", path = "../gix-utils" }

thiserror = "1.0.38"
btoi = "0.4.2"
bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"]}
bstr = { version = "1.3.0", default-features = false, features = [
"std",
"unicode",
] }
winnow = { version = "0.6.0", features = ["simd"] }
itoa = "1.0.1"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
serde = { version = "1.0.114", optional = true, default-features = false, features = [
"derive",
] }

document-features = { version = "0.2.0", optional = true }

[dev-dependencies]
pretty_assertions = "1.0.0"
gix-testtools = { path = "../tests/tools"}
gix-testtools = { path = "../tests/tools" }
gix-hash = { path = "../gix-hash" }

[package.metadata.docs.rs]
Expand Down
8 changes: 4 additions & 4 deletions gix-actor/src/signature/decode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub(crate) mod function {
use bstr::ByteSlice;
use btoi::btoi;
use gix_date::{time::Sign, OffsetInSeconds, SecondsSinceUnixEpoch, Time};
use gix_utils::btoi::to_signed;
use winnow::{
combinator::{alt, separated_pair, terminated},
error::{AddContext, ParserError, StrContext},
Expand All @@ -23,18 +23,18 @@ pub(crate) mod function {
b" ",
(
terminated(take_until(0.., SPACE), take(1usize))
.verify_map(|v| btoi::<SecondsSinceUnixEpoch>(v).ok())
.verify_map(|v| to_signed::<SecondsSinceUnixEpoch>(v).ok())
.context(StrContext::Expected("<timestamp>".into())),
alt((
take_while(1.., b'-').map(|_| Sign::Minus),
take_while(1.., b'+').map(|_| Sign::Plus),
))
.context(StrContext::Expected("+|-".into())),
take_while(2, AsChar::is_dec_digit)
.verify_map(|v| btoi::<OffsetInSeconds>(v).ok())
.verify_map(|v| to_signed::<OffsetInSeconds>(v).ok())
.context(StrContext::Expected("HH".into())),
take_while(1..=2, AsChar::is_dec_digit)
.verify_map(|v| btoi::<OffsetInSeconds>(v).ok())
.verify_map(|v| to_signed::<OffsetInSeconds>(v).ok())
.context(StrContext::Expected("MM".into())),
)
.map(|(time, sign, hours, minutes)| {
Expand Down
16 changes: 12 additions & 4 deletions gix-index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ test = true
serde = ["dep:serde", "smallvec/serde", "gix-hash/serde"]

[dependencies]
gix-features = { version = "^0.38.0", path = "../gix-features", features = ["rustsha1", "progress"] }
gix-features = { version = "^0.38.0", path = "../gix-features", features = [
"rustsha1",
"progress",
] }
gix-hash = { version = "^0.14.1", path = "../gix-hash" }
gix-bitmap = { version = "^0.2.10", path = "../gix-bitmap" }
gix-object = { version = "^0.41.0", path = "../gix-object" }
gix-traverse = { version = "^0.37.0", path = "../gix-traverse" }
gix-lock = { version = "^13.0.0", path = "../gix-lock" }
gix-fs = { version = "^0.10.0", path = "../gix-fs" }
gix-utils = { version = "^0.1.9", path = "../gix-utils" }

hashbrown = "0.14.3"
fnv = "1.0.7"
Expand All @@ -35,16 +39,20 @@ memmap2 = "0.9.0"
filetime = "0.2.15"
bstr = { version = "1.3.0", default-features = false }

serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"] }
serde = { version = "1.0.114", optional = true, default-features = false, features = [
"derive",
] }
smallvec = "1.7.0"
btoi = "0.4.3"
itoa = "1.0.3"
bitflags = "2"

document-features = { version = "0.2.0", optional = true }

[target.'cfg(not(windows))'.dependencies]
rustix = { version = "0.38.20", default-features = false, features = ["std", "fs"] }
rustix = { version = "0.38.20", default-features = false, features = [
"std",
"fs",
] }
libc = { version = "0.2.149" }

[package.metadata.docs.rs]
Expand Down
4 changes: 2 additions & 2 deletions gix-index/src/extension/tree/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ fn one_recursive(data: &[u8], hash_len: usize) -> Option<(Tree, &[u8])> {
let (path, data) = split_at_byte_exclusive(data, 0)?;

let (entry_count, data) = split_at_byte_exclusive(data, b' ')?;
let num_entries: i32 = btoi::btoi(entry_count).ok()?;
let num_entries: i32 = gix_utils::btoi::to_signed(entry_count).ok()?;

let (subtree_count, data) = split_at_byte_exclusive(data, b'\n')?;
let subtree_count: usize = btoi::btou(subtree_count).ok()?;
let subtree_count: usize = gix_utils::btoi::to_unsigned(subtree_count).ok()?;

let (id, mut data) = if num_entries >= 0 {
let (hash, data) = split_at_pos(data, hash_len)?;
Expand Down
27 changes: 20 additions & 7 deletions gix-object/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,49 @@ path = "./benches/decode_objects.rs"

[features]
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
serde = ["dep:serde", "bstr/serde", "smallvec/serde", "gix-hash/serde", "gix-actor/serde"]
serde = [
"dep:serde",
"bstr/serde",
"smallvec/serde",
"gix-hash/serde",
"gix-actor/serde",
]
## When parsing objects by default errors will only be available on the granularity of success or failure, and with the above flag enabled
## details information about the error location will be collected.
## Use it in applications which expect broken or invalid objects or for debugging purposes. Incorrectly formatted objects aren't at all
## common otherwise.
verbose-object-parsing-errors = ["winnow/std"]

[dependencies]
gix-features = { version = "^0.38.0", path = "../gix-features", features = ["rustsha1", "progress"] }
gix-features = { version = "^0.38.0", path = "../gix-features", features = [
"rustsha1",
"progress",
] }
gix-hash = { version = "^0.14.1", path = "../gix-hash" }
gix-validate = { version = "^0.8.3", path = "../gix-validate" }
gix-actor = { version = "^0.30.0", path = "../gix-actor" }
gix-date = { version = "^0.8.3", path = "../gix-date" }
gix-utils = { version = "^0.1.9", path = "../gix-utils" }

btoi = "0.4.2"
itoa = "1.0.1"
thiserror = "1.0.34"
bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"] }
bstr = { version = "1.3.0", default-features = false, features = [
"std",
"unicode",
] }
winnow = { version = "0.6.0", features = ["simd"] }
smallvec = { version = "1.4.0", features = ["write"] }
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
serde = { version = "1.0.114", optional = true, default-features = false, features = [
"derive",
] }

document-features = { version = "0.2.0", optional = true }

[dev-dependencies]
criterion = "0.5.1"
pretty_assertions = "1.0.0"
gix-testtools = { path = "../tests/tools"}
gix-testtools = { path = "../tests/tools" }

[package.metadata.docs.rs]
all-features = true
features = ["document-features"]

4 changes: 2 additions & 2 deletions gix-object/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ pub mod decode {
pub enum LooseHeaderDecodeError {
#[error("{message}: {number:?}")]
ParseIntegerError {
source: btoi::ParseIntegerError,
source: gix_utils::btoi::ParseIntegerError,
message: &'static str,
number: bstr::BString,
},
Expand All @@ -383,7 +383,7 @@ pub mod decode {
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 {
let size = gix_utils::btoi::to_signed(size_bytes).map_err(|source| ParseIntegerError {
source,
message: "Object size in header could not be parsed",
number: size_bytes.into(),
Expand Down
24 changes: 18 additions & 6 deletions gix-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ doctest = false
## If set, blocking command implementations are available and will use the blocking version of the `gix-transport` crate.
blocking-client = ["gix-transport/blocking-client", "maybe-async/is_sync"]
## As above, but provides async implementations instead.
async-client = ["gix-transport/async-client", "async-trait", "futures-io", "futures-lite"]
async-client = [
"gix-transport/async-client",
"async-trait",
"futures-io",
"futures-lite",
]

#! ### Other
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
Expand All @@ -40,17 +45,24 @@ path = "tests/async-protocol.rs"
required-features = ["async-client"]

[dependencies]
gix-features = { version = "^0.38.0", path = "../gix-features", features = ["progress"] }
gix-features = { version = "^0.38.0", path = "../gix-features", features = [
"progress",
] }
gix-transport = { version = "^0.41.0", path = "../gix-transport" }
gix-hash = { version = "^0.14.1", path = "../gix-hash" }
gix-date = { version = "^0.8.3", path = "../gix-date" }
gix-credentials = { version = "^0.24.0", path = "../gix-credentials" }
gix-utils = { version = "^0.1.9", path = "../gix-utils" }

thiserror = "1.0.32"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"] }
serde = { version = "1.0.114", optional = true, default-features = false, features = [
"derive",
] }
bstr = { version = "1.3.0", default-features = false, features = [
"std",
"unicode",
] }
winnow = { version = "0.6.0", features = ["simd"] }
btoi = "0.4.2"

# for async-client
async-trait = { version = "0.1.51", optional = true }
Expand All @@ -62,7 +74,7 @@ document-features = { version = "0.2.0", optional = true }

[dev-dependencies]
async-std = { version = "1.9.0", features = ["attributes"] }
gix-packetline = { path = "../gix-packetline" ,version = "^0.17.3" }
gix-packetline = { path = "../gix-packetline", version = "^0.17.3" }
gix-testtools = { path = "../tests/tools" }

[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion gix-protocol/src/remote_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> RemoteProgress<'a> {

fn parse_number(i: &mut &[u8]) -> PResult<usize, ()> {
take_till(0.., |c: u8| !c.is_ascii_digit())
.try_map(btoi::btoi)
.try_map(gix_utils::btoi::to_signed)
.parse_next(i)
}

Expand Down
5 changes: 3 additions & 2 deletions gix-quote/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ include = ["src/**/*", "LICENSE-*"]
doctest = false

[dependencies]
bstr = { version = "1.3.0", default-features = false, features = ["std"]}
gix-utils = { version = "^0.1.9", path = "../gix-utils" }

bstr = { version = "1.3.0", default-features = false, features = ["std"] }
thiserror = "1.0.38"
btoi = "0.4.2"
3 changes: 2 additions & 1 deletion gix-quote/src/ansi_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ pub fn undo(input: &BStr) -> Result<(Cow<'_, BStr>, usize), undo::Error> {
})?
.read_exact(&mut buf[1..])
.expect("impossible to fail as numbers match");
let byte = btoi::btou_radix(&buf, 8).map_err(|e| undo::Error::new(e, original))?;
let byte = gix_utils::btoi::to_unsigned_with_radix(&buf, 8)
.map_err(|e| undo::Error::new(e, original))?;
out.push(byte);
input = &input[2..];
consumed += 2;
Expand Down
2 changes: 1 addition & 1 deletion gix-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ rust-version = "1.65"
include = ["src/**/*", "LICENSE-*"]

[lib]
doctest = false
doctest = true

[features]
bstr = ["dep:bstr"]
Expand Down
Loading

0 comments on commit 5fc379d

Please sign in to comment.