mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-09 05:58:55 +00:00
templater: store type-erased version of commit/change id
It's unlikely we'll need to discriminate commit/change id types while templating, so let's unify them. Since ObjectId trait isn't object safe, I decided to simply store bytes instead of Box<dyn ObjectId>.
This commit is contained in:
parent
0f4269a141
commit
d6c6cdb45c
1 changed files with 6 additions and 11 deletions
|
@ -18,7 +18,7 @@ use std::io;
|
||||||
use std::ops::AddAssign;
|
use std::ops::AddAssign;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use jujutsu_lib::backend::{ChangeId, CommitId, ObjectId, Signature, Timestamp};
|
use jujutsu_lib::backend::{ChangeId, ObjectId, Signature, Timestamp};
|
||||||
use jujutsu_lib::commit::Commit;
|
use jujutsu_lib::commit::Commit;
|
||||||
use jujutsu_lib::op_store::WorkspaceId;
|
use jujutsu_lib::op_store::WorkspaceId;
|
||||||
use jujutsu_lib::repo::RepoRef;
|
use jujutsu_lib::repo::RepoRef;
|
||||||
|
@ -407,18 +407,13 @@ impl<'a, C, I, O> TemplateProperty<C, O> for TemplateFunction<'a, C, I, O> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Type-erased `CommitId`/`ChangeId`.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum CommitOrChangeId {
|
pub struct CommitOrChangeId(Vec<u8>);
|
||||||
CommitId(CommitId),
|
|
||||||
ChangeId(ChangeId),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommitOrChangeId {
|
impl CommitOrChangeId {
|
||||||
pub fn hex(&self) -> String {
|
pub fn hex(&self) -> String {
|
||||||
match self {
|
hex::encode(&self.0)
|
||||||
CommitOrChangeId::CommitId(id) => id.hex(),
|
|
||||||
CommitOrChangeId::ChangeId(id) => id.hex(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn short(&self) -> String {
|
pub fn short(&self) -> String {
|
||||||
|
@ -470,7 +465,7 @@ pub struct CommitIdProperty;
|
||||||
|
|
||||||
impl TemplateProperty<Commit, CommitOrChangeId> for CommitIdProperty {
|
impl TemplateProperty<Commit, CommitOrChangeId> for CommitIdProperty {
|
||||||
fn extract(&self, context: &Commit) -> CommitOrChangeId {
|
fn extract(&self, context: &Commit) -> CommitOrChangeId {
|
||||||
CommitOrChangeId::CommitId(context.id().clone())
|
CommitOrChangeId(context.id().to_bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,7 +473,7 @@ pub struct ChangeIdProperty;
|
||||||
|
|
||||||
impl TemplateProperty<Commit, CommitOrChangeId> for ChangeIdProperty {
|
impl TemplateProperty<Commit, CommitOrChangeId> for ChangeIdProperty {
|
||||||
fn extract(&self, context: &Commit) -> CommitOrChangeId {
|
fn extract(&self, context: &Commit) -> CommitOrChangeId {
|
||||||
CommitOrChangeId::ChangeId(context.change_id().clone())
|
CommitOrChangeId(context.change_id().to_bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue