Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(revset): add + as shortcut for "only child" #1461

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

claytonrcarter
Copy link
Collaborator

This adds + as a postfix revset operator that evaluates to sole(children(...)). I chose + because it matches the similar operator in jj revsets, but I didn't add - for symmetry because I didn't feel the need since we already have ~ and ^.

Note that I chose sole(...) because I have found that I (almost?) always wanted this shorthand in cases where there is only 1 child, and if I wanted all children, I could reach for the regular children(...) function. I don't think I care about this that strongly, though, and I'd be OK to remove sole(...) if preferred.

Handy use cases:

  • when it's easier to paste the commit already on the clipboard and just add + or ++ instead of copying the commit you really want :)
  • unstacking a stack of branches: git move -s prev-branch+ -d main
  • another way to do git next: git sw @+

@claytonrcarter claytonrcarter force-pushed the revset-plus branch 2 times, most recently from 23f0dae to b625b17 Compare December 10, 2024 16:11
@arxanas
Copy link
Owner

arxanas commented Dec 13, 2024

Sorry, haven't had time to go through my pending PRs yet. Generally speaking, I would want to be consistent with jj's revset language where possible, since git-branchless is probably a gateway to jj for many users.

@claytonrcarter claytonrcarter marked this pull request as draft December 16, 2024 02:12
@claytonrcarter
Copy link
Collaborator Author

consistent with jj's revset

OK, for now I have reimplemented this to use ! instead of +. Not only does it avoid the conflict with jj, but I found that my original implementation wasn't sophisticated at all enough to correctly handle a case like @+ + @++: it was parsed as (@+ + @+)+ instead of my intended @+ + (@++). I didn't understand the lalrpop grammar enough to fix that. Using ! sidesteps both of these issues, but at the cost of introducing a totally new operator.

If I can get my head around the union conflict and the lalrpop grammar, I would prefer to implement it to mimic jj, so I'll just draft this ! version for now.

eg `@!`, `abc123!`, `current(foo)!`, etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants