🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2023-07-09 19:05:07.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-07-09 19:05:07.0 +01:00:00
commit
46247bef2718af689111705eccc7973692c9d396 [patch]
tree
630af5bf151a27741146d7d85a78551ad94b4787
parent
fbb0afac681917667f6f34b74451fbd3aefac1f1
download
46247bef2718af689111705eccc7973692c9d396.tar.gz

Show last committed time for last modified on index



Diff

 src/database/indexer.rs | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/database/indexer.rs b/src/database/indexer.rs
index a7254d1..5636c0b 100644
--- a/src/database/indexer.rs
+++ a/src/database/indexer.rs
@@ -44,15 +44,38 @@
        let description = std::fs::read(repository.join("description")).unwrap_or_default();
        let description = Some(String::from_utf8_lossy(&description)).filter(|v| !v.is_empty());

        let git_repository = git2::Repository::open(scan_path.join(&relative)).unwrap();

        Repository {
            id,
            name,
            description,
            owner: None, // TODO read this from config
            last_modified: OffsetDateTime::now_utc(),
            last_modified: find_last_committed_time(&git_repository)
                .unwrap_or(OffsetDateTime::UNIX_EPOCH),
        }
        .insert(db, relative);
    }
}

fn find_last_committed_time(repo: &git2::Repository) -> Result<OffsetDateTime, git2::Error> {
    let mut timestamp = OffsetDateTime::UNIX_EPOCH;

    for reference in repo.references()? {
        let Ok(commit) = reference?.peel_to_commit() else {
            continue;
        };

        let committed_time = commit.committer().when().seconds();
        let committed_time = OffsetDateTime::from_unix_timestamp(committed_time)
            .unwrap_or(OffsetDateTime::UNIX_EPOCH);

        if committed_time > timestamp {
            timestamp = committed_time;
        }
    }

    Ok(timestamp)
}

fn update_repository_reflog(scan_path: &Path, db: &sled::Db) {