mygit

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

commit b4b5659d5550324dc25498bb07cddfb6da54cd9a
parent 296d03b708ece49c3d9a6609b8436ae1b52b0650
Author: Johann150 <johann@qwertqwefsday.eu>
Date:   Wed, 30 Jun 2021 19:19:09 +0200

use provided short_id function instead of truncating

When truncating to 7 characters, an Oid may not be unique enough,
so it is better to use git2::Object::short_id.

Diffstat:
Msrc/filters.rs | 4++++
Mtemplates/commit.html | 2+-
Mtemplates/log.html | 2+-
Mtemplates/repo.html | 2+-
4 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/filters.rs b/src/filters.rs @@ -72,3 +72,7 @@ pub fn signature_email_link(signature: &Signature) -> askama::Result<String> { signature.to_string() }) } + +pub fn short_id(commit: &git2::Commit) -> askama::Result<String> { + Ok(commit.as_object().short_id().unwrap().as_str().unwrap().to_string()) +} diff --git a/templates/commit.html b/templates/commit.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block title %}{{repo|repo_name}} commit {{commit.id()}} - {{crate::CONFIG.site_name}}{% endblock %} +{% block title %}{{repo|repo_name}} commit {{commit|short_id}} - {{crate::CONFIG.site_name}}{% endblock %} {% block content %} {% include "repo-navbar.html" %} diff --git a/templates/log.html b/templates/log.html @@ -11,7 +11,7 @@ <table> {% for commit in commits %} <tr> - <td><a href="/{{repo|repo_name|urlencode_strict}}/commit/{{commit.id()}}" class="commit-hash">{{commit.id().to_string()[..7]}}</a></td> + <td><a href="/{{repo|repo_name|urlencode_strict}}/commit/{{commit.id()}}" class="commit-hash">{{commit|short_id}}</a></td> {% let summary = commit.summary().unwrap_or("")|truncate(72) %} <td class="commit-summary">{{summary}}</td> <td class="commit-author-email">{{commit.author()|signature_email_link|safe}}</td> diff --git a/templates/repo.html b/templates/repo.html @@ -7,7 +7,7 @@ <table> {% for commit in commits %} <tr> - <td><a href="/{{repo|repo_name|urlencode_strict}}/commit/{{commit.id()}}" class="commit-hash">{{commit.id().to_string()[..7]}}</a></td> + <td><a href="/{{repo|repo_name|urlencode_strict}}/commit/{{commit.id()}}" class="commit-hash">{{commit|short_id}}</a></td> {% let summary = commit.summary().unwrap_or("")|truncate(72) %} <td class="commit-summary">{{summary}}</td> <td class="commit-author-email">{{commit.author()|signature_email_link|safe}}</td>