mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-09 22:16:32 +00:00
templater: move CommitOrChangeIdKeyword functions to CommitOrChangeId
CommitOrChangeIdKeyword is no longer needed.
This commit is contained in:
parent
bf58051c55
commit
38e6924482
2 changed files with 15 additions and 26 deletions
|
@ -23,12 +23,12 @@ use pest_derive::Parser;
|
|||
use crate::formatter::PlainTextFormatter;
|
||||
use crate::templater::{
|
||||
AuthorProperty, BranchProperty, ChangeIdProperty, CommitIdProperty, CommitOrChangeId,
|
||||
CommitOrChangeIdKeyword, CommitOrChangeIdShort, CommitOrChangeIdShortPrefixAndBrackets,
|
||||
CommitterProperty, ConditionalTemplate, ConflictProperty, ConstantTemplateProperty,
|
||||
DescriptionProperty, DivergentProperty, DynamicLabelTemplate, EmptyProperty, GitRefsProperty,
|
||||
IsGitHeadProperty, IsWorkingCopyProperty, LabelTemplate, ListTemplate, LiteralTemplate,
|
||||
SignatureTimestamp, StringPropertyTemplate, TagProperty, Template, TemplateFunction,
|
||||
TemplateProperty, WorkingCopiesProperty,
|
||||
CommitOrChangeIdShort, CommitOrChangeIdShortPrefixAndBrackets, CommitterProperty,
|
||||
ConditionalTemplate, ConflictProperty, ConstantTemplateProperty, DescriptionProperty,
|
||||
DivergentProperty, DynamicLabelTemplate, EmptyProperty, GitRefsProperty, IsGitHeadProperty,
|
||||
IsWorkingCopyProperty, LabelTemplate, ListTemplate, LiteralTemplate, SignatureTimestamp,
|
||||
StringPropertyTemplate, TagProperty, Template, TemplateFunction, TemplateProperty,
|
||||
WorkingCopiesProperty,
|
||||
};
|
||||
use crate::time_util;
|
||||
|
||||
|
@ -295,10 +295,9 @@ fn coerce_to_string<'a, I: 'a>(
|
|||
property,
|
||||
Box::new(|value| String::from(if value { "true" } else { "false" })),
|
||||
)),
|
||||
Property::CommitOrChangeId(property, _) => Box::new(TemplateFunction::new(
|
||||
property,
|
||||
Box::new(CommitOrChangeIdKeyword::default_format),
|
||||
)),
|
||||
Property::CommitOrChangeId(property, _) => {
|
||||
Box::new(TemplateFunction::new(property, Box::new(|id| id.hex())))
|
||||
}
|
||||
Property::Signature(property) => Box::new(TemplateFunction::new(
|
||||
property,
|
||||
Box::new(|signature| signature.name),
|
||||
|
|
|
@ -420,23 +420,13 @@ impl CommitOrChangeId {
|
|||
CommitOrChangeId::ChangeId(id) => id.hex(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CommitOrChangeIdKeyword;
|
||||
|
||||
impl CommitOrChangeIdKeyword {
|
||||
pub fn default_format(commit_or_change_id: CommitOrChangeId) -> String {
|
||||
commit_or_change_id.hex()
|
||||
pub fn short(&self) -> String {
|
||||
self.hex()[..12].to_string()
|
||||
}
|
||||
|
||||
pub fn short_format(commit_or_change_id: CommitOrChangeId) -> String {
|
||||
commit_or_change_id.hex()[..12].to_string()
|
||||
}
|
||||
pub fn short_prefix_and_brackets_format(
|
||||
commit_or_change_id: CommitOrChangeId,
|
||||
repo: RepoRef,
|
||||
) -> String {
|
||||
highlight_shortest_prefix(&commit_or_change_id.hex(), 12, repo)
|
||||
pub fn short_prefix_and_brackets(&self, repo: RepoRef) -> String {
|
||||
highlight_shortest_prefix(&self.hex(), 12, repo)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -459,7 +449,7 @@ pub struct CommitOrChangeIdShort<'a> {
|
|||
|
||||
impl TemplateProperty<CommitOrChangeId, String> for CommitOrChangeIdShort<'_> {
|
||||
fn extract(&self, context: &CommitOrChangeId) -> String {
|
||||
CommitOrChangeIdKeyword::short_format(context.clone())
|
||||
context.short()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -469,7 +459,7 @@ pub struct CommitOrChangeIdShortPrefixAndBrackets<'a> {
|
|||
|
||||
impl TemplateProperty<CommitOrChangeId, String> for CommitOrChangeIdShortPrefixAndBrackets<'_> {
|
||||
fn extract(&self, context: &CommitOrChangeId) -> String {
|
||||
CommitOrChangeIdKeyword::short_prefix_and_brackets_format(context.clone(), self.repo)
|
||||
context.short_prefix_and_brackets(self.repo)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue