Skip to content

Commit

Permalink
Add format argument to git revdate ffi (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZephyrTFA committed Jul 12, 2024
1 parent 22a6df5 commit ec2e497
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions dmsrc/git.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#define rustg_git_revparse(rev) RUSTG_CALL(RUST_G, "rg_git_revparse")(rev)

/**
* Returns the date of the given revision in the format YYYY-MM-DD.
* Returns null if the revision is invalid.
* Returns the date of the given revision using the provided format.
* Defaults to returning %F which is YYYY-MM-DD.
*/
#define rustg_git_commit_date(rev) RUSTG_CALL(RUST_G, "rg_git_commit_date")(rev)
/proc/rustg_git_commit_date(rev, format = "%F")
return RUSTG_CALL(RUST_G, "rg_git_commit_date")(rev, format)
4 changes: 2 additions & 2 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ byond_fn!(fn rg_git_revparse(rev) {
})
});

byond_fn!(fn rg_git_commit_date(rev) {
byond_fn!(fn rg_git_commit_date(rev, format) {
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())
Some(datetime.format(format).to_string())
})
});

0 comments on commit ec2e497

Please sign in to comment.