git no longer erroring when pulling
Diff
src/main.rs | 38 ++++++++++++++++++++++++++++++++------
src/git/packfile.rs | 25 +++++++++++++++++++------
2 files changed, 42 insertions(+), 21 deletions(-)
@@ -1,8 +1,9 @@
pub mod git;
use crate::git::PktLine;
use bytes::BytesMut;
use bytes::BufMut;
use futures::future::Future;
use git::codec::Encoder;
use git::codec::GitCodec;
@@ -141,6 +142,7 @@
Box::pin(async move {
let mut ls_refs = false;
let mut fetch = false;
let mut done = false;
while let Some(frame) = self.codec.decode(&mut self.input_bytes)? {
eprintln!("data: {:x?}", frame);
@@ -149,13 +151,15 @@
ls_refs = true;
} else if frame.as_ref() == "command=fetch".as_bytes() {
fetch = true;
} else if frame.as_ref() == "done".as_bytes() {
done = true;
}
}
if ls_refs {
@@ -165,22 +169,36 @@
}
if fetch {
self.write(PktLine::Data(b"acknowledgments\n"))?;
self.write(PktLine::Data(b"ready\n"))?;
self.write(PktLine::Delimiter)?;
done = true;
}
if done {
self.write(PktLine::Data(b"packfile\n"))?;
let packfile = git::packfile::PackFile::new(vec![git::packfile::PackFileEntry::new(
git::packfile::PackFileEntryType::Blob,
b"testing this is a test cool test",
b"testing this is a test cool test!",
)?]);
{
let mut buf = BytesMut::new();
let packfile_index = git::packfile::PackFileIndex {
packfile: &packfile,
};
packfile_index.encode_to(&mut buf)?;
self.write(PktLine::Data(buf.as_ref()))?;
}
{
let mut buf = BytesMut::new();
buf.put_u8(1);
packfile.encode_to(&mut buf)?;
self.write(PktLine::Data(buf.as_ref()))?;
}
@@ -1,8 +1,9 @@
use bytes::{BufMut, BytesMut};
use const_sha1::{sha1, ConstBuffer};
use flate2::{write::ZlibEncoder, Compression};
use std::convert::TryInto;
use std::io::Write as IoWrite;
use sha1::{Sha1, Digest};
@@ -15,13 +16,11 @@
impl<'a> PackFileIndex<'a> {
pub fn encode_to(self, original_buf: &mut BytesMut) -> Result<(), anyhow::Error> {
use sha1::{Sha1, Digest};
let mut buf = original_buf.split();
let mut buf = original_buf.split_off(original_buf.len());
buf.extend_from_slice(&[255u8, 116u8, 79u8, 99u8]);
buf.extend_from_slice(b"\xfftOc");
buf.put_u32(2);
@@ -113,18 +112,22 @@
pub const fn header_size() -> usize {
4 + std::mem::size_of::<u32>() + std::mem::size_of::<u32>()
}
pub fn encode_to(&self, original_buf: &mut BytesMut) -> Result<(), anyhow::Error> {
let mut buf = original_buf.split_off(original_buf.len());
pub fn encode_to(self, buf: &mut BytesMut) -> Result<(), anyhow::Error> {
buf.extend_from_slice(b"PACK");
buf.put_u32(2);
buf.put_u32(self.entries.len().try_into().unwrap());
for entry in &self.entries {
entry.encode_to(buf)?;
entry.encode_to(&mut buf)?;
}
buf.extend_from_slice(&self.hash);
buf.extend_from_slice(&sha1::Sha1::digest(&buf[..]));
original_buf.unsplit(buf);
Ok(())
}
}
@@ -191,9 +194,9 @@
})
}
fn size_of_data_be(&self) -> usize {
self.uncompressed_size.to_be()
}
@@ -203,7 +206,7 @@
fn write_header(&self, buf: &mut BytesMut) {
let mut size = self.size_of_data_be();
let mut size = self.uncompressed_size;
{