Skip to content

Commit

Permalink
feat(revset): add ! as shortcut for "only child"
Browse files Browse the repository at this point in the history
eg `@!`, `abc123!`, `current(foo)!`, etc
  • Loading branch information
claytonrcarter committed Dec 18, 2024
1 parent 41f8d7d commit f87823a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions git-branchless-revset/src/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Expr4: Expr<'input> = {
<lhs:Expr4> "~" => Expr::FunctionCall(Cow::Borrowed("ancestors.nth"), vec![lhs, Expr::Name(Cow::Borrowed("1"))]),
<lhs:Expr4> "~" <rhs:Name> => Expr::FunctionCall(Cow::Borrowed("ancestors.nth"), vec![lhs, Expr::Name(rhs)]),

<lhs:Expr4> "!" => Expr::FunctionCall(Cow::Borrowed("sole"), vec![Expr::FunctionCall(Cow::Borrowed("children"), vec![lhs])]),

<Expr5>
}

Expand Down
69 changes: 69 additions & 0 deletions git-branchless-revset/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,4 +667,73 @@ mod tests {

Ok(())
}

#[test]
fn test_revset_child_operator() -> eyre::Result<()> {
insta::assert_debug_snapshot!(parse("foo!"), @r###"
Ok(
FunctionCall(
"sole",
[
FunctionCall(
"children",
[
Name(
"foo",
),
],
),
],
),
)
"###);

insta::assert_debug_snapshot!(parse("@! + @!!"), @r###"
Ok(
FunctionCall(
"union",
[
FunctionCall(
"sole",
[
FunctionCall(
"children",
[
Name(
"@",
),
],
),
],
),
FunctionCall(
"sole",
[
FunctionCall(
"children",
[
FunctionCall(
"sole",
[
FunctionCall(
"children",
[
Name(
"@",
),
],
),
],
),
],
),
],
),
],
),
)
"###);

Ok(())
}
}

0 comments on commit f87823a

Please sign in to comment.