diff options
author | Katharina Fey <kookie@spacekookie.de> | 2020-10-31 18:57:39 +0100 |
---|---|---|
committer | Mx Kookie <kookie@spacekookie.de> | 2020-12-21 05:10:08 +0100 |
commit | 9dacf748651ea7139c0e9f3dee9ae66d949bf73f (patch) | |
tree | 7101bc20d5a531218ccd1b4cb9e04c67995f6d0e /apps/servers/octopus/supergit | |
parent | 4e09fe2509904ee64d2470ca8d41006d51e4ffd6 (diff) |
Add 'apps/servers/octopus/' from commit '623954d19fdf0dca47db319e5c88ee561aa8d25c'
git-subtree-dir: apps/servers/octopus
git-subtree-mainline: 4e09fe2509904ee64d2470ca8d41006d51e4ffd6
git-subtree-split: 623954d19fdf0dca47db319e5c88ee561aa8d25c
Diffstat (limited to '')
-rw-r--r-- | apps/servers/octopus/supergit/Cargo.toml | 10 | ||||
-rw-r--r-- | apps/servers/octopus/supergit/src/bin/test.rs | 16 | ||||
-rw-r--r-- | apps/servers/octopus/supergit/src/branch.rs | 22 | ||||
-rw-r--r-- | apps/servers/octopus/supergit/src/commit.rs | 11 | ||||
-rw-r--r-- | apps/servers/octopus/supergit/src/diff.rs | 5 | ||||
-rw-r--r-- | apps/servers/octopus/supergit/src/files.rs | 7 | ||||
-rw-r--r-- | apps/servers/octopus/supergit/src/lib.rs | 55 | ||||
-rw-r--r-- | apps/servers/octopus/supergit/src/raw/#tree_walk.rs# | 1 | ||||
l--------- | apps/servers/octopus/supergit/src/raw/.#tree_walk.rs | 1 | ||||
-rw-r--r-- | apps/servers/octopus/supergit/src/raw/branch_walk.rs | 19 | ||||
-rw-r--r-- | apps/servers/octopus/supergit/src/raw/mod.rs | 45 | ||||
-rw-r--r-- | apps/servers/octopus/supergit/src/raw/tree_walk.rs | 1 |
12 files changed, 193 insertions, 0 deletions
diff --git a/apps/servers/octopus/supergit/Cargo.toml b/apps/servers/octopus/supergit/Cargo.toml new file mode 100644 index 000000000000..029503e87c44 --- /dev/null +++ b/apps/servers/octopus/supergit/Cargo.toml @@ -0,0 +1,10 @@ +[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" +async-std = { version = "1.0", features = ["unstable"] }
\ No newline at end of file diff --git a/apps/servers/octopus/supergit/src/bin/test.rs b/apps/servers/octopus/supergit/src/bin/test.rs new file mode 100644 index 000000000000..166047e9dd17 --- /dev/null +++ b/apps/servers/octopus/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 <path>"); + std::process::exit(2); + } + }; + + let rr = RawRepository::open(path.as_str()).unwrap(); + +} diff --git a/apps/servers/octopus/supergit/src/branch.rs b/apps/servers/octopus/supergit/src/branch.rs new file mode 100644 index 000000000000..81abbffed112 --- /dev/null +++ b/apps/servers/octopus/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/apps/servers/octopus/supergit/src/commit.rs b/apps/servers/octopus/supergit/src/commit.rs new file mode 100644 index 000000000000..46a6ab4f7c8b --- /dev/null +++ b/apps/servers/octopus/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/apps/servers/octopus/supergit/src/diff.rs b/apps/servers/octopus/supergit/src/diff.rs new file mode 100644 index 000000000000..e92a4cd1804c --- /dev/null +++ b/apps/servers/octopus/supergit/src/diff.rs @@ -0,0 +1,5 @@ + +/// A diff between two commits +pub struct Diff { + +} diff --git a/apps/servers/octopus/supergit/src/files.rs b/apps/servers/octopus/supergit/src/files.rs new file mode 100644 index 000000000000..681b8877256f --- /dev/null +++ b/apps/servers/octopus/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/apps/servers/octopus/supergit/src/lib.rs b/apps/servers/octopus/supergit/src/lib.rs new file mode 100644 index 000000000000..887ccc029e1f --- /dev/null +++ b/apps/servers/octopus/supergit/src/lib.rs @@ -0,0 +1,55 @@ +//! 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}; + +mod commit; +pub use commit::{CommitId, Commit}; + +mod diff; +pub use diff::Diff; + +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 { + raw: RawRepository, +} + +impl Repository { + pub fn open(path: &std::path::Path) -> Arc<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) { + todo!() + } +} + +/////////// 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/apps/servers/octopus/supergit/src/raw/#tree_walk.rs# b/apps/servers/octopus/supergit/src/raw/#tree_walk.rs# new file mode 100644 index 000000000000..a693f624af46 --- /dev/null +++ b/apps/servers/octopus/supergit/src/raw/#tree_walk.rs# @@ -0,0 +1 @@ +//! Walk the file tree for a particular commit
\ No newline at end of file diff --git a/apps/servers/octopus/supergit/src/raw/.#tree_walk.rs b/apps/servers/octopus/supergit/src/raw/.#tree_walk.rs new file mode 120000 index 000000000000..a0d266615930 --- /dev/null +++ b/apps/servers/octopus/supergit/src/raw/.#tree_walk.rs @@ -0,0 +1 @@ +spacekookie@qq.53166
\ No newline at end of file diff --git a/apps/servers/octopus/supergit/src/raw/branch_walk.rs b/apps/servers/octopus/supergit/src/raw/branch_walk.rs new file mode 100644 index 000000000000..d4232c486560 --- /dev/null +++ b/apps/servers/octopus/supergit/src/raw/branch_walk.rs @@ -0,0 +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<String>, + /// Map of commit IDs to commit metadata + meta: BTreeMap<String, CommitNode>, +} + +pub struct CommitNode { + id: String, + author: String, + commiter: String, + message: String, + touches: BTreeSet<String>, + time: u64, +} diff --git a/apps/servers/octopus/supergit/src/raw/mod.rs b/apps/servers/octopus/supergit/src/raw/mod.rs new file mode 100644 index 000000000000..7bf6c0a396a4 --- /dev/null +++ b/apps/servers/octopus/supergit/src/raw/mod.rs @@ -0,0 +1,45 @@ +//! Raw representation wrappers for libgit2 + +mod branch_walk; +mod tree_walk; + +use crate::{Branch, BranchCommit}; +use git2::{self, Repository}; + +pub type RawResult<T> = Result<T, RawError>; + +/// An error abstraction for raw git operations +#[derive(Debug)] +pub enum RawError { + AllBad, +} + +impl From<git2::Error> for RawError { + fn from(_: git2::Error) -> Self { + Self::AllBad + } +} + +/// Represent a raw branch +pub struct RawBranch { + name: String, + head: String, +} + +/// Wrap a libgit2 repository to provide an API fascade +pub struct RawRepository { + inner: Repository, +} + +impl RawRepository { + pub fn open(path: &str) -> RawResult<Self> { + Ok(Self { + inner: Repository::open(path)?, + }) + } + + /// Parse branch data from repository + pub fn parse_branches(&self) -> RawResult<Vec<RawBranch>> { + todo!() + } +} diff --git a/apps/servers/octopus/supergit/src/raw/tree_walk.rs b/apps/servers/octopus/supergit/src/raw/tree_walk.rs new file mode 100644 index 000000000000..05337640cd19 --- /dev/null +++ b/apps/servers/octopus/supergit/src/raw/tree_walk.rs @@ -0,0 +1 @@ +//! Walk the file tree for a particular commit |