summaryrefslogtreecommitdiffstats
path: root/vendor/gix-packetline/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/gix-packetline/src
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-packetline/src')
-rw-r--r--vendor/gix-packetline/src/decode.rs2
-rw-r--r--vendor/gix-packetline/src/lib.rs10
-rw-r--r--vendor/gix-packetline/src/read/async_io.rs11
-rw-r--r--vendor/gix-packetline/src/read/blocking_io.rs12
-rw-r--r--vendor/gix-packetline/src/read/mod.rs9
-rw-r--r--vendor/gix-packetline/src/read/sidebands/async_io.rs36
-rw-r--r--vendor/gix-packetline/src/read/sidebands/blocking_io.rs58
7 files changed, 95 insertions, 43 deletions
diff --git a/vendor/gix-packetline/src/decode.rs b/vendor/gix-packetline/src/decode.rs
index bb3b0a2aa..b01087a1c 100644
--- a/vendor/gix-packetline/src/decode.rs
+++ b/vendor/gix-packetline/src/decode.rs
@@ -43,7 +43,7 @@ pub enum Stream<'a> {
/// The amount of bytes consumed from input
bytes_consumed: usize,
},
- /// A packet line could not yet be parsed to to missing bytes
+ /// A packet line could not yet be parsed due to missing bytes
Incomplete {
/// The amount of additional bytes needed for the parsing to complete
bytes_needed: usize,
diff --git a/vendor/gix-packetline/src/lib.rs b/vendor/gix-packetline/src/lib.rs
index 69ac3da33..c5dce1c66 100644
--- a/vendor/gix-packetline/src/lib.rs
+++ b/vendor/gix-packetline/src/lib.rs
@@ -19,7 +19,7 @@ const ERR_PREFIX: &[u8] = b"ERR ";
/// One of three side-band types allowing to multiplex information over a single connection.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
-#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Channel {
/// The usable data itself in any format.
Data = 1,
@@ -43,7 +43,7 @@ pub use write::blocking_io::Writer;
/// A borrowed packet line as it refers to a slice of data by reference.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
-#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PacketLineRef<'a> {
/// A chunk of raw data.
Data(&'a [u8]),
@@ -57,17 +57,17 @@ pub enum PacketLineRef<'a> {
/// A packet line representing an Error in a side-band channel.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
-#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ErrorRef<'a>(pub &'a [u8]);
/// A packet line representing text, which may include a trailing newline.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
-#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TextRef<'a>(pub &'a [u8]);
/// A band in a side-band channel.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
-#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum BandRef<'a> {
/// A band carrying data.
Data(&'a [u8]),
diff --git a/vendor/gix-packetline/src/read/async_io.rs b/vendor/gix-packetline/src/read/async_io.rs
index e0d53d397..bb4dcf2c1 100644
--- a/vendor/gix-packetline/src/read/async_io.rs
+++ b/vendor/gix-packetline/src/read/async_io.rs
@@ -6,7 +6,7 @@ use futures_lite::AsyncReadExt;
use crate::{
decode,
- read::{ExhaustiveOutcome, WithSidebands},
+ read::{ExhaustiveOutcome, ProgressAction, WithSidebands},
PacketLineRef, StreamingPeekableIter, MAX_LINE_LEN, U16_HEX_BYTES,
};
@@ -150,7 +150,8 @@ where
/// Same as [`as_read_with_sidebands(…)`][StreamingPeekableIter::as_read_with_sidebands()], but for channels without side band support.
///
/// Due to the preconfigured function type this method can be called without 'turbofish'.
- pub fn as_read(&mut self) -> WithSidebands<'_, T, fn(bool, &[u8])> {
+ #[allow(clippy::type_complexity)]
+ pub fn as_read(&mut self) -> WithSidebands<'_, T, fn(bool, &[u8]) -> ProgressAction> {
WithSidebands::new(self)
}
@@ -161,7 +162,7 @@ where
/// being true in case the `text` is to be interpreted as error.
///
/// _Please note_ that side bands need to be negotiated with the server.
- pub fn as_read_with_sidebands<F: FnMut(bool, &[u8]) + Unpin>(
+ pub fn as_read_with_sidebands<F: FnMut(bool, &[u8]) -> ProgressAction + Unpin>(
&mut self,
handle_progress: F,
) -> WithSidebands<'_, T, F> {
@@ -172,7 +173,9 @@ where
///
/// The type parameter `F` needs to be configured for this method to be callable using the 'turbofish' operator.
/// Use [`as_read()`][StreamingPeekableIter::as_read()].
- pub fn as_read_without_sidebands<F: FnMut(bool, &[u8]) + Unpin>(&mut self) -> WithSidebands<'_, T, F> {
+ pub fn as_read_without_sidebands<F: FnMut(bool, &[u8]) -> ProgressAction + Unpin>(
+ &mut self,
+ ) -> WithSidebands<'_, T, F> {
WithSidebands::without_progress_handler(self)
}
}
diff --git a/vendor/gix-packetline/src/read/blocking_io.rs b/vendor/gix-packetline/src/read/blocking_io.rs
index 7465c1603..6af660b7f 100644
--- a/vendor/gix-packetline/src/read/blocking_io.rs
+++ b/vendor/gix-packetline/src/read/blocking_io.rs
@@ -4,7 +4,7 @@ use bstr::ByteSlice;
use crate::{
decode,
- read::{ExhaustiveOutcome, WithSidebands},
+ read::{ExhaustiveOutcome, ProgressAction, WithSidebands},
PacketLineRef, StreamingPeekableIter, MAX_LINE_LEN, U16_HEX_BYTES,
};
@@ -146,7 +146,10 @@ where
/// being true in case the `text` is to be interpreted as error.
///
/// _Please note_ that side bands need to be negotiated with the server.
- pub fn as_read_with_sidebands<F: FnMut(bool, &[u8])>(&mut self, handle_progress: F) -> WithSidebands<'_, T, F> {
+ pub fn as_read_with_sidebands<F: FnMut(bool, &[u8]) -> ProgressAction>(
+ &mut self,
+ handle_progress: F,
+ ) -> WithSidebands<'_, T, F> {
WithSidebands::with_progress_handler(self, handle_progress)
}
@@ -154,14 +157,15 @@ where
///
/// The type parameter `F` needs to be configured for this method to be callable using the 'turbofish' operator.
/// Use [`as_read()`][StreamingPeekableIter::as_read()].
- pub fn as_read_without_sidebands<F: FnMut(bool, &[u8])>(&mut self) -> WithSidebands<'_, T, F> {
+ pub fn as_read_without_sidebands<F: FnMut(bool, &[u8]) -> ProgressAction>(&mut self) -> WithSidebands<'_, T, F> {
WithSidebands::without_progress_handler(self)
}
/// Same as [`as_read_with_sidebands(…)`][StreamingPeekableIter::as_read_with_sidebands()], but for channels without side band support.
///
/// Due to the preconfigured function type this method can be called without 'turbofish'.
- pub fn as_read(&mut self) -> WithSidebands<'_, T, fn(bool, &[u8])> {
+ #[allow(clippy::type_complexity)]
+ pub fn as_read(&mut self) -> WithSidebands<'_, T, fn(bool, &[u8]) -> ProgressAction> {
WithSidebands::new(self)
}
}
diff --git a/vendor/gix-packetline/src/read/mod.rs b/vendor/gix-packetline/src/read/mod.rs
index 5e01fde87..e06b90d13 100644
--- a/vendor/gix-packetline/src/read/mod.rs
+++ b/vendor/gix-packetline/src/read/mod.rs
@@ -2,6 +2,15 @@
use crate::MAX_LINE_LEN;
use crate::{PacketLineRef, StreamingPeekableIter, U16_HEX_BYTES};
+/// Allow the read-progress handler to determine how to continue.
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub enum ProgressAction {
+ /// Continue reading the next progress if available.
+ Continue,
+ /// Abort all IO even if more would be available, claiming the operation was interrupted.
+ Interrupt,
+}
+
#[cfg(any(feature = "blocking-io", feature = "async-io"))]
type ExhaustiveOutcome<'a> = (
bool, // is_done
diff --git a/vendor/gix-packetline/src/read/sidebands/async_io.rs b/vendor/gix-packetline/src/read/sidebands/async_io.rs
index c8d009ec4..96973a36f 100644
--- a/vendor/gix-packetline/src/read/sidebands/async_io.rs
+++ b/vendor/gix-packetline/src/read/sidebands/async_io.rs
@@ -7,7 +7,7 @@ use std::{
use futures_io::{AsyncBufRead, AsyncRead};
use futures_lite::ready;
-use crate::{decode, BandRef, PacketLineRef, StreamingPeekableIter, TextRef, U16_HEX_BYTES};
+use crate::{decode, read::ProgressAction, BandRef, PacketLineRef, StreamingPeekableIter, TextRef, U16_HEX_BYTES};
type ReadLineResult<'a> = Option<std::io::Result<Result<PacketLineRef<'a>, decode::Error>>>;
/// An implementor of [`AsyncBufRead`] yielding packet lines on each call to [`read_line()`][AsyncBufRead::read_line()].
@@ -37,7 +37,7 @@ where
}
}
-impl<'a, T> WithSidebands<'a, T, fn(bool, &[u8])>
+impl<'a, T> WithSidebands<'a, T, fn(bool, &[u8]) -> ProgressAction>
where
T: AsyncRead,
{
@@ -93,7 +93,7 @@ mod tests {
impl<'a, T, F> WithSidebands<'a, T, F>
where
T: AsyncRead + Unpin,
- F: FnMut(bool, &[u8]) + Unpin,
+ F: FnMut(bool, &[u8]) -> ProgressAction + Unpin,
{
/// Create a new instance with the given `parent` provider and the `handle_progress` function.
///
@@ -170,7 +170,7 @@ where
}
/// Read a packet line as string line.
- pub fn read_line<'b>(&'b mut self, buf: &'b mut String) -> ReadLineFuture<'a, 'b, T, F> {
+ pub fn read_line_to_string<'b>(&'b mut self, buf: &'b mut String) -> ReadLineFuture<'a, 'b, T, F> {
ReadLineFuture { parent: self, buf }
}
@@ -201,7 +201,7 @@ pub struct ReadDataLineFuture<'a, 'b, T: AsyncRead, F> {
impl<'a, 'b, T, F> Future for ReadDataLineFuture<'a, 'b, T, F>
where
T: AsyncRead + Unpin,
- F: FnMut(bool, &[u8]) + Unpin,
+ F: FnMut(bool, &[u8]) -> ProgressAction + Unpin,
{
type Output = std::io::Result<usize>;
@@ -228,7 +228,7 @@ pub struct ReadLineFuture<'a, 'b, T: AsyncRead, F> {
impl<'a, 'b, T, F> Future for ReadLineFuture<'a, 'b, T, F>
where
T: AsyncRead + Unpin,
- F: FnMut(bool, &[u8]) + Unpin,
+ F: FnMut(bool, &[u8]) -> ProgressAction + Unpin,
{
type Output = std::io::Result<usize>;
@@ -251,7 +251,7 @@ where
impl<'a, T, F> AsyncBufRead for WithSidebands<'a, T, F>
where
T: AsyncRead + Unpin,
- F: FnMut(bool, &[u8]) + Unpin,
+ F: FnMut(bool, &[u8]) -> ProgressAction + Unpin,
{
fn poll_fill_buf(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<&[u8]>> {
use std::io;
@@ -310,11 +310,27 @@ where
}
BandRef::Progress(d) => {
let text = TextRef::from(d).0;
- handle_progress(false, text);
+ match handle_progress(false, text) {
+ ProgressAction::Continue => {}
+ ProgressAction::Interrupt => {
+ return Poll::Ready(Err(io::Error::new(
+ std::io::ErrorKind::Other,
+ "interrupted by user",
+ )))
+ }
+ };
}
BandRef::Error(d) => {
let text = TextRef::from(d).0;
- handle_progress(true, text);
+ match handle_progress(true, text) {
+ ProgressAction::Continue => {}
+ ProgressAction::Interrupt => {
+ return Poll::Ready(Err(io::Error::new(
+ io::ErrorKind::Other,
+ "interrupted by user",
+ )))
+ }
+ };
}
};
}
@@ -353,7 +369,7 @@ where
impl<'a, T, F> AsyncRead for WithSidebands<'a, T, F>
where
T: AsyncRead + Unpin,
- F: FnMut(bool, &[u8]) + Unpin,
+ F: FnMut(bool, &[u8]) -> ProgressAction + Unpin,
{
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<std::io::Result<usize>> {
let nread = {
diff --git a/vendor/gix-packetline/src/read/sidebands/blocking_io.rs b/vendor/gix-packetline/src/read/sidebands/blocking_io.rs
index ea67dc09c..20c4a2bce 100644
--- a/vendor/gix-packetline/src/read/sidebands/blocking_io.rs
+++ b/vendor/gix-packetline/src/read/sidebands/blocking_io.rs
@@ -1,6 +1,6 @@
use std::{io, io::BufRead};
-use crate::{BandRef, PacketLineRef, StreamingPeekableIter, TextRef, U16_HEX_BYTES};
+use crate::{read::ProgressAction, BandRef, PacketLineRef, StreamingPeekableIter, TextRef, U16_HEX_BYTES};
/// An implementor of [`BufRead`][io::BufRead] yielding packet lines on each call to [`read_line()`][io::BufRead::read_line()].
/// It's also possible to hide the underlying packet lines using the [`Read`][io::Read] implementation which is useful
@@ -24,7 +24,7 @@ where
}
}
-impl<'a, T> WithSidebands<'a, T, fn(bool, &[u8])>
+impl<'a, T> WithSidebands<'a, T, fn(bool, &[u8]) -> ProgressAction>
where
T: io::Read,
{
@@ -42,7 +42,7 @@ where
impl<'a, T, F> WithSidebands<'a, T, F>
where
T: io::Read,
- F: FnMut(bool, &[u8]),
+ F: FnMut(bool, &[u8]) -> ProgressAction,
{
/// Create a new instance with the given `parent` provider and the `handle_progress` function.
///
@@ -109,12 +109,28 @@ where
);
self.parent.read_line()
}
+
+ /// Like `BufRead::read_line()`, but will only read one packetline at a time.
+ ///
+ /// It will also be easier to call as sometimes it's unclear which implementation we get on a type like this with
+ /// plenty of generic parameters.
+ pub fn read_line_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
+ assert_eq!(
+ self.cap, 0,
+ "we don't support partial buffers right now - read-line must be used consistently"
+ );
+ let line = std::str::from_utf8(self.fill_buf()?).map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
+ buf.push_str(line);
+ let bytes = line.len();
+ self.cap = 0;
+ Ok(bytes)
+ }
}
impl<'a, T, F> BufRead for WithSidebands<'a, T, F>
where
T: io::Read,
- F: FnMut(bool, &[u8]),
+ F: FnMut(bool, &[u8]) -> ProgressAction,
{
fn fill_buf(&mut self) -> io::Result<&[u8]> {
if self.pos >= self.cap {
@@ -138,11 +154,27 @@ where
}
BandRef::Progress(d) => {
let text = TextRef::from(d).0;
- handle_progress(false, text);
+ match handle_progress(false, text) {
+ ProgressAction::Continue => {}
+ ProgressAction::Interrupt => {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::Other,
+ "interrupted by user",
+ ))
+ }
+ };
}
BandRef::Error(d) => {
let text = TextRef::from(d).0;
- handle_progress(true, text);
+ match handle_progress(true, text) {
+ ProgressAction::Continue => {}
+ ProgressAction::Interrupt => {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::Other,
+ "interrupted by user",
+ ))
+ }
+ };
}
};
}
@@ -168,24 +200,12 @@ where
fn consume(&mut self, amt: usize) {
self.pos = std::cmp::min(self.pos + amt, self.cap);
}
-
- fn read_line(&mut self, buf: &mut String) -> io::Result<usize> {
- assert_eq!(
- self.cap, 0,
- "we don't support partial buffers right now - read-line must be used consistently"
- );
- let line = std::str::from_utf8(self.fill_buf()?).map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
- buf.push_str(line);
- let bytes = line.len();
- self.cap = 0;
- Ok(bytes)
- }
}
impl<'a, T, F> io::Read for WithSidebands<'a, T, F>
where
T: io::Read,
- F: FnMut(bool, &[u8]),
+ F: FnMut(bool, &[u8]) -> ProgressAction,
{
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let nread = {