mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-31 03:42:39 +00:00
templater: remove Template::has_content() superseded by FormatRecorder
This commit is contained in:
parent
974a5145e0
commit
558aa15e6e
@ -320,10 +320,6 @@ impl Template<()> for CommitOrChangeId<'_> {
|
||||
fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> {
|
||||
formatter.write_str(&self.hex())
|
||||
}
|
||||
|
||||
fn has_content(&self, _: &()) -> bool {
|
||||
true // a valid CommitId/ChangeId should never be empty
|
||||
}
|
||||
}
|
||||
|
||||
fn build_commit_or_change_id_method<'repo>(
|
||||
@ -376,10 +372,6 @@ impl Template<()> for ShortestIdPrefix {
|
||||
formatter.with_label("prefix", |fmt| fmt.write_str(&self.prefix))?;
|
||||
formatter.with_label("rest", |fmt| fmt.write_str(&self.rest))
|
||||
}
|
||||
|
||||
fn has_content(&self, _: &()) -> bool {
|
||||
!self.prefix.is_empty() || !self.rest.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl ShortestIdPrefix {
|
||||
|
@ -155,10 +155,6 @@ impl Template<()> for OperationId {
|
||||
fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> {
|
||||
formatter.write_str(&self.hex())
|
||||
}
|
||||
|
||||
fn has_content(&self, _: &()) -> bool {
|
||||
!self.as_bytes().is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
fn build_operation_id_method(
|
||||
|
@ -21,8 +21,6 @@ use crate::time_util;
|
||||
|
||||
pub trait Template<C> {
|
||||
fn format(&self, context: &C, formatter: &mut dyn Formatter) -> io::Result<()>;
|
||||
/// Returns true if `format()` will generate output other than labels.
|
||||
fn has_content(&self, context: &C) -> bool;
|
||||
}
|
||||
|
||||
pub trait IntoTemplate<'a, C> {
|
||||
@ -33,10 +31,6 @@ impl<C, T: Template<C> + ?Sized> Template<C> for Box<T> {
|
||||
fn format(&self, context: &C, formatter: &mut dyn Formatter) -> io::Result<()> {
|
||||
<T as Template<C>>::format(self, context, formatter)
|
||||
}
|
||||
|
||||
fn has_content(&self, context: &C) -> bool {
|
||||
<T as Template<C>>::has_content(self, context)
|
||||
}
|
||||
}
|
||||
|
||||
impl Template<()> for Signature {
|
||||
@ -47,30 +41,18 @@ impl Template<()> for Signature {
|
||||
write!(formatter, ">")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn has_content(&self, _: &()) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl Template<()> for String {
|
||||
fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> {
|
||||
formatter.write_str(self)
|
||||
}
|
||||
|
||||
fn has_content(&self, _: &()) -> bool {
|
||||
!self.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl Template<()> for Timestamp {
|
||||
fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> {
|
||||
formatter.write_str(&time_util::format_absolute_timestamp(self))
|
||||
}
|
||||
|
||||
fn has_content(&self, _: &()) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
@ -101,30 +83,18 @@ impl Template<()> for TimestampRange {
|
||||
self.end.format(&(), formatter)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn has_content(&self, _: &()) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl Template<()> for bool {
|
||||
fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> {
|
||||
formatter.write_str(if *self { "true" } else { "false" })
|
||||
}
|
||||
|
||||
fn has_content(&self, _: &()) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl Template<()> for i64 {
|
||||
fn format(&self, _: &(), formatter: &mut dyn Formatter) -> io::Result<()> {
|
||||
write!(formatter, "{self}")
|
||||
}
|
||||
|
||||
fn has_content(&self, _: &()) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LabelTemplate<T, L> {
|
||||
@ -158,10 +128,6 @@ where
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn has_content(&self, context: &C) -> bool {
|
||||
self.content.has_content(context)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ListTemplate<T>(pub Vec<T>);
|
||||
@ -173,10 +139,6 @@ impl<C, T: Template<C>> Template<C> for ListTemplate<T> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn has_content(&self, context: &C) -> bool {
|
||||
self.0.iter().any(|template| template.has_content(context))
|
||||
}
|
||||
}
|
||||
|
||||
/// Like `ListTemplate`, but inserts a separator between non-empty templates.
|
||||
@ -225,12 +187,6 @@ where
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn has_content(&self, context: &C) -> bool {
|
||||
self.contents
|
||||
.iter()
|
||||
.any(|template| template.has_content(context))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TemplateProperty<C> {
|
||||
@ -284,10 +240,6 @@ impl<C, O: Template<()>> Template<C> for Literal<O> {
|
||||
fn format(&self, _context: &C, formatter: &mut dyn Formatter) -> io::Result<()> {
|
||||
self.0.format(&(), formatter)
|
||||
}
|
||||
|
||||
fn has_content(&self, _context: &C) -> bool {
|
||||
self.0.has_content(&())
|
||||
}
|
||||
}
|
||||
|
||||
impl<C, O: Clone> TemplateProperty<C> for Literal<O> {
|
||||
@ -333,11 +285,6 @@ where
|
||||
let template = self.property.extract(context);
|
||||
template.format(&(), formatter)
|
||||
}
|
||||
|
||||
fn has_content(&self, context: &C) -> bool {
|
||||
let template = self.property.extract(context);
|
||||
template.has_content(&())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, C: 'a, O> IntoTemplate<'a, C> for Box<dyn TemplateProperty<C, Output = O> + 'a>
|
||||
@ -408,16 +355,6 @@ where
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn has_content(&self, context: &C) -> bool {
|
||||
if self.condition.extract(context) {
|
||||
self.true_template.has_content(context)
|
||||
} else if let Some(false_template) = &self.false_template {
|
||||
false_template.has_content(context)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: If needed, add a ContextualTemplateFunction where the function also
|
||||
|
Loading…
x
Reference in New Issue
Block a user