Skip to content

Conversation

@claytonrcarter
Copy link
Collaborator

As discussed in discord, this adds an exactly revset function. This returns the given revset only if it contains the expected number of commits. Otherwise it errors out. This was very straightforward to implement and includes tests.

Notes

  • I considered creating a more general usage count function that would behave like the text/date matchers, for example:
    • count(<revset>, exactly:1)
    • count(<revset>, greater_than:2)
    • count(<revset>, less_than_or_equal_to:3), etc.
    • While that would be cool, it was more than I needed at this time.
  • At first I had also added a sole() function, but I removed that in favor of making it an alias for exactly($1, 1) using the revset aliases PR.
  • I have already found this useful in scripting to give me added confidence that some automated task won't target more than I expect it to. I didn't expect this, but I like where it's going; for example I might write a script guard like if ! git query exactly(parents($INPUT), 1) ; then exit ; fi to prevent myself from accidentally operating on a merge commit.
  • The ExpectedSingletonSet appears to be unused. Should it be removed or would you like to keep it around?

Copy link
Owner

@arxanas arxanas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I had also added a sole() function, but I removed that in favor of making it an alias for exactly($1, 1) using the revset aliases PR.

Sounds good.

The ExpectedSingletonSet appears to be unused. Should it be removed or would you like to keep it around?

Oops, yeah, we can remove that. I forget what I wanted to use that for.

This also removes `ExpectedSingletonSet`, which was unused.
@claytonrcarter claytonrcarter merged commit f632e2f into master Aug 23, 2022
@claytonrcarter claytonrcarter deleted the revset-exactly branch August 23, 2022 08:42
@claytonrcarter
Copy link
Collaborator Author

FYI I've added exactly to the revset wiki. ✅

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.

3 participants