aboutsummaryrefslogtreecommitdiff
path: root/supergit
diff options
context:
space:
mode:
Diffstat (limited to 'supergit')
-rw-r--r--supergit/Cargo.toml9
-rw-r--r--supergit/src/branch.rs22
-rw-r--r--supergit/src/commit.rs11
-rw-r--r--supergit/src/files.rs7
-rw-r--r--supergit/src/lib.rs39
-rw-r--r--supergit/src/raw/mod.rs39
6 files changed, 127 insertions, 0 deletions
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 <kookie@spacekookie.de>"]
+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<BranchCommit>,
+}
+
+/// 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<Branch>),
+}
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<T> = Result<T, RawError>;
+
+/// An error abstraction for raw git operations
+#[derive(Debug)]
+pub(crate) enum RawError {
+ AllBad,
+}
+
+impl From<git2::Error> 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<Self> {
+ 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(())
+ }
+}