Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add format argument to git revdate ffi #179

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
})
});