added commit information to repository page
This commit is contained in:
@@ -1,8 +1,16 @@
|
||||
use std::error::Error;
|
||||
|
||||
use gix::{ Repository, object::tree::EntryKind };
|
||||
use gix::{
|
||||
ObjectId,
|
||||
Repository,
|
||||
diff::object::bstr::BStr,
|
||||
object::tree::EntryKind,
|
||||
revision::walk::Sorting,
|
||||
};
|
||||
use gix_traverse::commit::simple::CommitTimeOrder;
|
||||
use serde::Serialize;
|
||||
use tera::Context;
|
||||
use time_format::format_iso8601_utc;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct Entry {
|
||||
@@ -29,22 +37,39 @@ pub fn repo_to_context(r: Repository) -> Result<Context, Box<dyn Error>> {
|
||||
for e in tree.iter() {
|
||||
let entry = e.unwrap();
|
||||
|
||||
let last_commit = "TODO".to_string();
|
||||
let last_commit_message = "TODO".to_string();
|
||||
let last_commit_time = "1970-01-01T00:00:00".to_string();
|
||||
|
||||
let class = match entry.kind() {
|
||||
EntryKind::Tree => "directory",
|
||||
EntryKind::Blob => "file",
|
||||
_ => "",
|
||||
}.to_owned();
|
||||
|
||||
let path = entry.filename().to_string();
|
||||
let mut last_commit = String::new();
|
||||
let mut last_commit_message = String::new();
|
||||
let mut last_commit_time = String::new();
|
||||
|
||||
for i in r
|
||||
.head_commit()?
|
||||
.ancestors()
|
||||
.sorting(Sorting::ByCommitTime(CommitTimeOrder::NewestFirst))
|
||||
.all()? {
|
||||
let commit = i?.id().object()?.peel_to_commit()?;
|
||||
|
||||
let path_slice: &[u8] = path.as_ref();
|
||||
|
||||
if commit.tree()?.lookup_entry([path_slice])?.is_some() {
|
||||
last_commit = commit.short_id()?.to_string();
|
||||
last_commit_message = commit.message_raw()?.to_string();
|
||||
last_commit_time = format_iso8601_utc(commit.time()?.seconds)?;
|
||||
}
|
||||
}
|
||||
|
||||
entries.push(Entry {
|
||||
class,
|
||||
last_commit,
|
||||
last_commit_message,
|
||||
last_commit_time,
|
||||
path: entry.filename().to_string(),
|
||||
path,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user