browse ok

This commit is contained in:
Hubert 2021-07-19 06:52:15 +02:00
parent 06fcc46a15
commit a562c4616c
3 changed files with 22 additions and 5 deletions

View File

@ -5,6 +5,7 @@ pub struct Error(String);
impl From<git2::Error> for Error {
fn from(giterr: git2::Error) -> Self {
// panic!()
Error(format!("{}", giterr))
}
}

View File

@ -22,7 +22,9 @@ impl GitRepo {
pub fn get_tree<'a, 'b, 'c> (&'a self, commit : &'b GitRef, path : &'c Path) -> Result<GitDir<'a>, 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<Vec<GitBrowseEntry<'a>>, git2::Error> {

View File

@ -153,8 +153,14 @@ async fn git_main(
gitust : web::Data<Gitust>
) -> Result<GitMainTemplate<Vec<Entry>, 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 {