This commit is contained in:
Hubert
2021-07-19 06:16:17 +02:00
parent 35537c6688
commit 06fcc46a15
4 changed files with 241 additions and 6 deletions

View File

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

View File

@@ -19,7 +19,7 @@ impl GitRepo {
Repository::open(path).map(|git2| GitRepo{git2})
}
pub fn get_root_tree<'a, 'b> (&'a self, commit : &'b GitRef, path : &Path) -> Result<GitDir<'a>, git2::Error> {
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) => {
let oid = Oid::from_str(commit.as_str())?;
@@ -35,9 +35,9 @@ impl GitRepo {
}
};
let tree = commit.tree()?;
tree.get_path(path)?.
let fullname = PathBuf::from("/");
Ok(GitDir { fullname, tree })
let subtree = self.git2.find_tree(tree.get_path(path)?.id())?;
let fullname = path.to_path_buf();
Ok(GitDir { fullname, tree : subtree })
}
pub async fn browse<'a>(&'a self, dir: &GitDir<'a>) -> Result<Vec<GitBrowseEntry<'a>>, git2::Error> {

View File

@@ -172,7 +172,7 @@ async fn git_main(
((str_ref.to_string(), href.clone()), href)
}).collect();
let gitrepo = GitRepo::new(format!("{}/{}/{}.git", &gitust.repo_root_path, &repo.owner.name, &repo.name).as_str())?;
let root = gitrepo.get_root_tree(&commit)?;
let root = gitrepo.get_tree(&commit, Path::new(rootname.as_str()))?;
let browse = gitrepo.browse(&root).await?;
let mut entries : Vec<Entry> = Vec::new();
for entry in browse {