Skip to content

Commit

Permalink
Not cache git repository when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimach committed Apr 2, 2024
1 parent bbac153 commit 1b7992e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 12 additions & 19 deletions src/git.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
use chrono::{TimeZone, Utc};
use gix::{open::Error as OpenError, Repository};

thread_local! {
static REPOSITORY: Result<Repository, OpenError> = gix::open(".");
}

byond_fn!(fn rg_git_revparse(rev) {
REPOSITORY.with(|repo| -> Option<String> {
let repo = repo.as_ref().ok()?;
let object = repo.rev_parse_single(rev).ok()?;
Some(object.to_string())
})
let repo = gix::open(".");
let repo = repo.as_ref().ok()?;
let object = repo.rev_parse_single(rev).ok()?;
Some(object.to_string())
});

byond_fn!(fn rg_git_commit_date(rev) {
REPOSITORY.with(|repo| -> Option<String> {
let repo = repo.as_ref().ok()?;
let rev = repo.rev_parse_single(rev).ok()?;
let object = rev.object().ok()?;
let commit = object.try_into_commit().ok()?;
let commit_time = commit.committer().ok()?.time;
let datetime = Utc.timestamp_opt(commit_time.seconds, 0).latest()?;
Some(datetime.format("%F").to_string())
})
let repo = gix::open(".");
let repo = repo.as_ref().ok()?;
let rev = repo.rev_parse_single(rev).ok()?;
let object = rev.object().ok()?;
let commit = object.try_into_commit().ok()?;
let commit_time = commit.committer().ok()?.time;
let datetime = Utc.timestamp_opt(commit_time.seconds, 0).latest()?;
Some(datetime.format("%F").to_string())
});

0 comments on commit 1b7992e

Please sign in to comment.