mygit

[UNMAINTAINED] A cgit/webgit alternative, written in Rust
Log | Files | Refs | README | LICENSE

commit 2c572150c9fa083d336cb209566262c6d4bf101e
parent d81a4c63997dfaefea0b46290b9def6778609f93
Author: Johann150 <johann@qwertqwefsday.eu>
Date:   Thu, 15 Jul 2021 19:15:56 +0200

add gitweb URL compatibility

Diffstat:
Msrc/main.rs | 28+++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs @@ -116,7 +116,33 @@ struct IndexTemplate { repos: Vec<Repository>, } -async fn index(_req: Request<()>) -> tide::Result { +async fn index(req: Request<()>) -> tide::Result { + // check for gitweb parameters to redirect + if let Some(query) = req.url().query() { + // gitweb does not use standard & separated query parameters + let query = query + .split(";") + .map(|s| { + println!("{}", s); + let mut parts = s.splitn(2, "="); + (parts.next().unwrap(), parts.next().unwrap()) + }) + .collect::<std::collections::HashMap<_, _>>(); + if let Some(repo) = query.get("p") { + return Ok(tide::Redirect::permanent(match query.get("a") { + None | Some(&"summary") => format!("/{}/", repo), + Some(&"commit") | Some(&"commitdiff") => { + format!("/{}/commit/{}", repo, query.get("h").cloned().unwrap_or("")) + } + Some(&"shortlog") | Some(&"log") => { + format!("/{}/log/{}", repo, query.get("h").cloned().unwrap_or("")) + } + Some(_) => format!("/"), + }) + .into()); + } + } + let repos = fs::read_dir(&CONFIG.projectroot) .map(|entries| { entries