Skip to content

Commit b625b17

Browse files
feat(revset): add + as shortcut for "only child"
eg `@+`, `abc123+`, `current(foo)+`, etc
1 parent 2cb8484 commit b625b17

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [Unreleased] - ReleaseDate
1111

12+
### Added
13+
14+
- (#1461): Added `+` postfix revset operator; evaluates to "only child".
15+
1216
## [v0.10.0] - 2024-10-10
1317

1418
### Added

git-branchless-revset/src/grammar.lalrpop

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ grammar;
99
pub Expr: Expr<'input> = {
1010
<lhs:Expr> "|" <rhs:Expr2> => Expr::FunctionCall(Cow::Borrowed("union"), vec![lhs, rhs]),
1111
<lhs:Expr> "+" <rhs:Expr2> => Expr::FunctionCall(Cow::Borrowed("union"), vec![lhs, rhs]),
12+
<lhs:Expr> "+" => Expr::FunctionCall(Cow::Borrowed("sole"), vec![Expr::FunctionCall(Cow::Borrowed("children"), vec![lhs])]),
1213
<lhs:Expr> "or" <rhs:Expr2> => Expr::FunctionCall(Cow::Borrowed("union"), vec![lhs, rhs]),
1314
<Expr2>,
1415
}

git-branchless-revset/src/parser.rs

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

668668
Ok(())
669669
}
670+
671+
#[test]
672+
fn test_revset_child_operator() -> eyre::Result<()> {
673+
// TODO can we get a revset operator to complement ~/^?
674+
insta::assert_debug_snapshot!(parse("foo+"), @r###"
675+
Ok(
676+
FunctionCall(
677+
"sole",
678+
[
679+
FunctionCall(
680+
"children",
681+
[
682+
Name(
683+
"foo",
684+
),
685+
],
686+
),
687+
],
688+
),
689+
)
690+
"###);
691+
692+
Ok(())
693+
}
670694
}

0 commit comments

Comments
 (0)