From 846be151325eba91efd289ab6ff615d57abb4448 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 31 Jan 2023 17:56:59 +0900 Subject: [PATCH] templater: add CommitOrChangeId constructor to help inline keywords --- src/templater.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/templater.rs b/src/templater.rs index cb3ed369e..663aefc5d 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -486,7 +486,14 @@ pub struct CommitOrChangeId<'a> { id_bytes: Vec, } -impl CommitOrChangeId<'_> { +impl<'a> CommitOrChangeId<'a> { + pub fn new(repo: RepoRef<'a>, id: &impl ObjectId) -> Self { + CommitOrChangeId { + repo, + id_bytes: id.to_bytes(), + } + } + pub fn as_bytes(&self) -> &[u8] { &self.id_bytes } @@ -601,10 +608,7 @@ impl<'a> TemplateProperty for CommitIdProperty<'a> { type Output = CommitOrChangeId<'a>; fn extract(&self, context: &Commit) -> Self::Output { - CommitOrChangeId { - repo: self.repo, - id_bytes: context.id().to_bytes(), - } + CommitOrChangeId::new(self.repo, context.id()) } } @@ -616,10 +620,7 @@ impl<'a> TemplateProperty for ChangeIdProperty<'a> { type Output = CommitOrChangeId<'a>; fn extract(&self, context: &Commit) -> Self::Output { - CommitOrChangeId { - repo: self.repo, - id_bytes: context.change_id().to_bytes(), - } + CommitOrChangeId::new(self.repo, context.change_id()) } }