aboutsummaryrefslogtreecommitdiff
path: root/apps/servers/octopus/supergit/src/repo.rs
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-11-03 21:08:38 +0100
committerMx Kookie <kookie@spacekookie.de>2020-12-21 05:19:28 +0100
commit70fe187f1e118b6e63e512b6718635561682dad4 (patch)
tree1ae04ed78cee3dee951400f7d99642f885ef4cd9 /apps/servers/octopus/supergit/src/repo.rs
parent8be6dc679e97053da8f173333578ed626466d3de (diff)
octopus: refactoring & typed branch parsing
This code is work-in-progress, and doesn't work on a repo that has a branched history. The issue here is that after handling a merge commit, keeping track of which commit to look at next is non-trivial. This solution tries to isuse a "skip" command on the walker, but this can accidentally skip commits, when two merges have happened in succession (maybe a bug with the impl, not the concept). But also, the actual merge commit seems to already be part of the norma history? So maybe we can ommit the merge commit explicitly, and simply return a new branch handle instead.
Diffstat (limited to '')
-rw-r--r--apps/servers/octopus/supergit/src/repo.rs (renamed from apps/servers/octopus/supergit/src/raw/mod.rs)48
1 files changed, 26 insertions, 22 deletions
diff --git a/apps/servers/octopus/supergit/src/raw/mod.rs b/apps/servers/octopus/supergit/src/repo.rs
index 80bff3528f3d..37991c3a560f 100644
--- a/apps/servers/octopus/supergit/src/raw/mod.rs
+++ b/apps/servers/octopus/supergit/src/repo.rs
@@ -1,20 +1,25 @@
//! Raw representation wrappers for libgit2
-mod branch;
-pub use branch::RawBranch;
-
-mod branch_walk;
-mod tree_walk;
-
use crate::{Branch, BranchCommit};
-use git2::{self, Oid, Repository};
+use git2::{self, Oid};
+use std::sync::Arc;
-pub type RawResult<T> = Result<T, RawError>;
+pub type GitResult<T> = Result<T, GitError>;
/// The hex ID of a commit
-#[derive(Debug)]
+#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct HashId(String);
+impl HashId {
+ pub fn to_oid(&self) -> Oid {
+ self.clone().into()
+ }
+
+ pub fn to_string(&self) -> String {
+ self.0.clone()
+ }
+}
+
impl From<Oid> for HashId {
fn from(o: Oid) -> Self {
Self(o.to_string())
@@ -39,28 +44,28 @@ impl<'any> From<&'any HashId> for Oid {
}
}
-
/// An error abstraction for raw git operations
#[derive(Debug)]
-pub enum RawError {
+pub enum GitError {
AllBad,
}
-impl From<git2::Error> for RawError {
+impl From<git2::Error> for GitError {
fn from(_: git2::Error) -> Self {
Self::AllBad
}
}
-/// Wrap a libgit2 repository to provide an API fascade
-pub struct RawRepository {
- pub inner: Repository,
+/// Represents a git repository with lazy data loading
+#[derive(Clone)]
+pub struct Repository {
+ inner: Arc<git2::Repository>,
}
-impl RawRepository {
- pub fn open(path: &str) -> RawResult<Self> {
+impl Repository {
+ pub fn open(path: &str) -> GitResult<Self> {
Ok(Self {
- inner: Repository::open(path)?,
+ inner: Arc::new(git2::Repository::open(path)?),
})
}
@@ -69,7 +74,7 @@ impl RawRepository {
/// ## Panics
///
/// If there is an error around getting the name, or head commit.
- pub fn parse_branches(&self) -> RawResult<Vec<RawBranch>> {
+ pub fn branches(&self) -> GitResult<Vec<Branch>> {
Ok(self
.inner
.branches(None)?
@@ -78,14 +83,13 @@ impl RawRepository {
.map(|(branch, _)| {
let name = branch.name().unwrap().unwrap().into();
let head = branch.get().peel_to_commit().unwrap().id().into();
-
- RawBranch { name, head }
+ Branch::new(&self.inner, name, head)
})
.collect())
}
/// Get the files touched by a commit
- pub fn get_files_for(&self, id: HashId) -> RawResult<Vec<()>> {
+ pub fn get_files_for(&self, id: HashId) -> GitResult<Vec<()>> {
let c = self.inner.find_commit(id.into())?;
let tree = c.tree()?;