gix_protocol/handshake/refs/
blocking_io.rs

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