From 63cd5d0a8d3f77c0267f12a6aef52533cc2f7d09 Mon Sep 17 00:00:00 2001 From: Kaiden Fey Date: Sun, 25 Oct 2020 05:36:08 +0100 Subject: Adding a whole lot of shit (octopus and supergit) --- supergit/Cargo.toml | 9 +++++++++ supergit/src/branch.rs | 22 ++++++++++++++++++++++ supergit/src/commit.rs | 11 +++++++++++ supergit/src/files.rs | 7 +++++++ supergit/src/lib.rs | 39 +++++++++++++++++++++++++++++++++++++++ supergit/src/raw/mod.rs | 39 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 127 insertions(+) create mode 100644 supergit/Cargo.toml create mode 100644 supergit/src/branch.rs create mode 100644 supergit/src/commit.rs create mode 100644 supergit/src/files.rs create mode 100644 supergit/src/lib.rs create mode 100644 supergit/src/raw/mod.rs (limited to 'supergit') diff --git a/supergit/Cargo.toml b/supergit/Cargo.toml new file mode 100644 index 0000000..7fdb253 --- /dev/null +++ b/supergit/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "supergit" +description = "A strongly typed, read-only representation of a git repository" +version = "0.1.0" +authors = ["Mx Kookie "] +edition = "2018" + +[dependencies] +git2 = "0.11" \ No newline at end of file diff --git a/supergit/src/branch.rs b/supergit/src/branch.rs new file mode 100644 index 0000000..81abbff --- /dev/null +++ b/supergit/src/branch.rs @@ -0,0 +1,22 @@ +use crate::{Commit, CommitId}; + +/// Abstraction for a branch history slice +pub struct Branch { + name: String, + head: CommitId, + history: Vec, +} + +/// A commit represented as a relationship to a branch +/// +/// Most commits will be simple, meaning they are in sequence on the +/// branch. Two types of merge commits exist: normal, and octopus. +/// All branches leading into this branch are a reverse tree +pub enum BranchCommit { + /// A single commit + Commit(Commit), + /// A merge commit from one other branch + Merge(Branch), + /// An octopus merge with multiple branches + Octopus(Vec), +} diff --git a/supergit/src/commit.rs b/supergit/src/commit.rs new file mode 100644 index 0000000..46a6ab4 --- /dev/null +++ b/supergit/src/commit.rs @@ -0,0 +1,11 @@ +pub type CommitId = usize; + +/// Represent a commit on a repository +/// +/// This abstraction only contains metadata required to fetch the full +/// commit from disk, if it is queried. Any operation on this type +/// will block to first load +pub struct Commit { + pub id: CommitId, + hash: String, +} diff --git a/supergit/src/files.rs b/supergit/src/files.rs new file mode 100644 index 0000000..681b887 --- /dev/null +++ b/supergit/src/files.rs @@ -0,0 +1,7 @@ + +pub type FileId = usize; + +/// A file to have ever existed in a git repo +pub struct File { + id: FileId, +} diff --git a/supergit/src/lib.rs b/supergit/src/lib.rs new file mode 100644 index 0000000..3e02d30 --- /dev/null +++ b/supergit/src/lib.rs @@ -0,0 +1,39 @@ +//! Strongly typed git repository explorer library +//! + +mod branch; +pub use branch::{Branch, BranchCommit}; + +mod commit; +pub use commit::{CommitId, Commit}; + +pub(crate) mod raw; + +use std::sync::atomic::{AtomicUsize, Ordering}; + +/// Represents a git repository with lazy data loading +pub struct Repository {} + +impl Repository { + pub fn open(path: &std::path::Path) -> Self { + todo!() + } + + /// Sync the repository with the backing git files + /// + /// 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 fn sync(&self) { + + } +} + +/////////// IDs are created from the same pool to save on code size //////////// + +const ID_CTR: AtomicUsize = AtomicUsize::new(0); + +/// Get monotonically increasing IDs for objects +pub(crate) fn id() -> usize { + ID_CTR.fetch_add(1, Ordering::Relaxed) +} diff --git a/supergit/src/raw/mod.rs b/supergit/src/raw/mod.rs new file mode 100644 index 0000000..b2f67a4 --- /dev/null +++ b/supergit/src/raw/mod.rs @@ -0,0 +1,39 @@ +//! Raw representation wrappers for libgit2 + +use git2::{self, Repository}; + +pub(crate) type RawResult = Result; + +/// An error abstraction for raw git operations +#[derive(Debug)] +pub(crate) enum RawError { + AllBad, +} + +impl From for RawError { + fn from(_: git2::Error) -> Self { + Self::AllBad + } +} + +/// Wrap a libgit2 repository to provide an API fascade +pub(crate) struct RawRepository { + inner: Repository, +} + +impl RawRepository { + pub(crate) 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(()) + } +} -- cgit v1.2.3