Skip to content

Commit 3866517

Browse files
committed
Revert "[git-packetline] get it to compile by resorting to another buffer"
This reverts commit 01e15c8.
1 parent 01e15c8 commit 3866517

File tree

1 file changed

+42
-47
lines changed

1 file changed

+42
-47
lines changed

git-packetline/src/read/sidebands/async_io.rs

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
decode,
33
immutable::{Band, Text},
4-
PacketLine, StreamingPeekableIter, MAX_DATA_LEN,
4+
PacketLine, StreamingPeekableIter, U16_HEX_BYTES,
55
};
66
use futures_io::{AsyncBufRead, AsyncRead};
77
use futures_lite::ready;
@@ -24,7 +24,6 @@ where
2424
parent: Option<&'a mut StreamingPeekableIter<T>>,
2525
handle_progress: Option<F>,
2626
read_line: Option<Pin<Box<dyn Future<Output = ReadLineResult<'a>> + 'a>>>,
27-
buf: Vec<u8>,
2827
pos: usize,
2928
cap: usize,
3029
}
@@ -50,7 +49,6 @@ where
5049
parent: Some(parent),
5150
handle_progress: None,
5251
read_line: None,
53-
buf: Vec::with_capacity(MAX_DATA_LEN),
5452
pos: 0,
5553
cap: 0,
5654
}
@@ -71,7 +69,6 @@ where
7169
parent: Some(parent),
7270
handle_progress: Some(handle_progress),
7371
read_line: None,
74-
buf: Vec::with_capacity(MAX_DATA_LEN),
7572
pos: 0,
7673
cap: 0,
7774
}
@@ -83,7 +80,6 @@ where
8380
parent: Some(parent),
8481
handle_progress: None,
8582
read_line: None,
86-
buf: Vec::with_capacity(MAX_DATA_LEN),
8783
pos: 0,
8884
cap: 0,
8985
}
@@ -123,52 +119,51 @@ where
123119
{
124120
fn poll_fill_buf(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<std::io::Result<&[u8]>> {
125121
use futures_lite::FutureExt;
126-
use std::{io, io::Read};
127-
{
128-
let this = self.as_mut().get_mut();
129-
if this.pos >= this.cap {
130-
this.cap = loop {
131-
// todo!("poll a future based on a field of ourselves - self-ref once again");
132-
this.read_line = Some(this.parent.take().unwrap().read_line().boxed());
133-
let line = match ready!(this.read_line.as_mut().expect("set above").poll(_cx)) {
134-
Some(line) => line?.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?,
135-
None => break 0,
136-
};
137-
match this.handle_progress.as_mut() {
138-
Some(handle_progress) => {
139-
let mut band = line
140-
.decode_band()
141-
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
142-
match band {
143-
Band::Data(ref mut d) => break d.read(&mut this.buf)?,
144-
Band::Progress(d) => {
145-
let text = Text::from(d).0;
146-
handle_progress(false, text);
147-
}
148-
Band::Error(d) => {
149-
let text = Text::from(d).0;
150-
handle_progress(true, text);
151-
}
152-
};
153-
}
154-
None => {
155-
break match line.as_slice() {
156-
Some(ref mut d) => d.read(&mut this.buf)?,
157-
None => {
158-
return Poll::Ready(Err(io::Error::new(
159-
io::ErrorKind::UnexpectedEof,
160-
"encountered non-data line in a data-line only context",
161-
)))
162-
}
122+
use std::io;
123+
let this = self.as_mut().get_mut();
124+
if this.pos >= this.cap {
125+
let (ofs, cap) = loop {
126+
// todo!("poll a future based on a field of ourselves - self-ref once again");
127+
this.read_line = Some(this.parent.take().unwrap().read_line().boxed());
128+
let line = match ready!(this.read_line.as_mut().expect("set above").poll(_cx)) {
129+
Some(line) => line?.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?,
130+
None => break (0, 0),
131+
};
132+
match this.handle_progress.as_mut() {
133+
Some(handle_progress) => {
134+
let band = line
135+
.decode_band()
136+
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
137+
const ENCODED_BAND: usize = 1;
138+
match band {
139+
Band::Data(d) => break (U16_HEX_BYTES + ENCODED_BAND, d.len()),
140+
Band::Progress(d) => {
141+
let text = Text::from(d).0;
142+
handle_progress(false, text);
143+
}
144+
Band::Error(d) => {
145+
let text = Text::from(d).0;
146+
handle_progress(true, text);
147+
}
148+
};
149+
}
150+
None => {
151+
break match line.as_slice() {
152+
Some(d) => (U16_HEX_BYTES, d.len()),
153+
None => {
154+
return Poll::Ready(Err(io::Error::new(
155+
io::ErrorKind::UnexpectedEof,
156+
"encountered non-data line in a data-line only context",
157+
)))
163158
}
164159
}
165160
}
166-
};
167-
this.pos = 0;
168-
}
161+
}
162+
};
163+
this.cap = cap + ofs;
164+
this.pos = ofs;
169165
}
170-
let cap = self.cap;
171-
Poll::Ready(Ok(&self.get_mut().buf[..cap]))
166+
Poll::Ready(Ok(&this.parent.as_ref().unwrap().buf[this.pos..this.cap]))
172167
}
173168

174169
fn consume(self: Pin<&mut Self>, amt: usize) {

0 commit comments

Comments
 (0)