radicle/sigrefs/git: Refactor `Committer`
Just slightly more code reuse and a constant.
This commit is contained in:
parent
5d583338c8
commit
d25fb7f672
|
|
@ -21,6 +21,8 @@ pub struct Committer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Committer {
|
impl Committer {
|
||||||
|
const NAME: &str = "radicle";
|
||||||
|
|
||||||
/// Construct a [`Committer`] using the timestamp found at
|
/// Construct a [`Committer`] using the timestamp found at
|
||||||
/// [`GIT_COMMITTER_DATE`],
|
/// [`GIT_COMMITTER_DATE`],
|
||||||
///
|
///
|
||||||
|
|
@ -64,19 +66,11 @@ impl Committer {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let time = Time::new(
|
let timestamp = timestamp
|
||||||
timestamp
|
.try_into()
|
||||||
.try_into()
|
.expect("seconds since unix epoch must fit i64");
|
||||||
.expect("seconds since unix epoch must fit i64"),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
let author = Author {
|
|
||||||
name: "radicle".to_string(),
|
|
||||||
email: public_key.to_human(),
|
|
||||||
time,
|
|
||||||
};
|
|
||||||
|
|
||||||
Self::new(author)
|
Self::from_key_and_time(public_key, timestamp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,12 +82,7 @@ impl Committer {
|
||||||
/// variable.
|
/// variable.
|
||||||
#[cfg(any(test, feature = "test"))]
|
#[cfg(any(test, feature = "test"))]
|
||||||
pub fn stable(public_key: &PublicKey) -> Self {
|
pub fn stable(public_key: &PublicKey) -> Self {
|
||||||
let author = Author {
|
Self::from_key_and_time(public_key, 1671125284)
|
||||||
name: "radicle".to_string(),
|
|
||||||
email: public_key.to_human(),
|
|
||||||
time: Time::new(1671125284, 0),
|
|
||||||
};
|
|
||||||
Self::new(author)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a [`Committer`] with the provided [`Author`].
|
/// Construct a [`Committer`] with the provided [`Author`].
|
||||||
|
|
@ -104,6 +93,14 @@ impl Committer {
|
||||||
pub fn into_inner(self) -> Author {
|
pub fn into_inner(self) -> Author {
|
||||||
self.author
|
self.author
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_key_and_time(public_key: &PublicKey, timestamp: i64) -> Self {
|
||||||
|
Self::new(Author {
|
||||||
|
name: Self::NAME.to_string(),
|
||||||
|
email: public_key.to_human(),
|
||||||
|
time: Time::new(timestamp, 0),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod git2_impls {
|
mod git2_impls {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue