use bytes::Bytes;
use thrussh::{server::Session, ChannelId};
use crate::{
git::{
packfile::low_level::{PackFile, PackFileEntry},
PktLine,
},
Handler,
};
pub(crate) fn handle(
handle: &mut Handler,
session: &mut Session,
channel: ChannelId,
metadata: Vec<Bytes>,
packfile_entries: Vec<PackFileEntry<'_>>,
) -> Result<(), anyhow::Error> {
let done = metadata.iter().any(|v| v.as_ref() == b"done");
if !done {
handle.write(PktLine::Data(b"acknowledgments\n"))?;
handle.write(PktLine::Data(b"ready\n"))?;
handle.write(PktLine::Delimiter)?;
}
handle.write(PktLine::Data(b"packfile\n"))?;
handle.write(PktLine::SidebandMsg(b"Hello from chartered!\n"))?;
handle.flush(session, channel);
let packfile = PackFile::new(packfile_entries);
handle.write(PktLine::SidebandData(packfile))?;
handle.write(PktLine::Flush)?;
handle.flush(session, channel);
session.exit_status_request(channel, 0);
session.eof(channel);
session.close(channel);
Ok(())
}