diff --git a/src/repo.rs b/src/repo.rs index 6ddba76..0debecd 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -1,14 +1,17 @@ //! Utility functions for accessing a [`Repository`]. -use gix::{ObjectId, Repository}; +use gix::{actor::IdentityRef, Commit}; use crate::somehow; -pub fn short_commit(repo: &Repository, hash: &str) -> somehow::Result { - let hash = hash.parse::()?; - let commit = repo.find_object(hash)?.try_into_commit()?; +pub fn format_actor(author: IdentityRef<'_>) -> somehow::Result { + let mut buffer = vec![]; + author.write_to(&mut buffer)?; + Ok(String::from_utf8_lossy(&buffer).to_string()) +} - let id = commit.short_id()?; +pub fn format_commit_short(commit: &Commit<'_>) -> somehow::Result { + let id = commit.id().shorten_or_id(); let summary = commit.message()?.summary(); Ok(format!("{id} ({summary})")) } diff --git a/src/web/index.rs b/src/web/index.rs index a80a825..0558016 100644 --- a/src/web/index.rs +++ b/src/web/index.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use askama::Template; use axum::{extract::State, response::IntoResponse}; -use gix::ThreadSafeRepository; +use gix::{prelude::ObjectIdExt, ObjectId, ThreadSafeRepository}; use sqlx::SqlitePool; use crate::{config::Config, repo, somehow}; @@ -35,10 +35,14 @@ pub async fn get( let mut refs = vec![]; for row in rows { - let name = row.name; - let hash = row.hash; - let short = repo::short_commit(&repo, &hash)?; - refs.push(Ref { name, hash, short }); + let id = row.hash.parse::()?.attach(&repo); + let commit = id.object()?.try_into_commit()?; + + refs.push(Ref { + name: row.name, + hash: row.hash, + short: repo::format_commit_short(&commit)?, + }); } Ok(IndexTemplate {