anni-fetch

Crates.ioanni-fetch
lib.rsanni-fetch
version0.2.0
sourcesrc
created_at2021-03-17 13:06:39.472144
updated_at2021-03-18 02:08:00.207769
descriptionA library focuses on what git fetch does.
homepage
repositoryhttps://github.com/project-anni/anni-fetch
max_upload_size
id370119
size46,035
Yesterday17 (Yesterday17)

documentation

README

anni-fetch

crates.io API

A library focuses on what git fetch does.

Example

use anni_fetch::client::Message::PackData;
use anni_fetch::{Pack, Client};
use std::io::Cursor;
use anni_fetch::client::RequestBuilder;

fn main() {
    // create client
    let client = Client::new("https://github.com/project-anni/repo.git");

    // request and get message iterator
    let iter = client.request(
        RequestBuilder::new(true)
            .command("fetch")
            .argument("thin-pack")
            .argument("ofs-delta")
            .argument("deepen 1")
            .want(&client.ls_ref("HEAD").expect("failed to get sha1 of HEAD"))
            .argument("done")
            .build()
    ).unwrap();

    // prepare buffer for pack
    let mut pack = Vec::new();
    for msg in iter {
        match msg {
            // receive and insert into pack
            PackData(mut d) => pack.append(&mut d),
            _ => {}
        }
    }
    let mut cursor = Cursor::new(pack);

    // read pack
    Pack::from_reader(&mut cursor).expect("invalid pack file");
}
Commit count: 18

cargo fmt