From a2dcab2ea8a80ebc44e028fa88dab6e6b1dd2e40 Mon Sep 17 00:00:00 2001 From: Hubert Date: Sun, 18 Jul 2021 06:06:49 +0200 Subject: [PATCH] refacto --- src/git.rs | 22 +++++++++++----------- src/main.rs | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/git.rs b/src/git.rs index d65684a..b3d88c8 100644 --- a/src/git.rs +++ b/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, git2::Error> { + pub fn get_root_tree<'a, 'b> (&'a self, commit : &'b GitCommit) -> Result, 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>, git2::Error> { + pub async fn browse<'a>(&'a self, dir: &GitDir<'a>) -> Result>, 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<'_> { diff --git a/src/main.rs b/src/main.rs index 0432daf..d9e4b9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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;