mygit

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

commit a3fa176a73d7e02fe9e66cb598522c7d67e7bae6
parent d245ca4e0552e674439d4933211736e8ecaf7eaa
Author: Johann150 <johann@qwertqwefsday.eu>
Date:   Mon, 28 Jun 2021 22:43:24 +0200

link to tag pages

For tags which are not lightweight, the tags should be shown on their
separate page so users can see the content of the respective tag. They
can then go to the specific commit linked from there.

Diffstat:
Msrc/main.rs | 58++++++++++++++++++++++++++++++++--------------------------
Mtemplates/refs.html | 4++--
Mtemplates/refs.xml | 6+++---
3 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -316,7 +316,7 @@ async fn repo_log(req: Request<()>) -> tide::Result { struct RepoRefTemplate<'a> { repo: &'a Repository, branches: Vec<Reference<'a>>, - tags: Vec<(String, Signature<'static>)>, + tags: Vec<(String, String, Signature<'static>)>, } async fn repo_refs(req: Request<()>) -> tide::Result { @@ -335,30 +335,35 @@ async fn repo_refs(req: Request<()>) -> tide::Result { .collect(); let mut tags = Vec::new(); repo.tag_foreach(|oid, name_bytes| { + // remove prefix "ref/tags/" + let name = String::from_utf8(name_bytes[10..].to_vec()).unwrap(); + let obj = repo.find_object(oid, None).unwrap(); - let signature = match obj.kind().unwrap() { - git2::ObjectType::Tag => obj - .as_tag() - .unwrap() - .tagger() - .unwrap_or_else(|| obj.peel_to_commit().unwrap().committer().to_owned()) - .to_owned(), + tags.push(match obj.kind().unwrap() { + git2::ObjectType::Tag => ( + format!("refs/{}", name), + name, + obj.as_tag() + .unwrap() + .tagger() + .unwrap_or_else(|| obj.peel_to_commit().unwrap().committer().to_owned()) + .to_owned(), + ), git2::ObjectType::Commit => { // lightweight tag - obj.as_commit().unwrap().committer().to_owned() + ( + format!("commit/{}", name), + name, + obj.as_commit().unwrap().committer().to_owned(), + ) } _ => unreachable!("a tag was not a tag or lightweight tag"), - }; - tags.push(( - // remove prefix "ref/tags/" - String::from_utf8(name_bytes[10..].to_vec()).unwrap(), - signature, - )); + }); true }) .unwrap(); // sort so that newest tags are at the top - tags.sort_unstable_by(|(_, a), (_, b)| a.when().cmp(&b.when()).reverse()); + tags.sort_unstable_by(|(_, _, a), (_, _, b)| a.when().cmp(&b.when()).reverse()); let tmpl = RepoRefTemplate { repo: &repo, branches, @@ -820,7 +825,7 @@ async fn repo_log_feed(req: Request<()>) -> tide::Result { #[template(path = "refs.xml")] struct RepoRefFeedTemplate<'a> { repo: &'a Repository, - tags: Vec<(String, Signature<'static>, String)>, + tags: Vec<(String, String, Signature<'static>, String)>, base_url: &'a str, } @@ -836,11 +841,16 @@ async fn repo_refs_feed(req: Request<()>) -> tide::Result { let mut tags = Vec::new(); repo.tag_foreach(|oid, name_bytes| { + // remove prefix "ref/tags/" + let name = String::from_utf8(name_bytes[10..].to_vec()).unwrap(); + let obj = repo.find_object(oid, None).unwrap(); - let (signature, message) = match obj.kind().unwrap() { + tags.push(match obj.kind().unwrap() { git2::ObjectType::Tag => { let tag = obj.as_tag().unwrap(); ( + format!("refs/{}", name), + name, tag.tagger() .unwrap_or_else(|| obj.peel_to_commit().unwrap().committer().to_owned()) .to_owned(), @@ -850,23 +860,19 @@ async fn repo_refs_feed(req: Request<()>) -> tide::Result { git2::ObjectType::Commit => { // lightweight tag, therefore no content ( + format!("commit/{}", name), + name, obj.as_commit().unwrap().committer().to_owned(), String::new(), ) } _ => unreachable!("a tag was not a tag or lightweight tag"), - }; - tags.push(( - // remove prefix "ref/tags/" - String::from_utf8(name_bytes[10..].to_vec()).unwrap(), - signature, - message, - )); + }); true }) .unwrap(); // sort so that newest tags are at the top - tags.sort_unstable_by(|(_, a, _), (_, b, _)| a.when().cmp(&b.when()).reverse()); + tags.sort_unstable_by(|(_, _, a, _), (_, _, b, _)| a.when().cmp(&b.when()).reverse()); let mut url = req.url().clone(); { diff --git a/templates/refs.html b/templates/refs.html @@ -14,10 +14,10 @@ </table> <h2>Tags</h2> <table> - {% for (tag, signature) in tags %} + {% for (link, tag, signature) in tags %} <tr> <td class="git-reference"> - <a href="/{{repo|repo_name|urlencode_strict}}/commit/{{tag}}">{{tag}}</a> + <a href="/{{repo|repo_name|urlencode_strict}}/{{link}}">{{tag}}</a> </td> <td> {{signature|signature_email_link|safe}} diff --git a/templates/refs.xml b/templates/refs.xml @@ -12,11 +12,11 @@ <lastBuildDate>{{repo|last_modified|format_datetime("%a, %e %b %Y %T %z")}}</lastBuildDate> <managingEditor>{{repo|repo_owner}}</managingEditor> <docs>https://www.rssboard.org/rss-specification</docs> - {% for (tag, signature, message) in tags %} + {% for (link, tag, signature, message) in tags %} <item> <title>{{tag}}</title> - <link>{{base_url}}/commit/{{tag}}</link> - <guid isPermaLink="true">{{base_url}}/commit/{{tag}}</guid> + <link>{{base_url}}/{{link}}</link> + <guid isPermaLink="true">{{base_url}}/{{link}}</guid> <description>&lt;pre&gt;{{message}}&lt;/pre&gt;</description> <author>{{signature.email().unwrap_or("")}}</author> <pubDate>{{signature.when()|format_datetime("%a, %e %b %Y %T %z")}}</pubDate>