git.rs: uses default trait for entries

This commit is contained in:
2026-04-24 03:10:14 +00:00
parent 1f8eed80c7
commit ac86e4a13b

View File

@@ -31,7 +31,7 @@ use serde::Serialize;
use tera::Context; use tera::Context;
use time_format::format_iso8601_utc; use time_format::format_iso8601_utc;
#[derive(Serialize)] #[derive(Default, Serialize)]
struct Entry { struct Entry {
class: String, class: String,
last_commit: String, last_commit: String,
@@ -46,34 +46,28 @@ fn get_entries(tree: Tree) -> Result<Vec<Entry>, Box<dyn Error>> {
for e in tree.iter() { for e in tree.iter() {
let entry = e.unwrap(); let entry = e.unwrap();
let path = entry.filename().to_string(); let mut entry_t = Entry::default();
let mut last_commit = String::new(); entry_t.path = entry.filename().to_string();
let mut last_commit_message = String::new();
let mut last_commit_time = String::new();
let class = match entry.kind() { entry_t.class = match entry.kind() {
EntryKind::Tree | EntryKind::Commit => "directory", EntryKind::Tree | EntryKind::Commit => "directory",
_ => "file", _ => "file",
}.to_owned(); }.to_owned();
for i in tree.repo.head_commit()?.ancestors().sorting(order).all()? { for i in tree.repo.head_commit()?.ancestors().sorting(order).all()? {
let commit = i?.id().object()?.peel_to_commit()?; let commit = i?.id().object()?.peel_to_commit()?;
let path_slice: &[u8] = path.as_ref(); let path_slice: &[u8] = entry_t.path.as_ref();
if commit.tree()?.lookup_entry([path_slice])?.is_some() { if commit.tree()?.lookup_entry([path_slice])?.is_some() {
last_commit = commit.short_id()?.to_string(); entry_t.last_commit = commit.short_id()?.to_string();
last_commit_message = commit.message_raw()?.to_string(); entry_t.last_commit_message = commit.message_raw()?.to_string();
last_commit_time = format_iso8601_utc(commit.time()?.seconds)?; entry_t.last_commit_time = format_iso8601_utc(
commit.time()?.seconds
)?;
} }
} }
entries.push(Entry { entries.push(entry_t);
class,
last_commit,
last_commit_message,
last_commit_time,
path,
});
} }
Ok(entries) Ok(entries)
@@ -93,9 +87,9 @@ pub fn repo_to_context(r: Repository) -> Result<Context, Box<dyn Error>> {
let entries = get_entries(tree)?; let entries = get_entries(tree)?;
/*
let mut readme_content = String::new(); let mut readme_content = String::new();
/*
/* TODO: determine what file to use as README better */ /* TODO: determine what file to use as README better */
let readme_candidates = entries.iter().filter(|e| { let readme_candidates = entries.iter().filter(|e| {
match e.path.as_str().to_uppercase().as_str() { match e.path.as_str().to_uppercase().as_str() {