From 19a3fb7d6c3aec30163e9790da5001632b776451 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Tue, 15 Nov 2022 19:45:53 +0900 Subject: [PATCH] revset: flatten match arms of description|author|committer predicates Since most of the code duplicates has been extracted to helper functions, nested match statement looks more verbose. --- lib/src/revset.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 0abdf502a..4f857defb 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -735,18 +735,20 @@ fn parse_function_expression( expect_no_arguments(name, arguments_pair)?; Ok(RevsetExpression::all().with_parent_count(2..u32::MAX)) } - "description" | "author" | "committer" => { + "description" => { let arg = expect_one_argument(name, arguments_pair)?; let needle = parse_function_argument_to_string(name, arg)?; - let candidates = RevsetExpression::all(); - match name { - "description" => Ok(candidates.with_description(needle)), - "author" => Ok(candidates.with_author(needle)), - "committer" => Ok(candidates.with_committer(needle)), - _ => { - panic!("unexpected function name: {}", name) - } - } + Ok(RevsetExpression::all().with_description(needle)) + } + "author" => { + let arg = expect_one_argument(name, arguments_pair)?; + let needle = parse_function_argument_to_string(name, arg)?; + Ok(RevsetExpression::all().with_author(needle)) + } + "committer" => { + let arg = expect_one_argument(name, arguments_pair)?; + let needle = parse_function_argument_to_string(name, arg)?; + Ok(RevsetExpression::all().with_committer(needle)) } "file" => { if let Some(ctx) = workspace_ctx {