refacto
This commit is contained in:
parent
dc26021c43
commit
a2dcab2ea8
22
src/git.rs
22
src/git.rs
|
@ -13,15 +13,15 @@ impl GitRepo {
|
|||
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 commit = self.git2.find_commit(oid)?;
|
||||
let tree = commit.tree()?;
|
||||
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();
|
||||
for entry in dir.tree.iter() {
|
||||
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 fullname = dir.fullname.clone().add(name);
|
||||
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 => {
|
||||
let name = entry.name().ok_or(git2::Error::from_str("entry must have valid utf8 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"))?;}
|
||||
}
|
||||
|
@ -65,20 +65,20 @@ impl Display for GitCommit {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GitBrowseFile (String);
|
||||
pub struct GitFile(String);
|
||||
#[derive(Debug)]
|
||||
pub struct GitBrowseDir<'a>{
|
||||
pub struct GitDir<'a>{
|
||||
fullname: String,
|
||||
tree : git2::Tree<'a>,
|
||||
}
|
||||
|
||||
impl Display for GitBrowseFile {
|
||||
impl Display for GitFile {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for GitBrowseDir<'_> {
|
||||
impl Display for GitDir<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.fullname)
|
||||
}
|
||||
|
@ -86,8 +86,8 @@ impl Display for GitBrowseDir<'_> {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum GitBrowseEntry<'a> {
|
||||
EGitFile(GitBrowseFile),
|
||||
EGitDir(GitBrowseDir<'a>)
|
||||
EGitFile(GitFile),
|
||||
EGitDir(GitDir<'a>)
|
||||
}
|
||||
|
||||
impl Display for GitBrowseEntry<'_> {
|
||||
|
|
|
@ -14,7 +14,7 @@ use actix_web_httpauth::middleware::HttpAuthentication;
|
|||
use actix_web::dev::ServiceRequest;
|
||||
use actix_web_httpauth::extractors::basic::{BasicAuth, Config};
|
||||
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 env_logger::Env;
|
||||
use crate::ite::SuperIterator;
|
||||
|
|
Loading…
Reference in New Issue