Skip to content

Commit f87823a

Browse files
feat(revset): add ! as shortcut for "only child"
eg `@!`, `abc123!`, `current(foo)!`, etc
1 parent 41f8d7d commit f87823a

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

git-branchless-revset/src/grammar.lalrpop

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Expr4: Expr<'input> = {
4646
<lhs:Expr4> "~" => Expr::FunctionCall(Cow::Borrowed("ancestors.nth"), vec![lhs, Expr::Name(Cow::Borrowed("1"))]),
4747
<lhs:Expr4> "~" <rhs:Name> => Expr::FunctionCall(Cow::Borrowed("ancestors.nth"), vec![lhs, Expr::Name(rhs)]),
4848

49+
<lhs:Expr4> "!" => Expr::FunctionCall(Cow::Borrowed("sole"), vec![Expr::FunctionCall(Cow::Borrowed("children"), vec![lhs])]),
50+
4951
<Expr5>
5052
}
5153

git-branchless-revset/src/parser.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,4 +667,73 @@ mod tests {
667667

668668
Ok(())
669669
}
670+
671+
#[test]
672+
fn test_revset_child_operator() -> eyre::Result<()> {
673+
insta::assert_debug_snapshot!(parse("foo!"), @r###"
674+
Ok(
675+
FunctionCall(
676+
"sole",
677+
[
678+
FunctionCall(
679+
"children",
680+
[
681+
Name(
682+
"foo",
683+
),
684+
],
685+
),
686+
],
687+
),
688+
)
689+
"###);
690+
691+
insta::assert_debug_snapshot!(parse("@! + @!!"), @r###"
692+
Ok(
693+
FunctionCall(
694+
"union",
695+
[
696+
FunctionCall(
697+
"sole",
698+
[
699+
FunctionCall(
700+
"children",
701+
[
702+
Name(
703+
"@",
704+
),
705+
],
706+
),
707+
],
708+
),
709+
FunctionCall(
710+
"sole",
711+
[
712+
FunctionCall(
713+
"children",
714+
[
715+
FunctionCall(
716+
"sole",
717+
[
718+
FunctionCall(
719+
"children",
720+
[
721+
Name(
722+
"@",
723+
),
724+
],
725+
),
726+
],
727+
),
728+
],
729+
),
730+
],
731+
),
732+
],
733+
),
734+
)
735+
"###);
736+
737+
Ok(())
738+
}
670739
}

0 commit comments

Comments
 (0)