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
98 * [x] [error line](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L28:L28)98 * [x] [error line](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L28:L28)
99 * [x] [V2 additions](https://github.com/git/git/blob/master/Documentation/technical/protocol-v2.txt#L35:L36)99 * [x] [V2 additions](https://github.com/git/git/blob/master/Documentation/technical/protocol-v2.txt#L35:L36)
100 * [x] [side-band mode](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L467:L467)100 * [x] [side-band mode](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L467:L467)
101 * [ ] PacketLine 'Iterator' from `Read`
102 * [ ] **Version 1**101 * [ ] **Version 1**
103 * [ ] parse and serialize [capabilities](https://github.com/git/git/blob/master/Documentation/technical/protocol-capabilities.txt#L1:L1)102 * [ ] parse and serialize [capabilities](https://github.com/git/git/blob/master/Documentation/technical/protocol-capabilities.txt#L1:L1)
104 * [ ] [fetch](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L157:L157)103 * [ ] [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
26 /// start of whatever comes next.26 /// start of whatever comes next.
27 pub struct Reader<T> {27 pub struct Reader<T> {
28 pub inner: T,28 pub inner: T,
29 buf: Option<Vec<u8>>,29 buf: Vec<u8>,
30 occupied: Option<std::ops::Range<usize>>,30 occupied: Option<std::ops::Range<usize>>,
31 is_done: bool,
31 }32 }
32 33
33 impl<T> Reader<T>34 impl<T> Reader<T>
@@ -37,14 +38,16 @@ mod read { · 3 unmodified lines
37 pub fn new(inner: T) -> Self {38 pub fn new(inner: T) -> Self {
38 Reader {39 Reader {
39 inner,40 inner,
40 buf: Some({41 buf: {
41 let mut v = Vec::with_capacity(MAX_LINE_LEN);42 let mut v = Vec::with_capacity(MAX_LINE_LEN);
42 v.resize(MAX_LINE_LEN, 0);43 v.resize(MAX_LINE_LEN, 0);
43 v44 v
44 }),45 },
45 occupied: None,46 occupied: None,
47 is_done: false,
46 }48 }
47 }49 }
50
48 fn read_line_inner<'a>(51 fn read_line_inner<'a>(
49 reader: &mut T,52 reader: &mut T,
50 occupied: &mut Option<std::ops::Range<usize>>,53 occupied: &mut Option<std::ops::Range<usize>>,
@@ -60,22 +63,20 @@ mod read { · 9 unmodified lines
60 }63 }
61 64
62 pub fn read_line(&mut self) -> Option<io::Result<Result<Borrowed, decode::Error>>> {65 pub fn read_line(&mut self) -> Option<io::Result<Result<Borrowed, decode::Error>>> {
63 match self.buf.as_mut() {66 if self.is_done {
64 Some(buf) => {67 return None;
65 loop {68 }
66 match Self::read_line_inner(&mut self.inner, &mut self.occupied, buf) {69 Some(loop {
67 Ok(Ok(line)) if line == Borrowed::Flush => {70 match Self::read_line_inner(&mut self.inner, &mut self.occupied, &mut self.buf) {
68 self.buf = None;71 Ok(Ok(line)) if line == Borrowed::Flush => {
69 return None;72 self.is_done = true;
70 }73 return None;
71 Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
72 // res => return Some(res),
73 res => unimplemented!("tst"),
74 }
75 }74 }
75 Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
76 res => break res,
77 // res => unimplemented!("tst"),
76 }78 }
77 None => None,79 })
78 }
79 }80 }
80 }81 }
81}82}
tasks.md+1−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
6 * to be used to obtain more real-world samples of typical git interactions for use in the test-suite6 * to be used to obtain more real-world samples of typical git interactions for use in the test-suite
7 * [x] Don't forcibly remove newlines at the end of pack lines, but make that an extra step.7 * [x] Don't forcibly remove newlines at the end of pack lines, but make that an extra step.
8 * [x] decode band should be able to fail8 * [x] decode band should be able to fail
9 * [ ] PacketLine 'Iterator' from `Read`
9 * **git-protocol**10 * **git-protocol**
10 * [ ] pkt-lines support11 * [ ] pkt-lines support
11 * [ ] basic V1 parsing to understand data frames to allow placing them into individual files12 * [ ] basic V1 parsing to understand data frames to allow placing them into individual files