aboutsummaryrefslogtreecommitdiff
path: root/apps/servers/octopus/supergit/src/raw/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'apps/servers/octopus/supergit/src/raw/mod.rs')
-rw-r--r--apps/servers/octopus/supergit/src/raw/mod.rs65
1 files changed, 57 insertions, 8 deletions
diff --git a/apps/servers/octopus/supergit/src/raw/mod.rs b/apps/servers/octopus/supergit/src/raw/mod.rs
index 7bf6c0a396a4..80bff3528f3d 100644
--- a/apps/servers/octopus/supergit/src/raw/mod.rs
+++ b/apps/servers/octopus/supergit/src/raw/mod.rs
@@ -1,13 +1,45 @@
//! Raw representation wrappers for libgit2
+mod branch;
+pub use branch::RawBranch;
+
mod branch_walk;
mod tree_walk;
use crate::{Branch, BranchCommit};
-use git2::{self, Repository};
+use git2::{self, Oid, Repository};
pub type RawResult<T> = Result<T, RawError>;
+/// The hex ID of a commit
+#[derive(Debug)]
+pub struct HashId(String);
+
+impl From<Oid> for HashId {
+ fn from(o: Oid) -> Self {
+ Self(o.to_string())
+ }
+}
+
+impl From<HashId> for Oid {
+ fn from(hid: HashId) -> Self {
+ Oid::from_str(hid.0.as_str()).expect(&format!(
+ "Tried turning an invalid HashId variant into an Oid: {:?}",
+ hid
+ ))
+ }
+}
+
+impl<'any> From<&'any HashId> for Oid {
+ fn from(hid: &'any HashId) -> Self {
+ Oid::from_str(hid.0.as_str()).expect(&format!(
+ "Tried turning an invalid HashId variant into an Oid: {:?}",
+ hid
+ ))
+ }
+}
+
+
/// An error abstraction for raw git operations
#[derive(Debug)]
pub enum RawError {
@@ -20,15 +52,9 @@ impl From<git2::Error> for RawError {
}
}
-/// 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,
+ pub inner: Repository,
}
impl RawRepository {
@@ -39,7 +65,30 @@ impl RawRepository {
}
/// Parse branch data from repository
+ ///
+ /// ## Panics
+ ///
+ /// If there is an error around getting the name, or head commit.
pub fn parse_branches(&self) -> RawResult<Vec<RawBranch>> {
+ Ok(self
+ .inner
+ .branches(None)?
+ .into_iter()
+ .filter_map(|e| e.ok())
+ .map(|(branch, _)| {
+ let name = branch.name().unwrap().unwrap().into();
+ let head = branch.get().peel_to_commit().unwrap().id().into();
+
+ RawBranch { name, head }
+ })
+ .collect())
+ }
+
+ /// Get the files touched by a commit
+ pub fn get_files_for(&self, id: HashId) -> RawResult<Vec<()>> {
+ let c = self.inner.find_commit(id.into())?;
+ let tree = c.tree()?;
+
todo!()
}
}