mygit

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

commit bbd8d86252c3a267ea243204aae8c2a415a9e525
parent 6d6f2c57b8634e693fd9da2a45a6b7eee20bd10c
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Tue, 16 Mar 2021 22:43:42 -0700

Display branch name on log page

Diffstat:
MCargo.lock | 229+------------------------------------------------------------------------------
Msrc/main.rs | 22++++++++++++----------
Mtemplates/log.html | 1+
3 files changed, 14 insertions(+), 238 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -55,15 +55,6 @@ dependencies = [ ] [[package]] -name = "aho-corasick" -version = "0.7.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" -dependencies = [ - "memchr", -] - -[[package]] name = "anyhow" version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -117,7 +108,7 @@ checksum = "2582b77e0f3c506ec4838a25fa8a5f97b9bed72bb6d3d272ea1c031d8bd373bc" dependencies = [ "askama_escape", "humansize", - "nom 6.1.2", + "nom", "num-traits", "percent-encoding", "proc-macro2", @@ -448,12 +439,6 @@ dependencies = [ ] [[package]] -name = "bufstream" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8" - -[[package]] name = "bumpalo" version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -564,22 +549,6 @@ dependencies = [ ] [[package]] -name = "core-foundation" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" - -[[package]] name = "cpuid-bool" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -695,12 +664,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" [[package]] -name = "email-parser" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd45adbcbe4247e0a92f13ae66d10b11a6fc05f6184a8f573755afab21f18799" - -[[package]] name = "event-listener" version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -738,21 +701,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] name = "form_urlencoded" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1019,31 +967,6 @@ dependencies = [ ] [[package]] -name = "imap" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c617c55def8c42129e0dd503f11d7ee39d73f5c7e01eff55768b3879ff1d107d" -dependencies = [ - "base64 0.13.0", - "bufstream", - "chrono", - "imap-proto", - "lazy_static", - "native-tls", - "nom 5.1.2", - "regex", -] - -[[package]] -name = "imap-proto" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a6def1d5ac8975d70b3fd101d57953fe3278ef2ee5d7816cba54b1d1dfc22f" -dependencies = [ - "nom 5.1.2", -] - -[[package]] name = "indexmap" version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1203,7 +1126,6 @@ dependencies = [ "async-std", "chrono", "git2", - "mygit-inbox", "once_cell", "percent-encoding", "pico-args", @@ -1215,35 +1137,6 @@ dependencies = [ ] [[package]] -name = "mygit-inbox" -version = "0.1.0" -dependencies = [ - "askama", - "askama_tide", - "email-parser", - "imap", - "tide", -] - -[[package]] -name = "native-tls" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - -[[package]] name = "nb-connect" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1255,17 +1148,6 @@ dependencies = [ [[package]] name = "nom" -version = "5.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" -dependencies = [ - "lexical-core", - "memchr", - "version_check", -] - -[[package]] -name = "nom" version = "6.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2" @@ -1341,39 +1223,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] -name = "openssl" -version = "0.10.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577" -dependencies = [ - "bitflags", - "cfg-if 1.0.0", - "foreign-types", - "libc", - "once_cell", - "openssl-sys", -] - -[[package]] -name = "openssl-probe" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" - -[[package]] -name = "openssl-sys" -version = "0.9.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "313752393519e876837e09e1fa183ddef0be7735868dced3196f4472d536277f" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - -[[package]] name = "parking" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1609,41 +1458,12 @@ dependencies = [ ] [[package]] -name = "redox_syscall" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" -dependencies = [ - "bitflags", -] - -[[package]] -name = "regex" -version = "1.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] name = "regex-syntax" version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - -[[package]] name = "route-recognizer" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1680,39 +1500,6 @@ dependencies = [ ] [[package]] -name = "schannel" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" -dependencies = [ - "lazy_static", - "winapi", -] - -[[package]] -name = "security-framework" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d493c5f39e02dfb062cd8f33301f90f9b13b650e8c1b1d0fd75c19dd64bff69d" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee48cdde5ed250b0d3252818f646e174ab414036edb884dde62d80a3ac6082d" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] name = "semver" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1965,20 +1752,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] -name = "tempfile" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "rand 0.8.3", - "redox_syscall", - "remove_dir_all", - "winapi", -] - -[[package]] name = "thiserror" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/src/main.rs b/src/main.rs @@ -190,6 +190,7 @@ async fn repo_home(req: Request<()>) -> tide::Result { struct RepoLogTemplate<'a> { repo: &'a Repository, commits: Vec<Commit<'a>>, + branch: &'a str, } async fn repo_log(req: Request<()>) -> tide::Result { @@ -200,30 +201,31 @@ async fn repo_log(req: Request<()>) -> tide::Result { url.path_segments_mut().unwrap().pop(); return Ok(tide::Redirect::temporary(url.to_string()).into()); } - let commits = if repo.is_shallow() { tide::log::warn!("repository {:?} is only a shallow clone", repo.path()); vec![repo.head()?.peel_to_commit().unwrap()] } else { let mut revwalk = repo.revwalk()?; match req.param("ref") { - Ok(r) => revwalk.push_ref(&format!("refs/heads/{}", r))?, - _ => revwalk.push_head()?, + Ok(r) => { + revwalk.push_ref(&format!("refs/heads/{}", r))?; + } + _ => { + revwalk.push_head()?; + } }; - - // show newest commits first - revwalk - .set_sorting(git2::Sort::TIME) - .unwrap(); - + revwalk.set_sorting(git2::Sort::TIME).unwrap(); revwalk .filter_map(|oid| repo.find_commit(oid.unwrap()).ok().clone()) // TODO error handling - .take(100) // Only get first 100 commits + .take(100) .collect() }; + let head_branch = repo.head()?; + let branch = req.param("ref").unwrap_or(head_branch.shorthand().unwrap()); let tmpl = RepoLogTemplate { repo: &repo, commits, + branch: branch, }; Ok(tmpl.into()) } diff --git a/templates/log.html b/templates/log.html @@ -2,6 +2,7 @@ {% block content %} {% include "repo-navbar.html" %} + <h2>{{branch}}</h2> <table> {% for commit in commits %} <tr>