Skip to content

Commit

Permalink
adjust git_date::parsea(str) to use a str
Browse files Browse the repository at this point in the history
It will never not be UTF-8, so no bstr is required.
  • Loading branch information
Byron committed Aug 13, 2022
1 parent 11a5fa2 commit 0f8680a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 1 addition & 2 deletions git-date/src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::Time;
use bstr::BStr;

#[allow(missing_docs)]
pub fn parse(input: &BStr) -> Option<Time> {
pub fn parse(input: &str) -> Option<Time> {
// TODO: actual implementation, this is just to not constantly fail
if input == "1979-02-26 18:30:00" {
Some(Time::new(42, 1800))
Expand Down
2 changes: 1 addition & 1 deletion git-date/tests/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod parse {
#[test]
fn special_time_is_ok_for_now() {
assert_eq!(
git_date::parse("1979-02-26 18:30:00".into()).unwrap(),
git_date::parse("1979-02-26 18:30:00").unwrap(),
Time {
seconds_since_unix_epoch: 42,
offset_in_seconds: 1800,
Expand Down
8 changes: 6 additions & 2 deletions git-repository/src/repository/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,15 @@ impl Personas {
if git_env.eq(&git_sec::Permission::Allow) {
committer_name = committer_name.or_else(|| env_var("GIT_COMMITTER_NAME"));
committer_email = committer_email.or_else(|| env_var("GIT_COMMITTER_EMAIL"));
committer_date = env_var("GIT_COMMITTER_DATE").and_then(|date| git_date::parse(date.as_ref()));
committer_date = std::env::var("GIT_COMMITTER_DATE")
.ok()
.and_then(|date| git_date::parse(&date));

author_name = author_name.or_else(|| env_var("GIT_AUTHOR_NAME"));
author_email = author_email.or_else(|| env_var("GIT_AUTHOR_EMAIL"));
author_date = env_var("GIT_AUTHOR_DATE").and_then(|date| git_date::parse(date.as_ref()));
author_date = std::env::var("GIT_AUTHOR_DATE")
.ok()
.and_then(|date| git_date::parse(&date));

user_email = user_email.or_else(|| env_var("EMAIL")); // NOTE: we don't have permission for this specific one…
}
Expand Down
6 changes: 5 additions & 1 deletion git-revision/src/spec/parse/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,11 @@ where
Err(Error::SiblingBranchNeedsBranchName { name: (*name).into() })
}?
} else if has_ref_or_implied_name {
let time = git_date::parse(nav).ok_or_else(|| Error::Time { input: nav.into() })?;
let time = nav
.to_str()
.ok()
.and_then(git_date::parse)
.ok_or_else(|| Error::Time { input: nav.into() })?;
delegate
.reflog(delegate::ReflogLookup::Date(time))
.ok_or(Error::Delegate)?;
Expand Down

0 comments on commit 0f8680a

Please sign in to comment.