From 623954d19fdf0dca47db319e5c88ee561aa8d25c Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Tue, 27 Oct 2020 15:15:23 +0100 Subject: Adding raw git repository utilities --- supergit/Cargo.toml | 3 ++- supergit/src/bin/test.rs | 16 ++++++++++++++++ supergit/src/lib.rs | 19 ++++++++++++++++--- supergit/src/raw/branch_walk.rs | 18 ++++++++++++++++++ supergit/src/raw/mod.rs | 25 ++++++++++++++----------- 5 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 supergit/src/bin/test.rs (limited to 'supergit') diff --git a/supergit/Cargo.toml b/supergit/Cargo.toml index 7fdb253..029503e 100644 --- a/supergit/Cargo.toml +++ b/supergit/Cargo.toml @@ -6,4 +6,5 @@ authors = ["Mx Kookie "] edition = "2018" [dependencies] -git2 = "0.11" \ No newline at end of file +git2 = "0.11" +async-std = { version = "1.0", features = ["unstable"] } \ No newline at end of file diff --git a/supergit/src/bin/test.rs b/supergit/src/bin/test.rs new file mode 100644 index 0000000..166047e --- /dev/null +++ b/supergit/src/bin/test.rs @@ -0,0 +1,16 @@ +//! A test binary to use during development + +use supergit::raw::RawRepository; + +fn main() { + let path = match std::env::args().nth(1) { + Some(p) => p, + None => { + eprintln!("USAGE: supergit-test "); + std::process::exit(2); + } + }; + + let rr = RawRepository::open(path.as_str()).unwrap(); + +} diff --git a/supergit/src/lib.rs b/supergit/src/lib.rs index e209fac..887ccc0 100644 --- a/supergit/src/lib.rs +++ b/supergit/src/lib.rs @@ -1,5 +1,13 @@ //! Strongly typed git repository explorer library //! +//! This library exposes a read-only view into a git repository. To +//! get started, open an existing bare repo, and then call `sync()` to +//! build a cache of it. Every time you want your view of the repo to +//! update, call `sync()` again. If you want the sync operation to be +//! blocking, call `sync_blocking()` instead. +//! +//! + mod branch; pub use branch::{Branch, BranchCommit}; @@ -10,15 +18,20 @@ pub use commit::{CommitId, Commit}; mod diff; pub use diff::Diff; -pub(crate) mod raw; +pub mod raw; use std::sync::atomic::{AtomicUsize, Ordering}; +use async_std::sync::{Arc, RwLock}; + +use raw::RawRepository; /// Represents a git repository with lazy data loading -pub struct Repository {} +pub struct Repository { + raw: RawRepository, +} impl Repository { - pub fn open(path: &std::path::Path) -> Self { + pub fn open(path: &std::path::Path) -> Arc { todo!() } diff --git a/supergit/src/raw/branch_walk.rs b/supergit/src/raw/branch_walk.rs index dfc7485..d4232c4 100644 --- a/supergit/src/raw/branch_walk.rs +++ b/supergit/src/raw/branch_walk.rs @@ -1 +1,19 @@ //! Walk along a branch parsing commit metadata + +use std::collections::{BTreeMap, BTreeSet}; + +pub struct CommitHistory { + /// The correct order of commit IDs + order: Vec, + /// Map of commit IDs to commit metadata + meta: BTreeMap, +} + +pub struct CommitNode { + id: String, + author: String, + commiter: String, + message: String, + touches: BTreeSet, + time: u64, +} diff --git a/supergit/src/raw/mod.rs b/supergit/src/raw/mod.rs index 98602ca..7bf6c0a 100644 --- a/supergit/src/raw/mod.rs +++ b/supergit/src/raw/mod.rs @@ -3,13 +3,14 @@ mod branch_walk; mod tree_walk; +use crate::{Branch, BranchCommit}; use git2::{self, Repository}; -pub(crate) type RawResult = Result; +pub type RawResult = Result; /// An error abstraction for raw git operations #[derive(Debug)] -pub(crate) enum RawError { +pub enum RawError { AllBad, } @@ -19,24 +20,26 @@ impl From for RawError { } } +/// Represent a raw branch +pub struct RawBranch { + name: String, + head: String, +} + /// Wrap a libgit2 repository to provide an API fascade -pub(crate) struct RawRepository { +pub struct RawRepository { inner: Repository, } impl RawRepository { - pub(crate) fn open(path: &str) -> RawResult { + pub fn open(path: &str) -> RawResult { Ok(Self { inner: Repository::open(path)?, }) } - /// Sync the backing storage with the backing git repo - /// - /// This function can be invoked manually, but should be invoked - /// basically every time your program expects changes to have - /// happened. Polling this function is not recommended. - pub(crate) fn update(&self) -> RawResult<()> { - Ok(()) + /// Parse branch data from repository + pub fn parse_branches(&self) -> RawResult> { + todo!() } } -- cgit v1.2.3