use libvctrl_handler::{Commit, Hash, UserID};
#[derive(Debug, Default)]
pub struct CommitBuilder {
tree: Option<Hash>,
parents: Vec<Hash>,
author: Option<UserID>,
committer: Option<UserID>,
message: Option<String>,
}
impl CommitBuilder {
#[must_use]
pub const fn new() -> Self {
Self {
tree: None,
parents: Vec::new(),
author: None,
committer: None,
message: None,
}
}
#[must_use]
pub const fn tree(mut self, tree: Hash) -> Self {
self.tree = Some(tree);
self
}
#[must_use]
pub fn parent(mut self, parent: Hash) -> Self {
self.parents.push(parent);
self
}
#[must_use]
pub fn author(mut self, author: UserID) -> Self {
self.author = Some(author);
self
}
#[must_use]
pub fn committer(mut self, committer: UserID) -> Self {
self.committer = Some(committer);
self
}
#[must_use]
pub fn message(mut self, msg: impl Into<String>) -> Self {
self.message = Some(msg.into());
self
}
#[must_use]
pub fn build(self) -> Commit {
Commit::new(
self.tree.expect("tree not set"),
self.parents,
self.author.expect("author not set"),
self.committer.expect("committer not set"),
self.message.expect("message not set"),
)
}
}