Skip to content

Commit bce8468

Browse files
djcByron
authored andcommitted
feat!: large portions of the API for greater ease of use
1 parent f2c6a19 commit bce8468

File tree

32 files changed

+265
-296
lines changed

32 files changed

+265
-296
lines changed

gix-filter/src/driver/process/client.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{collections::HashSet, io::Write, str::FromStr};
22

33
use bstr::{BStr, BString, ByteVec};
4+
use gix_packetline::blocking_io::{encode, StreamingPeekableIter, Writer};
45

56
use crate::driver::{
67
process,
@@ -65,17 +66,15 @@ impl Client {
6566
versions: &[usize],
6667
desired_capabilities: &[&str],
6768
) -> Result<Self, handshake::Error> {
68-
let mut out = gix_packetline::write::blocking_io::Writer::new(
69-
process.stdin.take().expect("configured stdin when spawning"),
70-
);
69+
let mut out = Writer::new(process.stdin.take().expect("configured stdin when spawning"));
7170
out.write_all(format!("{welcome_prefix}-client").as_bytes())?;
7271
for version in versions {
7372
out.write_all(format!("version={version}").as_bytes())?;
7473
}
75-
gix_packetline::encode::blocking_io::flush_to_write(out.inner_mut())?;
74+
encode::flush_to_write(out.inner_mut())?;
7675
out.flush()?;
7776

78-
let mut input = gix_packetline::read::blocking_io::StreamingPeekableIter::new(
77+
let mut input = StreamingPeekableIter::new(
7978
process.stdout.take().expect("configured stdout when spawning"),
8079
&[gix_packetline::PacketLineRef::Flush],
8180
false, /* packet tracing */
@@ -127,7 +126,7 @@ impl Client {
127126
for capability in desired_capabilities {
128127
out.write_all(format!("capability={capability}").as_bytes())?;
129128
}
130-
gix_packetline::encode::blocking_io::flush_to_write(out.inner_mut())?;
129+
encode::flush_to_write(out.inner_mut())?;
131130
out.flush()?;
132131

133132
read.reset_with(&[gix_packetline::PacketLineRef::Flush]);
@@ -169,7 +168,7 @@ impl Client {
169168
) -> Result<process::Status, invoke::Error> {
170169
self.send_command_and_meta(command, meta)?;
171170
std::io::copy(content, &mut self.input)?;
172-
gix_packetline::encode::blocking_io::flush_to_write(self.input.inner_mut())?;
171+
encode::flush_to_write(self.input.inner_mut())?;
173172
self.input.flush()?;
174173
Ok(self.read_status()?)
175174
}
@@ -227,7 +226,7 @@ impl Client {
227226
buf.push_str(&value);
228227
self.input.write_all(&buf)?;
229228
}
230-
gix_packetline::encode::blocking_io::flush_to_write(self.input.inner_mut())?;
229+
encode::flush_to_write(self.input.inner_mut())?;
231230
Ok(())
232231
}
233232
}

gix-filter/src/driver/process/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::collections::HashSet;
22

3+
use gix_packetline::blocking_io::{StreamingPeekableIter, WithSidebands, Writer};
4+
35
/// A set of capabilities that have been negotiated between client and server.
46
pub type Capabilities = HashSet<String>;
57

@@ -12,9 +14,9 @@ pub struct Client {
1214
/// The negotiated version of the protocol.
1315
version: usize,
1416
/// A way to send packet-line encoded information to the process.
15-
input: gix_packetline::write::blocking_io::Writer<std::process::ChildStdin>,
17+
input: Writer<std::process::ChildStdin>,
1618
/// A way to read information sent to us by the process.
17-
out: gix_packetline::read::blocking_io::StreamingPeekableIter<std::process::ChildStdout>,
19+
out: StreamingPeekableIter<std::process::ChildStdout>,
1820
}
1921

2022
/// A handle to facilitate typical server interactions that include the handshake and command-invocations.
@@ -24,9 +26,9 @@ pub struct Server {
2426
/// The negotiated version of the protocol, it's the highest supported one.
2527
version: usize,
2628
/// A way to receive information from the client.
27-
input: gix_packetline::read::blocking_io::StreamingPeekableIter<std::io::StdinLock<'static>>,
29+
input: StreamingPeekableIter<std::io::StdinLock<'static>>,
2830
/// A way to send information to the client.
29-
out: gix_packetline::write::blocking_io::Writer<std::io::StdoutLock<'static>>,
31+
out: Writer<std::io::StdoutLock<'static>>,
3032
}
3133

3234
/// The return status of an [invoked command][Client::invoke()].
@@ -110,4 +112,4 @@ pub mod client;
110112
pub mod server;
111113

112114
type PacketlineReader<'a, T = std::process::ChildStdout> =
113-
gix_packetline::read::blocking_io::WithSidebands<'a, T, fn(bool, &[u8]) -> gix_packetline::read::ProgressAction>;
115+
WithSidebands<'a, T, fn(bool, &[u8]) -> gix_packetline::read::ProgressAction>;

gix-filter/src/driver/process/server.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{collections::HashSet, io::Write, str::FromStr};
22

33
use bstr::{BString, ByteSlice};
4+
use gix_packetline::blocking_io::{encode, StreamingPeekableIter, Writer};
45

56
use crate::driver::process::Server;
67

@@ -63,7 +64,7 @@ impl Server {
6364
pick_version: &mut dyn FnMut(&[usize]) -> Option<usize>,
6465
available_capabilities: &[&str],
6566
) -> Result<Self, handshake::Error> {
66-
let mut input = gix_packetline::read::blocking_io::StreamingPeekableIter::new(
67+
let mut input = StreamingPeekableIter::new(
6768
stdin.lock(),
6869
&[gix_packetline::PacketLineRef::Flush],
6970
false, /* packet tracing */
@@ -105,10 +106,10 @@ impl Server {
105106
}
106107
let version = pick_version(&versions).ok_or(handshake::Error::VersionMismatch { actual: versions })?;
107108
read.reset_with(&[gix_packetline::PacketLineRef::Flush]);
108-
let mut out = gix_packetline::write::blocking_io::Writer::new(stdout.lock());
109+
let mut out = Writer::new(stdout.lock());
109110
out.write_all(format!("{welcome_prefix}-server").as_bytes())?;
110111
out.write_all(format!("version={version}").as_bytes())?;
111-
gix_packetline::encode::blocking_io::flush_to_write(out.inner_mut())?;
112+
encode::flush_to_write(out.inner_mut())?;
112113
out.flush()?;
113114

114115
let mut capabilities = HashSet::new();
@@ -132,7 +133,7 @@ impl Server {
132133
for cap in &capabilities {
133134
out.write_all(format!("capability={cap}").as_bytes())?;
134135
}
135-
gix_packetline::encode::blocking_io::flush_to_write(out.inner_mut())?;
136+
encode::flush_to_write(out.inner_mut())?;
136137
out.flush()?;
137138

138139
drop(read);
@@ -209,6 +210,8 @@ impl Server {
209210
mod request {
210211
use std::io::Write;
211212

213+
use gix_packetline::blocking_io::{encode, Writer};
214+
212215
use crate::driver::{
213216
process,
214217
process::{server::Request, PacketlineReader},
@@ -233,7 +236,7 @@ mod request {
233236
if let Some(message) = status.message() {
234237
out.write_all(format!("status={message}").as_bytes())?;
235238
}
236-
gix_packetline::encode::blocking_io::flush_to_write(out.inner_mut())?;
239+
encode::flush_to_write(out.inner_mut())?;
237240
out.flush()
238241
}
239242
}
@@ -248,7 +251,7 @@ mod request {
248251
}
249252

250253
struct WriteAndFlushOnDrop<'a> {
251-
inner: &'a mut gix_packetline::write::blocking_io::Writer<std::io::StdoutLock<'static>>,
254+
inner: &'a mut Writer<std::io::StdoutLock<'static>>,
252255
}
253256

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

264267
impl Drop for WriteAndFlushOnDrop<'_> {
265268
fn drop(&mut self) {
266-
gix_packetline::encode::blocking_io::flush_to_write(self.inner.inner_mut()).ok();
269+
encode::flush_to_write(self.inner.inner_mut()).ok();
267270
self.inner.flush().ok();
268271
}
269272
}

gix-packetline/src/encode/async_io.rs renamed to gix-packetline/src/async_io/encode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use std::{
77
use futures_io::AsyncWrite;
88
use futures_lite::AsyncWriteExt;
99

10-
use super::u16_to_hex;
1110
use crate::{
12-
encode::Error, BandRef, Channel, ErrorRef, PacketLineRef, TextRef, DELIMITER_LINE, ERR_PREFIX, FLUSH_LINE,
13-
MAX_DATA_LEN, RESPONSE_END_LINE,
11+
encode::{u16_to_hex, Error},
12+
BandRef, Channel, ErrorRef, PacketLineRef, TextRef, DELIMITER_LINE, ERR_PREFIX, FLUSH_LINE, MAX_DATA_LEN,
13+
RESPONSE_END_LINE,
1414
};
1515

1616
pin_project_lite::pin_project! {

gix-packetline/src/read/async_io.rs renamed to gix-packetline/src/async_io/read.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bstr::ByteSlice;
77
use futures_io::AsyncRead;
88
use futures_lite::AsyncReadExt;
99

10-
pub use super::sidebands::async_io::WithSidebands;
10+
pub use super::sidebands::WithSidebands;
1111
use crate::{
1212
decode,
1313
read::{ExhaustiveOutcome, ProgressAction},

gix-packetline/src/read/sidebands/async_io.rs renamed to gix-packetline/src/async_io/sidebands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66

77
use futures_io::{AsyncBufRead, AsyncRead};
88

9-
use crate::read::async_io::StreamingPeekableIter;
9+
use super::read::StreamingPeekableIter;
1010
use crate::{decode, read::ProgressAction, BandRef, PacketLineRef, TextRef, U16_HEX_BYTES};
1111

1212
type ReadLineResult<'a> = Option<std::io::Result<Result<PacketLineRef<'a>, decode::Error>>>;

gix-packetline/src/write/async_io.rs renamed to gix-packetline/src/async_io/write.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ use std::{
66

77
use futures_io::AsyncWrite;
88

9-
use crate::{encode, MAX_DATA_LEN, U16_HEX_BYTES};
9+
use super::encode::LineWriter;
10+
use crate::{MAX_DATA_LEN, U16_HEX_BYTES};
1011

1112
pin_project_lite::pin_project! {
1213
/// An implementor of [`Write`][io::Write] which passes all input to an inner `Write` in packet line data encoding,
1314
/// one line per `write(…)` call or as many lines as it takes if the data doesn't fit into the maximum allowed line length.
1415
pub struct Writer<T> {
1516
#[pin]
16-
inner: encode::async_io::LineWriter<'static, T>,
17+
inner: LineWriter<'static, T>,
1718
state: State,
1819
}
1920
}
@@ -27,7 +28,7 @@ impl<T: AsyncWrite + Unpin> Writer<T> {
2728
/// Create a new instance from the given `write`
2829
pub fn new(write: T) -> Self {
2930
Writer {
30-
inner: encode::async_io::LineWriter::new(write, &[], &[]),
31+
inner: LineWriter::new(write, &[], &[]),
3132
state: State::Idle,
3233
}
3334
}

gix-packetline/src/encode/blocking_io.rs renamed to gix-packetline/src/blocking_io/encode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::io;
22

3-
use super::u16_to_hex;
43
use crate::{
5-
encode::Error, BandRef, Channel, ErrorRef, PacketLineRef, TextRef, DELIMITER_LINE, ERR_PREFIX, FLUSH_LINE,
6-
MAX_DATA_LEN, RESPONSE_END_LINE,
4+
encode::{u16_to_hex, Error},
5+
BandRef, Channel, ErrorRef, PacketLineRef, TextRef, DELIMITER_LINE, ERR_PREFIX, FLUSH_LINE, MAX_DATA_LEN,
6+
RESPONSE_END_LINE,
77
};
88

99
/// Write a response-end message to `out`.

gix-packetline/src/read/blocking_io.rs renamed to gix-packetline/src/blocking_io/read.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use std::{
55

66
use bstr::ByteSlice;
77

8-
pub use super::sidebands::blocking_io::WithSidebands;
8+
pub use super::sidebands::WithSidebands;
99
use crate::{
1010
decode,
11-
read::{ExhaustiveOutcome, ProgressAction},
12-
PacketLineRef, StreamingPeekableIterState, MAX_LINE_LEN, U16_HEX_BYTES,
11+
read::{ExhaustiveOutcome, ProgressAction, StreamingPeekableIterState},
12+
PacketLineRef, MAX_LINE_LEN, U16_HEX_BYTES,
1313
};
1414

1515
/// Read pack lines one after another, without consuming more than needed from the underlying

gix-packetline/src/read/sidebands/blocking_io.rs renamed to gix-packetline/src/blocking_io/sidebands.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::{io, io::BufRead};
22

3-
use crate::{
4-
read::{blocking_io::StreamingPeekableIter, ProgressAction},
5-
BandRef, PacketLineRef, TextRef, U16_HEX_BYTES,
6-
};
3+
use super::read::StreamingPeekableIter;
4+
use crate::{read::ProgressAction, BandRef, PacketLineRef, TextRef, U16_HEX_BYTES};
75

86
/// An implementor of [`BufRead`][io::BufRead] yielding packet lines on each call to [`read_line()`][io::BufRead::read_line()].
97
/// It's also possible to hide the underlying packet lines using the [`Read`][io::Read] implementation which is useful

0 commit comments

Comments
 (0)