mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
revset: make error type opaque to try_transform_expression()
It no longer handles RevsetResolutionError.
This commit is contained in:
parent
f1e2d19d57
commit
3927c01d08
1 changed files with 19 additions and 19 deletions
|
@ -13,6 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::convert::Infallible;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -1110,11 +1111,10 @@ fn transform_expression_bottom_up(
|
||||||
expression: &Rc<RevsetExpression>,
|
expression: &Rc<RevsetExpression>,
|
||||||
mut f: impl FnMut(&Rc<RevsetExpression>) -> TransformedExpression,
|
mut f: impl FnMut(&Rc<RevsetExpression>) -> TransformedExpression,
|
||||||
) -> TransformedExpression {
|
) -> TransformedExpression {
|
||||||
try_transform_expression(expression, |_| Ok(None), |expression| Ok(f(expression))).unwrap()
|
try_transform_expression::<Infallible>(expression, |_| Ok(None), |expression| Ok(f(expression)))
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
type TransformResult = Result<TransformedExpression, RevsetResolutionError>;
|
|
||||||
|
|
||||||
/// Walks `expression` tree and applies transformation recursively.
|
/// Walks `expression` tree and applies transformation recursively.
|
||||||
///
|
///
|
||||||
/// `pre` is the callback to rewrite subtree including children. It is
|
/// `pre` is the callback to rewrite subtree including children. It is
|
||||||
|
@ -1127,16 +1127,16 @@ type TransformResult = Result<TransformedExpression, RevsetResolutionError>;
|
||||||
/// If no nodes rewritten, this function returns `None`.
|
/// If no nodes rewritten, this function returns `None`.
|
||||||
/// `std::iter::successors()` could be used if the transformation needs to be
|
/// `std::iter::successors()` could be used if the transformation needs to be
|
||||||
/// applied repeatedly until converged.
|
/// applied repeatedly until converged.
|
||||||
fn try_transform_expression(
|
fn try_transform_expression<E>(
|
||||||
expression: &Rc<RevsetExpression>,
|
expression: &Rc<RevsetExpression>,
|
||||||
mut pre: impl FnMut(&Rc<RevsetExpression>) -> TransformResult,
|
mut pre: impl FnMut(&Rc<RevsetExpression>) -> Result<TransformedExpression, E>,
|
||||||
mut post: impl FnMut(&Rc<RevsetExpression>) -> TransformResult,
|
mut post: impl FnMut(&Rc<RevsetExpression>) -> Result<TransformedExpression, E>,
|
||||||
) -> TransformResult {
|
) -> Result<TransformedExpression, E> {
|
||||||
fn transform_child_rec(
|
fn transform_child_rec<E>(
|
||||||
expression: &Rc<RevsetExpression>,
|
expression: &Rc<RevsetExpression>,
|
||||||
pre: &mut impl FnMut(&Rc<RevsetExpression>) -> TransformResult,
|
pre: &mut impl FnMut(&Rc<RevsetExpression>) -> Result<TransformedExpression, E>,
|
||||||
post: &mut impl FnMut(&Rc<RevsetExpression>) -> TransformResult,
|
post: &mut impl FnMut(&Rc<RevsetExpression>) -> Result<TransformedExpression, E>,
|
||||||
) -> TransformResult {
|
) -> Result<TransformedExpression, E> {
|
||||||
Ok(match expression.as_ref() {
|
Ok(match expression.as_ref() {
|
||||||
RevsetExpression::None => None,
|
RevsetExpression::None => None,
|
||||||
RevsetExpression::All => None,
|
RevsetExpression::All => None,
|
||||||
|
@ -1216,11 +1216,11 @@ fn try_transform_expression(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
fn transform_rec_pair(
|
fn transform_rec_pair<E>(
|
||||||
(expression1, expression2): (&Rc<RevsetExpression>, &Rc<RevsetExpression>),
|
(expression1, expression2): (&Rc<RevsetExpression>, &Rc<RevsetExpression>),
|
||||||
pre: &mut impl FnMut(&Rc<RevsetExpression>) -> TransformResult,
|
pre: &mut impl FnMut(&Rc<RevsetExpression>) -> Result<TransformedExpression, E>,
|
||||||
post: &mut impl FnMut(&Rc<RevsetExpression>) -> TransformResult,
|
post: &mut impl FnMut(&Rc<RevsetExpression>) -> Result<TransformedExpression, E>,
|
||||||
) -> Result<Option<(Rc<RevsetExpression>, Rc<RevsetExpression>)>, RevsetResolutionError> {
|
) -> Result<Option<(Rc<RevsetExpression>, Rc<RevsetExpression>)>, E> {
|
||||||
match (
|
match (
|
||||||
transform_rec(expression1, pre, post)?,
|
transform_rec(expression1, pre, post)?,
|
||||||
transform_rec(expression2, pre, post)?,
|
transform_rec(expression2, pre, post)?,
|
||||||
|
@ -1234,11 +1234,11 @@ fn try_transform_expression(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transform_rec(
|
fn transform_rec<E>(
|
||||||
expression: &Rc<RevsetExpression>,
|
expression: &Rc<RevsetExpression>,
|
||||||
pre: &mut impl FnMut(&Rc<RevsetExpression>) -> TransformResult,
|
pre: &mut impl FnMut(&Rc<RevsetExpression>) -> Result<TransformedExpression, E>,
|
||||||
post: &mut impl FnMut(&Rc<RevsetExpression>) -> TransformResult,
|
post: &mut impl FnMut(&Rc<RevsetExpression>) -> Result<TransformedExpression, E>,
|
||||||
) -> TransformResult {
|
) -> Result<TransformedExpression, E> {
|
||||||
if let Some(new_expression) = pre(expression)? {
|
if let Some(new_expression) = pre(expression)? {
|
||||||
return Ok(Some(new_expression));
|
return Ok(Some(new_expression));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue