diff options
Diffstat (limited to 'vendor/gix-protocol/src')
-rw-r--r-- | vendor/gix-protocol/src/fetch/delegate.rs | 2 | ||||
-rw-r--r-- | vendor/gix-protocol/src/fetch/response/async_io.rs | 13 | ||||
-rw-r--r-- | vendor/gix-protocol/src/fetch/response/blocking_io.rs | 8 | ||||
-rw-r--r-- | vendor/gix-protocol/src/fetch/response/mod.rs | 6 | ||||
-rw-r--r-- | vendor/gix-protocol/src/fetch_fn.rs | 13 | ||||
-rw-r--r-- | vendor/gix-protocol/src/handshake/function.rs | 2 | ||||
-rw-r--r-- | vendor/gix-protocol/src/handshake/mod.rs | 6 | ||||
-rw-r--r-- | vendor/gix-protocol/src/handshake/refs/tests.rs | 27 | ||||
-rw-r--r-- | vendor/gix-protocol/src/remote_progress.rs | 4 |
9 files changed, 56 insertions, 25 deletions
diff --git a/vendor/gix-protocol/src/fetch/delegate.rs b/vendor/gix-protocol/src/fetch/delegate.rs index b0db2f833..d4b900f66 100644 --- a/vendor/gix-protocol/src/fetch/delegate.rs +++ b/vendor/gix-protocol/src/fetch/delegate.rs @@ -86,7 +86,7 @@ pub trait DelegateBlocking { /// with each call to `negotiate` to find the common base(s). /// /// Note that you should not `want` and object that you already have. - /// `refs` are the the tips of on the server side, effectively the latest objects _they_ have. + /// `refs` are the tips of on the server side, effectively the latest objects _they_ have. /// /// Return `Action::Close` if you know that there are no `haves` on your end to allow the server to send all of its objects /// as is the case during initial clones. diff --git a/vendor/gix-protocol/src/fetch/response/async_io.rs b/vendor/gix-protocol/src/fetch/response/async_io.rs index 7b00d843c..550ed46b6 100644 --- a/vendor/gix-protocol/src/fetch/response/async_io.rs +++ b/vendor/gix-protocol/src/fetch/response/async_io.rs @@ -1,6 +1,5 @@ use std::io; -use futures_lite::AsyncBufReadExt; use gix_transport::{client, Protocol}; use crate::fetch::{ @@ -16,7 +15,7 @@ async fn parse_v2_section<T>( parse: impl Fn(&str) -> Result<T, response::Error>, ) -> Result<bool, response::Error> { line.clear(); - while reader.read_line(line).await? != 0 { + while reader.readline_str(line).await? != 0 { res.push(parse(line)?); line.clear(); } @@ -62,7 +61,7 @@ impl Response { Some(client::MessageKind::Flush), "If this isn't a flush packet, we don't know what's going on" ); - reader.read_line(&mut line).await?; + reader.readline_str(&mut line).await?; reader.reset(Protocol::V1); match reader.peek_data_line().await { Some(Ok(Ok(line))) => String::from_utf8_lossy(line), @@ -76,7 +75,11 @@ impl Response { if Response::parse_v1_ack_or_shallow_or_assume_pack(&mut acks, &mut shallows, &peeked_line) { break 'lines true; } - assert_ne!(reader.read_line(&mut line).await?, 0, "consuming a peeked line works"); + assert_ne!( + reader.readline_str(&mut line).await?, + 0, + "consuming a peeked line works" + ); }; Ok(Response { acks, @@ -94,7 +97,7 @@ impl Response { let mut wanted_refs = Vec::<WantedRef>::new(); let has_pack = 'section: loop { line.clear(); - if reader.read_line(&mut line).await? == 0 { + if reader.readline_str(&mut line).await? == 0 { return Err(response::Error::Io(io::Error::new( io::ErrorKind::UnexpectedEof, "Could not read message headline", diff --git a/vendor/gix-protocol/src/fetch/response/blocking_io.rs b/vendor/gix-protocol/src/fetch/response/blocking_io.rs index ca79724e2..7a3f2deb3 100644 --- a/vendor/gix-protocol/src/fetch/response/blocking_io.rs +++ b/vendor/gix-protocol/src/fetch/response/blocking_io.rs @@ -15,7 +15,7 @@ fn parse_v2_section<T>( parse: impl Fn(&str) -> Result<T, response::Error>, ) -> Result<bool, response::Error> { line.clear(); - while reader.read_line(line)? != 0 { + while reader.readline_str(line)? != 0 { res.push(parse(line)?); line.clear(); } @@ -61,7 +61,7 @@ impl Response { Some(client::MessageKind::Flush), "If this isn't a flush packet, we don't know what's going on" ); - reader.read_line(&mut line)?; + reader.readline_str(&mut line)?; reader.reset(Protocol::V1); match reader.peek_data_line() { Some(Ok(Ok(line))) => String::from_utf8_lossy(line), @@ -75,7 +75,7 @@ impl Response { if Response::parse_v1_ack_or_shallow_or_assume_pack(&mut acks, &mut shallows, &peeked_line) { break 'lines true; } - assert_ne!(reader.read_line(&mut line)?, 0, "consuming a peeked line works"); + assert_ne!(reader.readline_str(&mut line)?, 0, "consuming a peeked line works"); }; Ok(Response { acks, @@ -93,7 +93,7 @@ impl Response { let mut wanted_refs = Vec::<WantedRef>::new(); let has_pack = 'section: loop { line.clear(); - if reader.read_line(&mut line)? == 0 { + if reader.readline_str(&mut line)? == 0 { return Err(response::Error::Io(io::Error::new( io::ErrorKind::UnexpectedEof, "Could not read message headline", diff --git a/vendor/gix-protocol/src/fetch/response/mod.rs b/vendor/gix-protocol/src/fetch/response/mod.rs index 8c99cc872..bfb4beb83 100644 --- a/vendor/gix-protocol/src/fetch/response/mod.rs +++ b/vendor/gix-protocol/src/fetch/response/mod.rs @@ -49,7 +49,7 @@ impl gix_transport::IsSpuriousError for Error { /// An 'ACK' line received from the server. #[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 Acknowledgement { /// The contained `id` is in common. Common(gix_hash::ObjectId), @@ -61,7 +61,7 @@ pub enum Acknowledgement { /// A shallow line received from the server. #[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 ShallowUpdate { /// Shallow the given `id`. Shallow(gix_hash::ObjectId), @@ -71,7 +71,7 @@ pub enum ShallowUpdate { /// A wanted-ref line received from the server. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct WantedRef { /// The object id of the wanted ref, as seen by the server. pub id: gix_hash::ObjectId, diff --git a/vendor/gix-protocol/src/fetch_fn.rs b/vendor/gix-protocol/src/fetch_fn.rs index 5b2d214ae..5899ed95f 100644 --- a/vendor/gix-protocol/src/fetch_fn.rs +++ b/vendor/gix-protocol/src/fetch_fn.rs @@ -11,6 +11,7 @@ use crate::{ }; /// A way to indicate how to treat the connection underlying the transport, potentially allowing to reuse it. +#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum FetchConnection { /// Use this variant if server should be informed that the operation is completed and no further commands will be issued /// at the end of the fetch operation or after deciding that no fetch operation should happen after references were listed. @@ -19,6 +20,7 @@ pub enum FetchConnection { /// Generally it only applies when using persistent transports. /// /// In most explicit client side failure modes the end-of-operation' notification will be sent to the server automatically. + #[default] TerminateOnSuccessfulCompletion, /// Indicate that persistent transport connections can be reused by _not_ sending an 'end-of-operation' notification to the server. @@ -31,12 +33,6 @@ pub enum FetchConnection { AllowReuse, } -impl Default for FetchConnection { - fn default() -> Self { - FetchConnection::TerminateOnSuccessfulCompletion - } -} - /// Perform a 'fetch' operation with the server using `transport`, with `delegate` handling all server interactions. /// **Note** that `delegate` has blocking operations and thus this entire call should be on an executor which can handle /// that. This could be the current thread blocking, or another thread. @@ -49,6 +45,8 @@ impl Default for FetchConnection { /// _Note_ that depending on the `delegate`, the actual action performed can be `ls-refs`, `clone` or `fetch`. #[allow(clippy::result_large_err)] #[maybe_async] +// TODO: remove this without losing test coverage - we have the same but better in `gix` and it's +// not really worth it to maintain the delegates here. pub async fn fetch<F, D, T, P>( mut transport: T, mut delegate: D, @@ -162,7 +160,8 @@ where reader.set_progress_handler(Some(Box::new({ let mut remote_progress = progress.add_child("remote"); move |is_err: bool, data: &[u8]| { - crate::RemoteProgress::translate_to_progress(is_err, data, &mut remote_progress) + crate::RemoteProgress::translate_to_progress(is_err, data, &mut remote_progress); + gix_transport::packetline::read::ProgressAction::Continue } }) as gix_transport::client::HandleProgress)); } diff --git a/vendor/gix-protocol/src/handshake/function.rs b/vendor/gix-protocol/src/handshake/function.rs index c56824cca..1206ee363 100644 --- a/vendor/gix-protocol/src/handshake/function.rs +++ b/vendor/gix-protocol/src/handshake/function.rs @@ -46,7 +46,7 @@ where progress.set_name("authentication"); let credentials::protocol::Outcome { identity, next } = authenticate(credentials::helper::Action::get_for_url(url.clone()))? - .expect("FILL provides an identity or errors"); + .ok_or(Error::EmptyCredentials)?; transport.set_identity(identity)?; progress.step(); progress.set_name("handshake (authenticated)"); diff --git a/vendor/gix-protocol/src/handshake/mod.rs b/vendor/gix-protocol/src/handshake/mod.rs index 4e0741012..6d70ed145 100644 --- a/vendor/gix-protocol/src/handshake/mod.rs +++ b/vendor/gix-protocol/src/handshake/mod.rs @@ -3,7 +3,7 @@ use gix_transport::client::Capabilities; /// A git reference, commonly referred to as 'ref', as returned by a git server before sending a pack. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Ref { /// A ref pointing to a `tag` object, which in turns points to an `object`, usually a commit Peeled { @@ -46,7 +46,7 @@ pub enum Ref { /// The result of the [`handshake()`][super::handshake()] function. #[derive(Default, Debug, Clone)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Outcome { /// The protocol version the server responded with. It might have downgraded the desired version. pub server_protocol_version: gix_transport::Protocol, @@ -68,6 +68,8 @@ mod error { pub enum Error { #[error("Failed to obtain credentials")] Credentials(#[from] credentials::protocol::Error), + #[error("No credentials were returned at all as if the credential helper isn't functioning unknowingly")] + EmptyCredentials, #[error("Credentials provided for \"{url}\" were not accepted by the remote")] InvalidCredentials { url: BString, source: std::io::Error }, #[error(transparent)] diff --git a/vendor/gix-protocol/src/handshake/refs/tests.rs b/vendor/gix-protocol/src/handshake/refs/tests.rs index a7c9171a5..7d995da5c 100644 --- a/vendor/gix-protocol/src/handshake/refs/tests.rs +++ b/vendor/gix-protocol/src/handshake/refs/tests.rs @@ -170,6 +170,20 @@ impl<'a> gix_transport::client::ReadlineBufRead for Fixture<'a> { self.0 = lines.as_bytes(); Some(Ok(Ok(gix_packetline::PacketLineRef::Data(res)))) } + + fn readline_str(&mut self, line: &mut String) -> std::io::Result<usize> { + use bstr::{BStr, ByteSlice}; + let bytes: &BStr = self.0.into(); + let mut lines = bytes.lines(); + let res = match lines.next() { + None => return Ok(0), + Some(line) => line, + }; + self.0 = lines.as_bytes(); + let len = res.len(); + line.push_str(res.to_str().expect("valid UTF8 in fixture")); + Ok(len) + } } #[cfg(feature = "async-client")] @@ -220,4 +234,17 @@ impl<'a> gix_transport::client::ReadlineBufRead for Fixture<'a> { self.0 = lines.as_bytes(); Some(Ok(Ok(gix_packetline::PacketLineRef::Data(res)))) } + async fn readline_str(&mut self, line: &mut String) -> std::io::Result<usize> { + use bstr::{BStr, ByteSlice}; + let bytes: &BStr = self.0.into(); + let mut lines = bytes.lines(); + let res = match lines.next() { + None => return Ok(0), + Some(line) => line, + }; + self.0 = lines.as_bytes(); + let len = res.len(); + line.push_str(res.to_str().expect("valid UTF8 in fixture")); + Ok(len) + } } diff --git a/vendor/gix-protocol/src/remote_progress.rs b/vendor/gix-protocol/src/remote_progress.rs index 50d0eed17..538a767fc 100644 --- a/vendor/gix-protocol/src/remote_progress.rs +++ b/vendor/gix-protocol/src/remote_progress.rs @@ -10,9 +10,9 @@ use nom::{ /// The information usually found in remote progress messages as sent by a git server during /// fetch, clone and push operations. #[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 RemoteProgress<'a> { - #[cfg_attr(feature = "serde1", serde(borrow))] + #[cfg_attr(feature = "serde", serde(borrow))] /// The name of the action, like "clone". pub action: &'a bstr::BStr, /// The percentage to indicate progress, between 0 and 100. |