gix_protocol/handshake/refs/
blocking_io.rs

1use crate::transport::client::blocking_io::ReadlineBufRead;
2use crate::{
3    fetch::response::ShallowUpdate,
4    handshake::{refs, refs::parse::Error, Ref},
5};
6
7/// Parse refs from the given input line by line. Protocol V2 is required for this to succeed.
8pub fn from_v2_refs(in_refs: &mut dyn ReadlineBufRead) -> Result<Vec<Ref>, Error> {
9    let mut out_refs = Vec::new();
10    while let Some(line) = in_refs.readline().transpose()?.transpose()?.and_then(|l| l.as_bstr()) {
11        out_refs.push(refs::shared::parse_v2(line)?);
12    }
13    Ok(out_refs)
14}
15
16/// Parse refs from the return stream of the handshake as well as the server capabilities, also received as part of the
17/// handshake.
18/// Together they form a complete set of refs.
19///
20/// # Note
21///
22/// Symbolic refs are shoe-horned into server capabilities whereas refs (without symbolic ones) are sent automatically as
23/// part of the handshake. Both symbolic and peeled refs need to be combined to fit into the [`Ref`] type provided here.
24pub fn from_v1_refs_received_as_part_of_handshake_and_capabilities<'a>(
25    in_refs: &mut dyn ReadlineBufRead,
26    capabilities: impl Iterator<Item = gix_transport::client::capabilities::Capability<'a>>,
27) -> Result<(Vec<Ref>, Vec<ShallowUpdate>), Error> {
28    let mut out_refs = refs::shared::from_capabilities(capabilities)?;
29    let mut out_shallow = Vec::new();
30    let number_of_possible_symbolic_refs_for_lookup = out_refs.len();
31
32    while let Some(line) = in_refs.readline().transpose()?.transpose()?.and_then(|l| l.as_bstr()) {
33        refs::shared::parse_v1(
34            number_of_possible_symbolic_refs_for_lookup,
35            &mut out_refs,
36            &mut out_shallow,
37            line,
38        )?;
39    }
40    Ok((out_refs.into_iter().map(Into::into).collect(), out_shallow))
41}