diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs index 7b6b542382..589974e552 100644 --- a/cli/src/commit_templater.rs +++ b/cli/src/commit_templater.rs @@ -14,6 +14,7 @@ use std::any::Any; use std::cmp::max; +use std::cmp::Ordering; use std::collections::HashMap; use std::io; use std::rc::Rc; @@ -427,6 +428,27 @@ impl<'repo> IntoTemplateProperty<'repo> for CommitTemplatePropertyKind<'repo> { (CommitTemplatePropertyKind::TreeDiff(_), _) => None, } } + + fn try_into_cmp( + self, + other: Self, + ) -> Option + 'repo>> { + match (self, other) { + (CommitTemplatePropertyKind::Core(lhs), CommitTemplatePropertyKind::Core(rhs)) => { + lhs.try_into_cmp(rhs) + } + (CommitTemplatePropertyKind::Core(_), _) => None, + (CommitTemplatePropertyKind::Commit(_), _) => None, + (CommitTemplatePropertyKind::CommitOpt(_), _) => None, + (CommitTemplatePropertyKind::CommitList(_), _) => None, + (CommitTemplatePropertyKind::RefName(_), _) => None, + (CommitTemplatePropertyKind::RefNameOpt(_), _) => None, + (CommitTemplatePropertyKind::RefNameList(_), _) => None, + (CommitTemplatePropertyKind::CommitOrChangeId(_), _) => None, + (CommitTemplatePropertyKind::ShortestIdPrefix(_), _) => None, + (CommitTemplatePropertyKind::TreeDiff(_), _) => None, + } + } } /// Table of functions that translate method call node of self type `T`. diff --git a/cli/src/generic_templater.rs b/cli/src/generic_templater.rs index 7c40dca978..cf8fee15b2 100644 --- a/cli/src/generic_templater.rs +++ b/cli/src/generic_templater.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::cmp::Ordering; use std::collections::HashMap; use crate::template_builder; @@ -177,6 +178,19 @@ impl<'a, C: 'a> IntoTemplateProperty<'a> for GenericTemplatePropertyKind<'a, C> (GenericTemplatePropertyKind::Self_(_), _) => None, } } + + fn try_into_cmp( + self, + other: Self, + ) -> Option + 'a>> { + match (self, other) { + (GenericTemplatePropertyKind::Core(lhs), GenericTemplatePropertyKind::Core(rhs)) => { + lhs.try_into_cmp(rhs) + } + (GenericTemplatePropertyKind::Core(_), _) => None, + (GenericTemplatePropertyKind::Self_(_), _) => None, + } + } } /// Function that translates keyword (or 0-ary method call node of the self type diff --git a/cli/src/operation_templater.rs b/cli/src/operation_templater.rs index 8e23c7d57e..50b1bc717b 100644 --- a/cli/src/operation_templater.rs +++ b/cli/src/operation_templater.rs @@ -13,6 +13,7 @@ // limitations under the License. use std::any::Any; +use std::cmp::Ordering; use std::collections::HashMap; use std::io; @@ -200,6 +201,18 @@ impl IntoTemplateProperty<'static> for OperationTemplatePropertyKind { (OperationTemplatePropertyKind::OperationId(_), _) => None, } } + + fn try_into_cmp(self, other: Self) -> Option>> { + match (self, other) { + ( + OperationTemplatePropertyKind::Core(lhs), + OperationTemplatePropertyKind::Core(rhs), + ) => lhs.try_into_cmp(rhs), + (OperationTemplatePropertyKind::Core(_), _) => None, + (OperationTemplatePropertyKind::Operation(_), _) => None, + (OperationTemplatePropertyKind::OperationId(_), _) => None, + } + } } /// Table of functions that translate method call node of self type `T`. diff --git a/cli/src/template_builder.rs b/cli/src/template_builder.rs index 0b0246de8f..0811938f87 100644 --- a/cli/src/template_builder.rs +++ b/cli/src/template_builder.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::cmp::Ordering; use std::collections::HashMap; use std::io; @@ -165,6 +166,10 @@ pub trait IntoTemplateProperty<'a> { /// Transforms into a property that will evaluate to `self == other`. fn try_into_eq(self, other: Self) -> Option + 'a>>; + + /// Transforms into a property that will evaluate to an [`Ordering`]. + fn try_into_cmp(self, other: Self) + -> Option + 'a>>; } pub enum CoreTemplatePropertyKind<'a> { @@ -294,6 +299,28 @@ impl<'a> IntoTemplateProperty<'a> for CoreTemplatePropertyKind<'a> { (CoreTemplatePropertyKind::ListTemplate(_), _) => None, } } + + fn try_into_cmp( + self, + other: Self, + ) -> Option + 'a>> { + match (self, other) { + (CoreTemplatePropertyKind::Integer(lhs), CoreTemplatePropertyKind::Integer(rhs)) => { + Some(Box::new((lhs, rhs).map(|(l, r)| l.cmp(&r)))) + } + (CoreTemplatePropertyKind::String(_), _) => None, + (CoreTemplatePropertyKind::StringList(_), _) => None, + (CoreTemplatePropertyKind::Boolean(_), _) => None, + (CoreTemplatePropertyKind::Integer(_), _) => None, + (CoreTemplatePropertyKind::IntegerOpt(_), _) => None, + (CoreTemplatePropertyKind::Signature(_), _) => None, + (CoreTemplatePropertyKind::SizeHint(_), _) => None, + (CoreTemplatePropertyKind::Timestamp(_), _) => None, + (CoreTemplatePropertyKind::TimestampRange(_), _) => None, + (CoreTemplatePropertyKind::Template(_), _) => None, + (CoreTemplatePropertyKind::ListTemplate(_), _) => None, + } + } } /// Function that translates global function call node. @@ -540,6 +567,13 @@ impl<'a, P: IntoTemplateProperty<'a>> Expression

{ pub fn try_into_eq(self, other: Self) -> Option + 'a>> { self.property.try_into_eq(other.property) } + + pub fn try_into_cmp( + self, + other: Self, + ) -> Option + 'a>> { + self.property.try_into_cmp(other.property) + } } pub struct BuildContext<'i, P> {