History

[protocol] FAIL2: lifetime issues with loop

The loop is needed to handle interrupt errors correctly. Writing it differently has no effect either, that's good I guess

Sebastian Thiel committed 6 years ago

Commit c2ff0701 parent 0f468f93 files · +19 −18Browse files

Unified · Split

3 files
  1. README.md +0 −1
  2. git-protocol/src/packet_line/mod.rs +18 −17
  3. tasks.md +1 −0
README.md+0−1
@@ -98,7 +98,6 @@ Please see _'Development Status'_ for a listing of all crates and their capabili · 97 unmodified lines
9898 * [x] [error line](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L28:L28)
9999 * [x] [V2 additions](https://github.com/git/git/blob/master/Documentation/technical/protocol-v2.txt#L35:L36)
100100 * [x] [side-band mode](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L467:L467)
101− * [ ] PacketLine 'Iterator' from `Read`
102101 * [ ] **Version 1**
103102 * [ ] parse and serialize [capabilities](https://github.com/git/git/blob/master/Documentation/technical/protocol-capabilities.txt#L1:L1)
104103 * [ ] [fetch](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L157:L157)
git-protocol/src/packet_line/mod.rs+18−17
@@ -26,8 +26,9 @@ mod read { · 25 unmodified lines
2626 /// start of whatever comes next.
2727 pub struct Reader<T> {
2828 pub inner: T,
29− buf: Option<Vec<u8>>,
29+ buf: Vec<u8>,
3030 occupied: Option<std::ops::Range<usize>>,
31+ is_done: bool,
3132 }
3233
3334 impl<T> Reader<T>
@@ -37,14 +38,16 @@ mod read { · 3 unmodified lines
3738 pub fn new(inner: T) -> Self {
3839 Reader {
3940 inner,
40− buf: Some({
41+ buf: {
4142 let mut v = Vec::with_capacity(MAX_LINE_LEN);
4243 v.resize(MAX_LINE_LEN, 0);
4344 v
44− }),
45+ },
4546 occupied: None,
47+ is_done: false,
4648 }
4749 }
50+
4851 fn read_line_inner<'a>(
4952 reader: &mut T,
5053 occupied: &mut Option<std::ops::Range<usize>>,
@@ -60,22 +63,20 @@ mod read { · 9 unmodified lines
6063 }
6164
6265 pub fn read_line(&mut self) -> Option<io::Result<Result<Borrowed, decode::Error>>> {
63− match self.buf.as_mut() {
64− Some(buf) => {
65− loop {
66− match Self::read_line_inner(&mut self.inner, &mut self.occupied, buf) {
67− Ok(Ok(line)) if line == Borrowed::Flush => {
68− self.buf = None;
69− return None;
70− }
71− Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
72− // res => return Some(res),
73− res => unimplemented!("tst"),
74− }
66+ if self.is_done {
67+ return None;
68+ }
69+ Some(loop {
70+ match Self::read_line_inner(&mut self.inner, &mut self.occupied, &mut self.buf) {
71+ Ok(Ok(line)) if line == Borrowed::Flush => {
72+ self.is_done = true;
73+ return None;
7574 }
75+ Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
76+ res => break res,
77+ // res => unimplemented!("tst"),
7678 }
77− None => None,
78− }
79+ })
7980 }
8081 }
8182 }
tasks.md+1−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
66 * to be used to obtain more real-world samples of typical git interactions for use in the test-suite
77 * [x] Don't forcibly remove newlines at the end of pack lines, but make that an extra step.
88 * [x] decode band should be able to fail
9+ * [ ] PacketLine 'Iterator' from `Read`
910 * **git-protocol**
1011 * [ ] pkt-lines support
1112 * [ ] basic V1 parsing to understand data frames to allow placing them into individual files