Format author and committer time like git
This commit is contained in:
parent
128384bcf7
commit
b83d908d4b
4 changed files with 12 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2766,6 +2766,7 @@ dependencies = [
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"serde",
|
"serde",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
"time",
|
||||||
"tokio",
|
"tokio",
|
||||||
"toml",
|
"toml",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ mime_guess = "2.0.4"
|
||||||
rust-embed = "6.8.1"
|
rust-embed = "6.8.1"
|
||||||
serde = { version = "1.0.181", features = ["derive"] }
|
serde = { version = "1.0.181", features = ["derive"] }
|
||||||
sqlx = { version = "0.7.1", features = ["runtime-tokio", "sqlite"] }
|
sqlx = { version = "0.7.1", features = ["runtime-tokio", "sqlite"] }
|
||||||
|
time = { version = "0.3.25", features = ["formatting", "macros"] }
|
||||||
tokio = { version = "1.29.1", features = ["full"] }
|
tokio = { version = "1.29.1", features = ["full"] }
|
||||||
toml = "0.7.6"
|
toml = "0.7.6"
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
//! Utility functions for accessing a [`Repository`].
|
//! Utility functions for accessing a [`Repository`].
|
||||||
|
|
||||||
use gix::{actor::IdentityRef, Commit};
|
use gix::{actor::IdentityRef, date::Time, Commit};
|
||||||
|
use time::macros::format_description;
|
||||||
|
|
||||||
use crate::somehow;
|
use crate::somehow;
|
||||||
|
|
||||||
|
|
@ -10,6 +11,12 @@ pub fn format_actor(author: IdentityRef<'_>) -> somehow::Result<String> {
|
||||||
Ok(String::from_utf8_lossy(&buffer).to_string())
|
Ok(String::from_utf8_lossy(&buffer).to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn format_time(time: Time) -> String {
|
||||||
|
time.format(format_description!(
|
||||||
|
"[year]-[month]-[day] [hour]:[minute]:[second] [offset_hour sign:mandatory][offset_minute]"
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn format_commit_short(commit: &Commit<'_>) -> somehow::Result<String> {
|
pub fn format_commit_short(commit: &Commit<'_>) -> somehow::Result<String> {
|
||||||
let id = commit.id().shorten_or_id();
|
let id = commit.id().shorten_or_id();
|
||||||
let summary = commit.message()?.summary();
|
let summary = commit.message()?.summary();
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,9 @@ pub async fn get(
|
||||||
summary: commit.message()?.summary().to_string(),
|
summary: commit.message()?.summary().to_string(),
|
||||||
message: commit.message_raw_sloppy().to_string(),
|
message: commit.message_raw_sloppy().to_string(),
|
||||||
author: repo::format_actor(author_info.actor())?,
|
author: repo::format_actor(author_info.actor())?,
|
||||||
author_date: author_info.time.to_bstring().to_string(),
|
author_date: repo::format_time(author_info.time),
|
||||||
commit: repo::format_actor(committer_info.actor())?,
|
commit: repo::format_actor(committer_info.actor())?,
|
||||||
commit_date: committer_info.time.to_bstring().to_string(),
|
commit_date: repo::format_time(committer_info.time),
|
||||||
parents,
|
parents,
|
||||||
children,
|
children,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue