Skip to content

Have gix-filter depend on gix-packetline-blocking unaliased #1940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gix-filter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gix-command = { version = "^0.5.0", path = "../gix-command" }
gix-quote = { version = "^0.5.0", path = "../gix-quote" }
gix-utils = { version = "^0.2.0", path = "../gix-utils" }
gix-path = { version = "^0.10.15", path = "../gix-path" }
gix-packetline = { package = "gix-packetline-blocking", version = "^0.18.3", path = "../gix-packetline-blocking" }
gix-packetline-blocking = { version = "^0.18.3", path = "../gix-packetline-blocking" }
gix-attributes = { version = "^0.25.0", path = "../gix-attributes" }

encoding_rs = "0.8.32"
Expand Down
27 changes: 14 additions & 13 deletions gix-filter/src/driver/process/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub mod invoke {
#[error("Failed to read or write to the process")]
Io(#[from] std::io::Error),
#[error(transparent)]
PacketlineDecode(#[from] gix_packetline::decode::Error),
PacketlineDecode(#[from] gix_packetline_blocking::decode::Error),
}

impl From<super::Error> for Error {
Expand All @@ -65,17 +65,18 @@ impl Client {
versions: &[usize],
desired_capabilities: &[&str],
) -> Result<Self, handshake::Error> {
let mut out = gix_packetline::Writer::new(process.stdin.take().expect("configured stdin when spawning"));
let mut out =
gix_packetline_blocking::Writer::new(process.stdin.take().expect("configured stdin when spawning"));
out.write_all(format!("{welcome_prefix}-client").as_bytes())?;
for version in versions {
out.write_all(format!("version={version}").as_bytes())?;
}
gix_packetline::encode::flush_to_write(out.inner_mut())?;
gix_packetline_blocking::encode::flush_to_write(out.inner_mut())?;
out.flush()?;

let mut input = gix_packetline::StreamingPeekableIter::new(
let mut input = gix_packetline_blocking::StreamingPeekableIter::new(
process.stdout.take().expect("configured stdout when spawning"),
&[gix_packetline::PacketLineRef::Flush],
&[gix_packetline_blocking::PacketLineRef::Flush],
false, /* packet tracing */
);
let mut read = input.as_read();
Expand Down Expand Up @@ -125,10 +126,10 @@ impl Client {
for capability in desired_capabilities {
out.write_all(format!("capability={capability}").as_bytes())?;
}
gix_packetline::encode::flush_to_write(out.inner_mut())?;
gix_packetline_blocking::encode::flush_to_write(out.inner_mut())?;
out.flush()?;

read.reset_with(&[gix_packetline::PacketLineRef::Flush]);
read.reset_with(&[gix_packetline_blocking::PacketLineRef::Flush]);
let mut capabilities = HashSet::new();
loop {
buf.clear();
Expand Down Expand Up @@ -167,7 +168,7 @@ impl Client {
) -> Result<process::Status, invoke::Error> {
self.send_command_and_meta(command, meta)?;
std::io::copy(content, &mut self.input)?;
gix_packetline::encode::flush_to_write(self.input.inner_mut())?;
gix_packetline_blocking::encode::flush_to_write(self.input.inner_mut())?;
self.input.flush()?;
Ok(self.read_status()?)
}
Expand All @@ -189,15 +190,15 @@ impl Client {
inspect_line(line.as_bstr());
}
}
self.out.reset_with(&[gix_packetline::PacketLineRef::Flush]);
self.out.reset_with(&[gix_packetline_blocking::PacketLineRef::Flush]);
let status = self.read_status()?;
Ok(status)
}

/// Return a `Read` implementation that reads the server process output until the next flush package, and validates
/// the status. If the status indicates failure, the last read will also fail.
pub fn as_read(&mut self) -> impl std::io::Read + '_ {
self.out.reset_with(&[gix_packetline::PacketLineRef::Flush]);
self.out.reset_with(&[gix_packetline_blocking::PacketLineRef::Flush]);
ReadProcessOutputAndStatus {
inner: self.out.as_read(),
}
Expand Down Expand Up @@ -225,7 +226,7 @@ impl Client {
buf.push_str(&value);
self.input.write_all(&buf)?;
}
gix_packetline::encode::flush_to_write(self.input.inner_mut())?;
gix_packetline_blocking::encode::flush_to_write(self.input.inner_mut())?;
Ok(())
}
}
Expand All @@ -248,7 +249,7 @@ fn read_status(read: &mut PacketlineReader<'_>) -> std::io::Result<process::Stat
if count > 0 && matches!(status, process::Status::Previous) {
status = process::Status::Unset;
}
read.reset_with(&[gix_packetline::PacketLineRef::Flush]);
read.reset_with(&[gix_packetline_blocking::PacketLineRef::Flush]);
Ok(status)
}

Expand All @@ -260,7 +261,7 @@ impl std::io::Read for ReadProcessOutputAndStatus<'_> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let num_read = self.inner.read(buf)?;
if num_read == 0 {
self.inner.reset_with(&[gix_packetline::PacketLineRef::Flush]);
self.inner.reset_with(&[gix_packetline_blocking::PacketLineRef::Flush]);
let status = read_status(&mut self.inner)?;
if status.is_success() {
Ok(0)
Expand Down
15 changes: 9 additions & 6 deletions gix-filter/src/driver/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ pub struct Client {
/// The negotiated version of the protocol.
version: usize,
/// A way to send packet-line encoded information to the process.
input: gix_packetline::Writer<std::process::ChildStdin>,
input: gix_packetline_blocking::Writer<std::process::ChildStdin>,
/// A way to read information sent to us by the process.
out: gix_packetline::StreamingPeekableIter<std::process::ChildStdout>,
out: gix_packetline_blocking::StreamingPeekableIter<std::process::ChildStdout>,
}

/// A handle to facilitate typical server interactions that include the handshake and command-invocations.
Expand All @@ -24,9 +24,9 @@ pub struct Server {
/// The negotiated version of the protocol, it's the highest supported one.
version: usize,
/// A way to receive information from the client.
input: gix_packetline::StreamingPeekableIter<std::io::StdinLock<'static>>,
input: gix_packetline_blocking::StreamingPeekableIter<std::io::StdinLock<'static>>,
/// A way to send information to the client.
out: gix_packetline::Writer<std::io::StdoutLock<'static>>,
out: gix_packetline_blocking::Writer<std::io::StdoutLock<'static>>,
}

/// The return status of an [invoked command][Client::invoke()].
Expand Down Expand Up @@ -109,5 +109,8 @@ pub mod client;
///
pub mod server;

type PacketlineReader<'a, T = std::process::ChildStdout> =
gix_packetline::read::WithSidebands<'a, T, fn(bool, &[u8]) -> gix_packetline::read::ProgressAction>;
type PacketlineReader<'a, T = std::process::ChildStdout> = gix_packetline_blocking::read::WithSidebands<
'a,
T,
fn(bool, &[u8]) -> gix_packetline_blocking::read::ProgressAction,
>;
22 changes: 11 additions & 11 deletions gix-filter/src/driver/process/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod next_request {
#[error("{msg} '{actual}'")]
Protocol { msg: String, actual: BString },
#[error(transparent)]
PacketlineDecode(#[from] gix_packetline::decode::Error),
PacketlineDecode(#[from] gix_packetline_blocking::decode::Error),
}
}

Expand Down Expand Up @@ -63,9 +63,9 @@ impl Server {
pick_version: &mut dyn FnMut(&[usize]) -> Option<usize>,
available_capabilities: &[&str],
) -> Result<Self, handshake::Error> {
let mut input = gix_packetline::StreamingPeekableIter::new(
let mut input = gix_packetline_blocking::StreamingPeekableIter::new(
stdin.lock(),
&[gix_packetline::PacketLineRef::Flush],
&[gix_packetline_blocking::PacketLineRef::Flush],
false, /* packet tracing */
);
let mut read = input.as_read();
Expand Down Expand Up @@ -104,11 +104,11 @@ impl Server {
);
}
let version = pick_version(&versions).ok_or(handshake::Error::VersionMismatch { actual: versions })?;
read.reset_with(&[gix_packetline::PacketLineRef::Flush]);
let mut out = gix_packetline::Writer::new(stdout.lock());
read.reset_with(&[gix_packetline_blocking::PacketLineRef::Flush]);
let mut out = gix_packetline_blocking::Writer::new(stdout.lock());
out.write_all(format!("{welcome_prefix}-server").as_bytes())?;
out.write_all(format!("version={version}").as_bytes())?;
gix_packetline::encode::flush_to_write(out.inner_mut())?;
gix_packetline_blocking::encode::flush_to_write(out.inner_mut())?;
out.flush()?;

let mut capabilities = HashSet::new();
Expand All @@ -132,7 +132,7 @@ impl Server {
for cap in &capabilities {
out.write_all(format!("capability={cap}").as_bytes())?;
}
gix_packetline::encode::flush_to_write(out.inner_mut())?;
gix_packetline_blocking::encode::flush_to_write(out.inner_mut())?;
out.flush()?;

drop(read);
Expand Down Expand Up @@ -196,7 +196,7 @@ impl Server {
}

drop(read);
self.input.reset_with(&[gix_packetline::PacketLineRef::Flush]);
self.input.reset_with(&[gix_packetline_blocking::PacketLineRef::Flush]);

Ok(Some(Request {
parent: self,
Expand Down Expand Up @@ -233,7 +233,7 @@ mod request {
if let Some(message) = status.message() {
out.write_all(format!("status={message}").as_bytes())?;
}
gix_packetline::encode::flush_to_write(out.inner_mut())?;
gix_packetline_blocking::encode::flush_to_write(out.inner_mut())?;
out.flush()
}
}
Expand All @@ -248,7 +248,7 @@ mod request {
}

struct WriteAndFlushOnDrop<'a> {
inner: &'a mut gix_packetline::Writer<std::io::StdoutLock<'static>>,
inner: &'a mut gix_packetline_blocking::Writer<std::io::StdoutLock<'static>>,
}

impl std::io::Write for WriteAndFlushOnDrop<'_> {
Expand All @@ -263,7 +263,7 @@ mod request {

impl Drop for WriteAndFlushOnDrop<'_> {
fn drop(&mut self) {
gix_packetline::encode::flush_to_write(self.inner.inner_mut()).ok();
gix_packetline_blocking::encode::flush_to_write(self.inner.inner_mut()).ok();
self.inner.flush().ok();
}
}
Expand Down
3 changes: 0 additions & 3 deletions gix-packetline-blocking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ blocking-io = []
## DO NOT USE, instead use `gix-packetline` directly.
async-io = []

## DO NOT USE, instead use `gix-packetline` directly (and still don't specify `futures-lite`).
futures-lite = []

#! ### Other
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
serde = ["dep:serde", "bstr/serde"]
Expand Down
Loading