Skip to content

Commit

Permalink
[ref-ls] support for line peeking in packet line readers
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 8, 2020
1 parent 1f9cc44 commit 0c0c575
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
12 changes: 12 additions & 0 deletions git-packetline/src/provider/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ where
pub fn set_progress_handler(&mut self, handle_progress: Option<F>) {
self.handle_progress = handle_progress;
}

pub fn peek_data_line(&mut self) -> Option<io::Result<Result<&[u8], crate::decode::Error>>> {
match self.parent.peek_line() {
Some(Ok(Ok(line))) => match line {
crate::PacketLine::Data(line) => Some(Ok(Ok(line))),
_ => None,
},
Some(Ok(Err(err))) => Some(Ok(Err(err))),
Some(Err(err)) => Some(Err(err)),
None => None,
}
}
}

impl<'a, T, F> io::BufRead for ReadWithSidebands<'a, T, F>
Expand Down
9 changes: 9 additions & 0 deletions git-protocol/src/fetch/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ pub enum Acknowledgement {
NAK,
}

impl Acknowledgement {
pub fn id(&self) -> Option<&owned::Id> {
match self {
Acknowledgement::Common(id) => Some(id),
_ => None,
}
}
}

/// A representation of a complete fetch response
pub struct Response {
acks: Option<Vec<Acknowledgement>>,
Expand Down
4 changes: 4 additions & 0 deletions git-transport/src/client/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ impl<H: Http, B: ExtendedBufRead> ExtendedBufRead for HeadersThenBody<H, B> {
fn set_progress_handler(&mut self, handle_progress: Option<HandleProgress>) {
self.body.set_progress_handler(handle_progress)
}

fn peek_data_line(&mut self) -> Option<io::Result<Result<&[u8], git_packetline::decode::Error>>> {
self.body.peek_data_line()
}
}

pub fn connect(url: &str, version: crate::Protocol) -> Result<Transport<Impl>, Infallible> {
Expand Down
4 changes: 4 additions & 0 deletions git-transport/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,16 @@ impl<'a> RequestWriter<'a> {

pub trait ExtendedBufRead: io::BufRead {
fn set_progress_handler(&mut self, handle_progress: Option<HandleProgress>);
fn peek_data_line(&mut self) -> Option<io::Result<Result<&[u8], git_packetline::decode::Error>>>;
}

impl<'a, T: io::Read> ExtendedBufRead for git_packetline::provider::ReadWithSidebands<'a, T, HandleProgress> {
fn set_progress_handler(&mut self, handle_progress: Option<HandleProgress>) {
self.set_progress_handler(handle_progress)
}
fn peek_data_line(&mut self) -> Option<io::Result<Result<&[u8], git_packetline::decode::Error>>> {
self.peek_data_line()
}
}

pub type HandleProgress = Box<dyn FnMut(bool, &[u8])>;
Expand Down
6 changes: 3 additions & 3 deletions tasks.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
### Cloning
* **git-transport**
* a way to support shallow lines during V1 handshake (doesnt' seem to happen in V2 at all)
* [ ] a way to support shallow lines during V1 handshake (doesnt' seem to happen in V2 at all)
* **git-protocol**
* [ ] delegate interaction to support clone
* [ ] parse server negotiation response
* [ ] negotiation via delegate
* [ ] pack file receive passed to delegate
* [ ] assure there is a way to do fetches with have/want negotiation
* [ ] received pack file passed to delegate
* [x] assure there is a way to do fetches with have/want negotiation
* **gixp-pack-receive**
* [ ] hookup `git-protocol` with delegate to allow for receiving full packs
* [ ] **gixp-pack-receive** may optionally write received refs to the specified directory
Expand Down

0 comments on commit 0c0c575

Please sign in to comment.