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 10, 2024
1 parent 2cb8484 commit b625b17
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - ReleaseDate

### Added

- (#1461): Added `+` postfix revset operator; evaluates to "only child".

## [v0.10.0] - 2024-10-10

### Added
Expand Down
1 change: 1 addition & 0 deletions git-branchless-revset/src/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ grammar;
pub Expr: Expr<'input> = {
<lhs:Expr> "|" <rhs:Expr2> => Expr::FunctionCall(Cow::Borrowed("union"), vec![lhs, rhs]),
<lhs:Expr> "+" <rhs:Expr2> => Expr::FunctionCall(Cow::Borrowed("union"), vec![lhs, rhs]),
<lhs:Expr> "+" => Expr::FunctionCall(Cow::Borrowed("sole"), vec![Expr::FunctionCall(Cow::Borrowed("children"), vec![lhs])]),
<lhs:Expr> "or" <rhs:Expr2> => Expr::FunctionCall(Cow::Borrowed("union"), vec![lhs, rhs]),
<Expr2>,
}
Expand Down
24 changes: 24 additions & 0 deletions git-branchless-revset/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,4 +667,28 @@ mod tests {

Ok(())
}

#[test]
fn test_revset_child_operator() -> eyre::Result<()> {
// TODO can we get a revset operator to complement ~/^?
insta::assert_debug_snapshot!(parse("foo+"), @r###"
Ok(
FunctionCall(
"sole",
[
FunctionCall(
"children",
[
Name(
"foo",
),
],
),
],
),
)
"###);

Ok(())
}
}

0 comments on commit b625b17

Please sign in to comment.