mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-03 18:24:19 +00:00
templater: add CommitOrChangeId constructor to help inline keywords
This commit is contained in:
parent
dc0e3c1855
commit
846be15132
1 changed files with 10 additions and 9 deletions
|
@ -486,7 +486,14 @@ pub struct CommitOrChangeId<'a> {
|
|||
id_bytes: Vec<u8>,
|
||||
}
|
||||
|
||||
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<Commit> 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<Commit> 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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue