works a bit

This commit is contained in:
2021-07-18 14:34:06 +02:00
parent 2278b46a88
commit 82757ef9eb
3 changed files with 44 additions and 46 deletions

View File

@@ -27,7 +27,7 @@ use serde::Deserialize;
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
use tokio::process::{Child, ChildStdout, Command};
use gitcommit::GitCommit;
use gitcommit::GitRef;
use gitdir::GitDir;
use gitrepo::GitRepo;
@@ -124,6 +124,7 @@ async fn hello_auth(req : HttpRequest) -> impl Responder {
struct GitWebQ {
commit: Option<String>,
path: Option<String>,
branch: Option<String>,
}
@@ -148,52 +149,30 @@ async fn chunk() -> HttpResponse {
#[get("/git/{owner}/{repo}.git")]
async fn git_main(
web::Path((ownername, reponame)): web::Path<(String, String)>,
web::Query(GitWebQ{commit : commitnameopt, path : pathopt}) : web::Query<GitWebQ>,
web::Query(GitWebQ{commit : commitnameopt, path : pathopt, branch : branchopt}) : web::Query<GitWebQ>,
gitust : web::Data<Gitust>
) -> Result<GitMainTemplate<Vec<Entry>, Vec<(String, String)>>, error::Error> {
let commitname = match commitnameopt {
None => {"master".to_string()}
Some(s) => {s}
};
let rootname = match pathopt {
None => {"/".to_string()}
Some(s) => {s}
};
let commit = GitCommit::new(commitname);
let commit = match commitnameopt {
None => {match branchopt {
None => {GitRef::Branch("master".to_string())}
Some(s) => {GitRef::Branch(s)}
}}
Some(s) => {GitRef::Commit(s)}
};
let owner = Owner { name : ownername};
let repo = Repository {name : reponame, owner};
let user = User { name : "Hubert".to_string()};
let path = rootname.split("/").map_accum("/git/".to_string() + &repo.owner.name + "/" + &repo.name + "/" + commit.value(), |str_ref, b| {
// il faut ajouter le commit/branch dans la query
let path = rootname.split("/").map_accum("/git/".to_string() + &repo.owner.name + "/" + &repo.name, |str_ref, b| {
let href = b + "/" + str_ref;
((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 repogit = match git2::Repository::open(format!("{}/{}/{}.git", &gitust.repo_root_path, &repo.owner.name, &repo.name)) {
// Ok(repo) => repo,
// Err(e) => panic!("failed to open: {}", e),
// };
// let head = match repogit.head() {
// Ok(head) => head,
// Err(e) => panic!("failed to get head: {}", e)
// };
// let commitgit = match head.peel_to_commit() {
// Ok(commit) => commit,
// Err(e) => panic!("failed to get commit: {}", e)
// };
// let tree = match commitgit.tree() {
// Ok(tree) => tree,
// Err(e) => panic!("failed to get tree: {}", e)
// };
// for entry in tree.iter() {
// println!("{:?}", entry.name());
// println!("{:?}", entry.kind());
// if entry.kind() == Some(ObjectType::Tree) {
// let subtree = repogit.find_tree(entry.id()).expect("this pust be a tree");
// println!("{:?}", subtree);
// }
// }
let root = gitrepo.get_root_tree(&commit)?;
// let root = GitBrowseDir::new(rootname);
let browse = gitrepo.browse(&root).await?;
let mut entries : Vec<Entry> = Vec::new();
for entry in browse {