diff options
Diffstat (limited to 'vendor/gix-utils')
-rw-r--r-- | vendor/gix-utils/.cargo-checksum.json | 1 | ||||
-rw-r--r-- | vendor/gix-utils/CHANGELOG.md | 71 | ||||
-rw-r--r-- | vendor/gix-utils/Cargo.toml | 26 | ||||
-rw-r--r-- | vendor/gix-utils/src/backoff.rs | 82 | ||||
-rw-r--r-- | vendor/gix-utils/src/lib.rs | 8 | ||||
-rw-r--r-- | vendor/gix-utils/tests/backoff/mod.rs | 56 | ||||
-rw-r--r-- | vendor/gix-utils/tests/utils.rs | 1 |
7 files changed, 245 insertions, 0 deletions
diff --git a/vendor/gix-utils/.cargo-checksum.json b/vendor/gix-utils/.cargo-checksum.json new file mode 100644 index 000000000..5506be995 --- /dev/null +++ b/vendor/gix-utils/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"CHANGELOG.md":"613071272fce41af5719f0ccc493eda3e0880bbbd8b7da478ce286051bf2931b","Cargo.toml":"4fb44a1f28d595cec0818b0974bfd827b0047cd6e4f9346262ad852b551f10af","src/backoff.rs":"13a27184095bb012e34e5f2fa6780080262c247d5812b40fe1bc5c6c0693fc04","src/lib.rs":"f3f0e3f90fe811a3ab340a3a2de2fc26dd77f6262c8518343abbd74f310296f7","tests/backoff/mod.rs":"c6ff28587f4c2b3ae3a76f4eddef1ac51bb8b52bde012a5571c6ac097da57b65","tests/utils.rs":"ab95e8f32f25da9d2d7af49c4f0572fe60199cbb908cd2b3d0aec28dce83cb91"},"package":"c10b69beac219acb8df673187a1f07dde2d74092f974fb3f9eb385aeb667c909"}
\ No newline at end of file diff --git a/vendor/gix-utils/CHANGELOG.md b/vendor/gix-utils/CHANGELOG.md new file mode 100644 index 000000000..4157809df --- /dev/null +++ b/vendor/gix-utils/CHANGELOG.md @@ -0,0 +1,71 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## 0.1.1 (2023-04-26) + +A maintenance release without user-facing changes. + +### Commit Statistics + +<csr-read-only-do-not-edit/> + + - 3 commits contributed to the release over the course of 1 calendar day. + - 7 days passed between releases. + - 0 commits were understood as [conventional](https://www.conventionalcommits.org). + - 0 issues like '(#ID)' were seen in commit messages + +### Commit Details + +<csr-read-only-do-not-edit/> + +<details><summary>view details</summary> + + * **Uncategorized** + - Prepare changelogs prior to release ([`30a1a71`](https://github.com/Byron/gitoxide/commit/30a1a71f36f24faac0e0b362ffdfedea7f9cdbf1)) + - Merge branch 'index-entries-attrs' ([`f37a930`](https://github.com/Byron/gitoxide/commit/f37a930aefa27e67f0b693ba9669cc26d49044fa)) + - Indicate that `gix-utils` is in early mode. ([`0f3b65f`](https://github.com/Byron/gitoxide/commit/0f3b65fdc210aded0a4e4ab72267e81141509122)) +</details> + +## 0.1.0 (2023-04-19) + +### New Features (BREAKING) + + - <csr-id-b83ee366a3c65c717beb587ad809268f1c54b8ad/> Rename `serde1` cargo feature to `serde` and use the weak-deps cargo capability. + With it it's possible to not automatically declare all optional dependencies externally visible + features, and thus re-use feature names that oterwise are also a crate name. + + Previously I thought that `serde1` is for future-proofing and supporting multiple serde versions + at the same time. However, it's most definitely a burden I wouldn't want anyway, so using + `serde` seems to be the way to go into the future. + +### Commit Statistics + +<csr-read-only-do-not-edit/> + + - 9 commits contributed to the release over the course of 5 calendar days. + - 1 commit was understood as [conventional](https://www.conventionalcommits.org). + - 1 unique issue was worked on: [#814](https://github.com/Byron/gitoxide/issues/814) + +### Commit Details + +<csr-read-only-do-not-edit/> + +<details><summary>view details</summary> + + * **[#814](https://github.com/Byron/gitoxide/issues/814)** + - Rename `serde1` cargo feature to `serde` and use the weak-deps cargo capability. ([`b83ee36`](https://github.com/Byron/gitoxide/commit/b83ee366a3c65c717beb587ad809268f1c54b8ad)) + * **Uncategorized** + - Release gix-utils v0.1.0, gix-hash v0.11.0, gix-date v0.5.0, gix-features v0.29.0, gix-actor v0.20.0, gix-object v0.29.0, gix-archive v0.1.0, gix-fs v0.1.0, safety bump 25 crates ([`8dbd0a6`](https://github.com/Byron/gitoxide/commit/8dbd0a60557a85acfa231800a058cbac0271a8cf)) + - Prepare changelog prior to release ([`7f06458`](https://github.com/Byron/gitoxide/commit/7f064583bd0e1b078df89a7750f5a25deb70f516)) + - Make fmt ([`5d2b5d0`](https://github.com/Byron/gitoxide/commit/5d2b5d02c3869e07dc2507a8f2519ee1df633df7)) + - Rename the serde1 feature to serde ([`19338d9`](https://github.com/Byron/gitoxide/commit/19338d934b6712b7d6bd3fa3b2e4189bf7e6c8a1)) + - Create new `gix-fs` crate to consolidate all filesystem utilities ([`f8cc33c`](https://github.com/Byron/gitoxide/commit/f8cc33cb372dd2b4bbe4a09cf4f64916681ab1dd)) + - Merge branch 'main' into dev ([`23ee47f`](https://github.com/Byron/gitoxide/commit/23ee47fb24c197f8437bd426544b2aa74e005bdc)) + - Merge branch 'worktree-stack' ([`3d47919`](https://github.com/Byron/gitoxide/commit/3d47919c1a2f83fc7c1fd7ae590d098057a22626)) + - A new create for filesystem specific utilities ([`ef8f405`](https://github.com/Byron/gitoxide/commit/ef8f405d06adf100bbe5f0b1fccbe8bb2c6fd650)) +</details> + diff --git a/vendor/gix-utils/Cargo.toml b/vendor/gix-utils/Cargo.toml new file mode 100644 index 000000000..4137617bd --- /dev/null +++ b/vendor/gix-utils/Cargo.toml @@ -0,0 +1,26 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2021" +rust-version = "1.64" +name = "gix-utils" +version = "0.1.1" +authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"] +description = "A crate with `gitoxide` utilities that don't need feature toggles" +license = "MIT/Apache-2.0" +repository = "https://github.com/Byron/gitoxide" + +[lib] +doctest = false + +[dependencies.fastrand] +version = "1.9.0" diff --git a/vendor/gix-utils/src/backoff.rs b/vendor/gix-utils/src/backoff.rs new file mode 100644 index 000000000..66d663024 --- /dev/null +++ b/vendor/gix-utils/src/backoff.rs @@ -0,0 +1,82 @@ +use std::time::Duration; + +fn randomize(backoff_ms: usize) -> usize { + let new_value = (fastrand::usize(750..=1250) * backoff_ms) / 1000; + if new_value == 0 { + backoff_ms + } else { + new_value + } +} + +/// A utility to calculate steps for exponential backoff similar to how it's done in `git`. +pub struct Exponential<Fn> { + multiplier: usize, + max_multiplier: usize, + exponent: usize, + transform: Fn, +} + +impl Default for Exponential<fn(usize) -> usize> { + fn default() -> Self { + Exponential { + multiplier: 1, + max_multiplier: 1000, + exponent: 1, + transform: std::convert::identity, + } + } +} + +impl Exponential<fn(usize) -> usize> { + /// Create a new exponential backoff iterator that backs off in randomized, ever increasing steps. + pub fn default_with_random() -> Self { + Exponential { + multiplier: 1, + max_multiplier: 1000, + exponent: 1, + transform: randomize, + } + } +} + +impl<Transform> Exponential<Transform> +where + Transform: Fn(usize) -> usize, +{ + /// Return an iterator that yields `Duration` instances to sleep on until `time` is depleted. + pub fn until_no_remaining(&mut self, time: Duration) -> impl Iterator<Item = Duration> + '_ { + let mut elapsed = Duration::default(); + let mut stop_next_iteration = false; + self.take_while(move |d| { + if stop_next_iteration { + false + } else { + elapsed += *d; + if elapsed > time { + stop_next_iteration = true; + } + true + } + }) + } +} + +impl<Transform> Iterator for Exponential<Transform> +where + Transform: Fn(usize) -> usize, +{ + type Item = Duration; + + fn next(&mut self) -> Option<Self::Item> { + let wait = Duration::from_millis((self.transform)(self.multiplier) as u64); + + self.multiplier += 2 * self.exponent + 1; + if self.multiplier > self.max_multiplier { + self.multiplier = self.max_multiplier; + } else { + self.exponent += 1; + } + Some(wait) + } +} diff --git a/vendor/gix-utils/src/lib.rs b/vendor/gix-utils/src/lib.rs new file mode 100644 index 000000000..4c9d99fa4 --- /dev/null +++ b/vendor/gix-utils/src/lib.rs @@ -0,0 +1,8 @@ +//! A crate with utilities that don't need feature toggles. +//! +//! If they would need feature toggles, they should be in `gix-features` instead. +#![deny(rust_2018_idioms, missing_docs)] +#![forbid(unsafe_code)] + +/// +pub mod backoff; diff --git a/vendor/gix-utils/tests/backoff/mod.rs b/vendor/gix-utils/tests/backoff/mod.rs new file mode 100644 index 000000000..a84ed7543 --- /dev/null +++ b/vendor/gix-utils/tests/backoff/mod.rs @@ -0,0 +1,56 @@ +use std::{convert::TryInto, time::Duration}; + +use gix_utils::backoff::Exponential; + +const EXPECTED_TILL_SECOND: &[usize] = &[ + 1usize, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, + 625, 676, 729, 784, 841, 900, 961, 1000, 1000, +]; + +#[test] +fn random_exponential_produces_values_in_the_correct_range() { + let mut num_identities = 0; + for (actual, expected) in Exponential::default_with_random().zip(EXPECTED_TILL_SECOND) { + let actual: usize = actual.as_millis().try_into().unwrap(); + if actual == *expected { + num_identities += 1; + } + assert!( + actual * 1000 >= (expected - 1) * 750, + "value too small: {actual} < {expected}" + ); + assert!( + actual * 1000 <= (expected + 1) * 1250, + "value too big: {actual} > {expected}" + ); + } + assert!( + num_identities < EXPECTED_TILL_SECOND.len(), + "too many untransformed values: {num_identities}" + ); +} + +#[test] +fn how_many_iterations_for_a_second_of_waittime() { + let max = Duration::from_millis(1000); + assert_eq!(Exponential::default().until_no_remaining(max).count(), 14); + assert_eq!( + Exponential::default() + .until_no_remaining(max) + .reduce(|acc, n| acc + n) + .unwrap(), + Duration::from_millis(1015), + "a little overshoot" + ); +} + +#[test] +fn output_with_default_settings() { + assert_eq!( + Exponential::default().take(33).collect::<Vec<_>>(), + EXPECTED_TILL_SECOND + .iter() + .map(|n| Duration::from_millis(*n as u64)) + .collect::<Vec<_>>() + ); +} diff --git a/vendor/gix-utils/tests/utils.rs b/vendor/gix-utils/tests/utils.rs new file mode 100644 index 000000000..ed38d3e98 --- /dev/null +++ b/vendor/gix-utils/tests/utils.rs @@ -0,0 +1 @@ +mod backoff; |