diff --git a/Cargo.lock b/Cargo.lock index 69e1bfc00de..4b63e15bd7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -258,11 +258,19 @@ version = "0.0.0" [[package]] name = "gitoxide" version = "1.0.0" +dependencies = [ + "anyhow", + "gitoxide-core", + "structopt", +] + +[[package]] +name = "gitoxide-core" +version = "0.1.0" dependencies = [ "anyhow", "git-odb", "git-repository", - "structopt", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 021d108aeab..0822275aec6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,7 @@ test = false doctest = false [dependencies] -git-repository = { version = "0.1.0", path = "git-repository" } -git-odb = { version = "0.1.0", path = "git-odb", default-features = false, features = ["fast-sha1"] } +gitoxide-core = { version = "0.1.0", path = "gitoxide-core" } anyhow = "1.0.31" structopt = "0.3.14" @@ -28,6 +27,7 @@ incremental = false [workspace] members = [ + "gitoxide-core", "git-object", "git-odb", "git-repository", diff --git a/README.md b/README.md index 83a8a7bb8fe..048bbbf871a 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,12 @@ [![Rust](https://github.com/Byron/git-oxide/workflows/Rust/badge.svg)](https://github.com/Byron/git-oxide/actions) **gio** is a command-line interface (*CLI*) to access git repositories. It's written to optimize the -user-experience, and perform as good or better than the native implementation. +user-experience, and perform as good or better than the native implementation, and make git tooling more +hackable. -The CLI uses various libraries to implement +The CLI uses various crates, please see _'Development Status'_ for details. - * [ ] a git *repository* and *references* (see `git-core`) - * [ ] encoding and decoding git objects (see `git-object`) - * [ ] a git object database (see `git-odb` and - [examples](https://github.com/Byron/git-oxide/tree/master/lib/git-odb/examples)) - * [ ] a transport layer for push and pull (see `git-transport`) - - **This project is early in development and currently strictly for fun** - - **Currently I am implementing whatever is needed to set a new record for solving - [this - problem](https://github.com/gitpython-developers/GitPython/issues/765#issuecomment-396072153)** - -## Tasks +## Development Status * **git-repository** * [x] initialize @@ -212,3 +201,8 @@ Thus one has to post-process the file by reducing its size by one using `truncat * **deflate2** _(MIT Licensed)_ * We use various abstractions to implement decompression and compression directly on top of the rather low-level `miniz_oxide` crate +## Fun facts + +* Originally I was really fascinated by [this problem](https://github.com/gitpython-developers/GitPython/issues/765#issuecomment-396072153) + and believe that with `gitoxide` it will be possible to provide the fastest implementation for that problem. + diff --git a/gitoxide-core/Cargo.toml b/gitoxide-core/Cargo.toml new file mode 100644 index 00000000000..ae6a8239eec --- /dev/null +++ b/gitoxide-core/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "gitoxide-core" +description = "The library implementating all capabilities of the gitoxide CLI" +version = "0.1.0" +authors = ["Sebastian Thiel "] +publish = false +license = "MIT" +edition = "2018" + +[dependencies] +git-repository = { version = "0.1.0", path = "../git-repository" } +git-odb = { version = "0.1.0", path = "../git-odb", default-features = false, features = ["fast-sha1"] } +anyhow = "1.0.31" diff --git a/gitoxide-core/src/lib.rs b/gitoxide-core/src/lib.rs new file mode 100644 index 00000000000..30c04642ce2 --- /dev/null +++ b/gitoxide-core/src/lib.rs @@ -0,0 +1,13 @@ +use anyhow::{Context, Result}; +use std::{io, path::Path}; + +pub fn init() -> Result<()> { + git_repository::init::repository().with_context(|| "Repository initialization failed") +} + +pub fn verify_pack_or_pack_index(path: impl AsRef, mut out: impl io::Write) -> Result<()> { + let pack = git_odb::pack::File::at(path).with_context(|| "Could not open pack file")?; + pack.verify_checksum().with_context(|| "Failed")?; + writeln!(out, "OK")?; + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 658f7b7670d..925a9ac0b55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ #![forbid(unsafe_code)] -use anyhow::{Context, Result}; +use anyhow::Result; +use gitoxide_core as core; +use std::io::stdout; use structopt::StructOpt; mod options { @@ -48,16 +50,10 @@ mod options { fn main() -> Result<()> { let args = options::Args::from_args(); match args.cmd { - options::Subcommands::Init => { - git_repository::init::repository().with_context(|| "Repository initialization failed") - } + options::Subcommands::Init => core::init(), options::Subcommands::Plumbing(cmd) => match cmd { options::Plumbing::VerifyPack { path } => { - let pack = - git_odb::pack::File::at(path).with_context(|| "Could not open pack file")?; - pack.verify_checksum().with_context(|| "Failed")?; - println!("OK"); - Ok(()) + core::verify_pack_or_pack_index(path, stdout()) } }, }?;