This commit is contained in:
Hubert 2021-07-18 06:06:49 +02:00
parent dc26021c43
commit a2dcab2ea8
2 changed files with 12 additions and 12 deletions

View File

@ -13,15 +13,15 @@ impl GitRepo {
Repository::open(path).map(|git2| GitRepo{git2}) Repository::open(path).map(|git2| GitRepo{git2})
} }
pub fn get_root_tree<'a, 'b> (&'a self, commit : &'b GitCommit) -> Result<GitBrowseDir<'a>, git2::Error> { pub fn get_root_tree<'a, 'b> (&'a self, commit : &'b GitCommit) -> Result<GitDir<'a>, git2::Error> {
let oid = Oid::from_str(&commit.0)?; let oid = Oid::from_str(&commit.0)?;
let commit = self.git2.find_commit(oid)?; let commit = self.git2.find_commit(oid)?;
let tree = commit.tree()?; let tree = commit.tree()?;
let fullname = "/".to_string(); let fullname = "/".to_string();
Ok(GitBrowseDir{ fullname, tree }) Ok(GitDir { fullname, tree })
} }
pub async fn browse<'a>(&'a self, dir: &GitBrowseDir<'a>) -> Result<Vec<GitBrowseEntry<'a>>, git2::Error> { pub async fn browse<'a>(&'a self, dir: &GitDir<'a>) -> Result<Vec<GitBrowseEntry<'a>>, git2::Error> {
let mut res = Vec::new(); let mut res = Vec::new();
for entry in dir.tree.iter() { for entry in dir.tree.iter() {
match entry.kind() { match entry.kind() {
@ -33,12 +33,12 @@ impl GitRepo {
let name = entry.name().ok_or(git2::Error::from_str("entry must have valid utf8 name"))?; let name = entry.name().ok_or(git2::Error::from_str("entry must have valid utf8 name"))?;
let fullname = dir.fullname.clone().add(name); let fullname = dir.fullname.clone().add(name);
let subtree = self.git2.find_tree(entry.id())?; let subtree = self.git2.find_tree(entry.id())?;
res.push(GitBrowseEntry::EGitDir(GitBrowseDir{fullname, tree : subtree})); res.push(GitBrowseEntry::EGitDir(GitDir {fullname, tree : subtree}));
} }
ObjectType::Blob => { ObjectType::Blob => {
let name = entry.name().ok_or(git2::Error::from_str("entry must have valid utf8 name"))?; let name = entry.name().ok_or(git2::Error::from_str("entry must have valid utf8 name"))?;
let fullname = dir.fullname.clone().add(name); let fullname = dir.fullname.clone().add(name);
res.push(GitBrowseEntry::EGitFile(GitBrowseFile(fullname))); res.push(GitBrowseEntry::EGitFile(GitFile(fullname)));
} }
ObjectType::Tag => {Err(git2::Error::from_str("tree entry cannot be of kind tag"))?;} ObjectType::Tag => {Err(git2::Error::from_str("tree entry cannot be of kind tag"))?;}
} }
@ -65,20 +65,20 @@ impl Display for GitCommit {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct GitBrowseFile (String); pub struct GitFile(String);
#[derive(Debug)] #[derive(Debug)]
pub struct GitBrowseDir<'a>{ pub struct GitDir<'a>{
fullname: String, fullname: String,
tree : git2::Tree<'a>, tree : git2::Tree<'a>,
} }
impl Display for GitBrowseFile { impl Display for GitFile {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0) write!(f, "{}", self.0)
} }
} }
impl Display for GitBrowseDir<'_> { impl Display for GitDir<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.fullname) write!(f, "{}", self.fullname)
} }
@ -86,8 +86,8 @@ impl Display for GitBrowseDir<'_> {
#[derive(Debug)] #[derive(Debug)]
pub enum GitBrowseEntry<'a> { pub enum GitBrowseEntry<'a> {
EGitFile(GitBrowseFile), EGitFile(GitFile),
EGitDir(GitBrowseDir<'a>) EGitDir(GitDir<'a>)
} }
impl Display for GitBrowseEntry<'_> { impl Display for GitBrowseEntry<'_> {

View File

@ -14,7 +14,7 @@ use actix_web_httpauth::middleware::HttpAuthentication;
use actix_web::dev::ServiceRequest; use actix_web::dev::ServiceRequest;
use actix_web_httpauth::extractors::basic::{BasicAuth, Config}; use actix_web_httpauth::extractors::basic::{BasicAuth, Config};
use actix_web_httpauth::extractors::AuthenticationError; use actix_web_httpauth::extractors::AuthenticationError;
use crate::git::{GitBrowseEntry, GitRepo, GitCommit, GitBrowseDir}; use crate::git::{GitBrowseEntry, GitRepo, GitCommit, GitDir};
use actix_web::middleware::Logger; use actix_web::middleware::Logger;
use env_logger::Env; use env_logger::Env;
use crate::ite::SuperIterator; use crate::ite::SuperIterator;