#anni #git #client

anni-fetch

A library focuses on what git fetch does

3 unstable releases

0.2.0 Mar 18, 2021
0.1.1 Mar 17, 2021
0.1.0 Mar 17, 2021

#621 in #git

27 downloads per month

Apache-2.0

34KB
695 lines

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");
}

Dependencies

~2.9–4MB
~105K SLoC