Skip to content

Commit

Permalink
use lines not split (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZephyrTFA authored Jul 14, 2024
1 parent 89146ff commit c0eb135
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ byond_fn!(fn rg_git_commit_date(rev, format) {
});

byond_fn!(fn rg_git_commit_date_head(format) {
let head_log_path = Path::new(".git")
.join("logs")
.join("HEAD");
let head_log_path = Path::new(".git").join("logs").join("HEAD");
let head_log = fs::metadata(&head_log_path).ok()?;
if !head_log.is_file() {
return None;
}
let log_entries = fs::read_to_string(&head_log_path).ok()?;
let log_entries = log_entries.split('\n');
let last_entry = log_entries.last()?.split_ascii_whitespace().collect::<Vec<_>>();
if last_entry.len() < 5 { // 5 is the timestamp
let log_entries = log_entries.lines();
let last_entry = log_entries
.last()?
.split_ascii_whitespace()
.collect::<Vec<_>>();
if last_entry.len() < 5 {
// 5 is the timestamp
return None;
}
let datetime = Utc.timestamp_opt(last_entry[4].parse().ok()?, 0).latest()?;
Expand Down

0 comments on commit c0eb135

Please sign in to comment.