From a562c4616c274b929ecff0d35b89f2aee0ab5186 Mon Sep 17 00:00:00 2001 From: Hubert Date: Mon, 19 Jul 2021 06:52:15 +0200 Subject: [PATCH] browse ok --- src/error.rs | 1 + src/gitrepo.rs | 16 +++++++++++++--- src/main.rs | 10 ++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/error.rs b/src/error.rs index 82dc2c5..4546c64 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,6 +5,7 @@ pub struct Error(String); impl From for Error { fn from(giterr: git2::Error) -> Self { + // panic!() Error(format!("{}", giterr)) } } diff --git a/src/gitrepo.rs b/src/gitrepo.rs index dbd1971..2db541c 100644 --- a/src/gitrepo.rs +++ b/src/gitrepo.rs @@ -22,7 +22,9 @@ impl GitRepo { pub fn get_tree<'a, 'b, 'c> (&'a self, commit : &'b GitRef, path : &'c Path) -> Result, git2::Error> { let commit = match commit { GitRef::Commit(commit) => { + // println!("commit : {}", commit.as_str()); let oid = Oid::from_str(commit.as_str())?; + // println!("{}", oid); self.git2.find_commit(oid)? } GitRef::Branch(branch) => { @@ -30,14 +32,22 @@ impl GitRepo { branch.get().peel_to_commit()? } GitRef::Head => { + // println!("coucou1"); let head = self.git2.head()?; + // println!("coucou"); head.peel_to_commit()? } }; - let tree = commit.tree()?; - let subtree = self.git2.find_tree(tree.get_path(path)?.id())?; + let root_tree = commit.tree()?; + let tree = if path.as_os_str().len() == 0 { + root_tree + } else { + let oid1 = root_tree.get_path(path)?.id(); + // println!("{}", oid1); + self.git2.find_tree(oid1)? + }; let fullname = path.to_path_buf(); - Ok(GitDir { fullname, tree : subtree }) + Ok(GitDir { fullname, tree }) } pub async fn browse<'a>(&'a self, dir: &GitDir<'a>) -> Result>, git2::Error> { diff --git a/src/main.rs b/src/main.rs index c16a093..580cca0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -153,8 +153,14 @@ async fn git_main( gitust : web::Data ) -> Result, Vec<(String, String)>>, error::Error> { let rootname = match pathopt { - None => {"/".to_string()} - Some(s) => {s} + None => {"".to_string()} + Some(s) => { + if s.starts_with("/") { + (&s[1..]).to_string() + } else { + s + } + } }; let commit = match commitnameopt { None => {match branchopt {