diff --git a/src/backend/git.rs b/src/backend/git.rs index f7868a4..dd52102 100644 --- a/src/backend/git.rs +++ b/src/backend/git.rs @@ -31,7 +31,7 @@ use serde::Serialize; use tera::Context; use time_format::format_iso8601_utc; -#[derive(Serialize)] +#[derive(Default, Serialize)] struct Entry { class: String, last_commit: String, @@ -46,34 +46,28 @@ fn get_entries(tree: Tree) -> Result, Box> { for e in tree.iter() { let entry = e.unwrap(); - 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(); + let mut entry_t = Entry::default(); + entry_t.path = entry.filename().to_string(); - let class = match entry.kind() { + entry_t.class = match entry.kind() { EntryKind::Tree | EntryKind::Commit => "directory", _ => "file", }.to_owned(); for i in tree.repo.head_commit()?.ancestors().sorting(order).all()? { 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() { - last_commit = commit.short_id()?.to_string(); - last_commit_message = commit.message_raw()?.to_string(); - last_commit_time = format_iso8601_utc(commit.time()?.seconds)?; + entry_t.last_commit = commit.short_id()?.to_string(); + entry_t.last_commit_message = commit.message_raw()?.to_string(); + entry_t.last_commit_time = format_iso8601_utc( + commit.time()?.seconds + )?; } } - entries.push(Entry { - class, - last_commit, - last_commit_message, - last_commit_time, - path, - }); + entries.push(entry_t); } Ok(entries) @@ -93,9 +87,9 @@ pub fn repo_to_context(r: Repository) -> Result> { let entries = get_entries(tree)?; + /* let mut readme_content = String::new(); - /* /* TODO: determine what file to use as README better */ let readme_candidates = entries.iter().filter(|e| { match e.path.as_str().to_uppercase().as_str() {