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

Add optional depth parameter to ancestors() revset function #2200

Merged
merged 2 commits into from
Sep 7, 2023

Conversation

sullyj3
Copy link
Collaborator

@sullyj3 sullyj3 commented Sep 2, 2023

Allows ancestors(rev, n) in the revset language.

⮞ jj log -r 'ancestors(@, 5)'
@  korrtmol [email protected] 2023-09-02 17:37:15.000 +10:00 c9dca8e9
│  (empty) Add test for revset n ancestors
◉  owvqrlnu [email protected] 2023-09-02 17:35:20.000 +10:00 main* HEAD@git 498cd57b
│  Add optional argument n to ancestors() in revset language
◉  yoslkysy [email protected] 2023-09-02 17:09:53.000 +10:00 80456ec4
│  Add generations argument to RevsetExpression::ancestors method
◉  uqwupmro [email protected] 2023-09-01 16:49:23.000 -07:00 main@upstream e3825495
│  store: don't include cached objects in `Debug` format
◉  ostmnpsu [email protected] 2023-09-01 16:23:39.000 -07:00 16c897d8
│  conflicts: leverage `Merge::map()` in `materialize_merge_result()`
~

See #1984 for some context.

Since I care most about the git log -n 5 use-case, I chose to implement the simplest option of those discussed, returning the last n changes, including the "descendent" change.

Support for ancestors(x, m, n) can be added later, since it will be backwards compatible. However, if we later went for the ancestors(x, m..n) syntax, I believe that would require a breaking change, unless it was allowed to support either a number or a range argument. I'm not familiar enough with the language to know if that's possible.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

@google-cla
Copy link

google-cla bot commented Sep 2, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@yuja
Copy link
Collaborator

yuja commented Sep 2, 2023

Thanks, the code looks good to me. Can you also update docs/revsets.md (and add a couple of tests)?

Maybe we need to call the count argument differently in the doc since it's the limit of the ancestor lookup. Mercurial calls it a depth. I think generation is also good.

Support for ancestors(x, m, n) can be added later, since it will be backwards compatible. However, if we later went for the ancestors(x, m..n) syntax, I believe that would require a breaking change, unless it was allowed to support either a number or a range argument.

Actually adding ancestors(x, m, n) would be a bit trickier than m..n since the arguments order differs from ancestors(x, n).

@sullyj3
Copy link
Collaborator Author

sullyj3 commented Sep 3, 2023

For sure! For the tests I was thinking just a couple different invocations of jj log, with and without the optional argument. Should I stick them in cli/tests/test_revset_output.rs, or cli/tests/test_log_command.rs?

@yuja
Copy link
Collaborator

yuja commented Sep 3, 2023

For the tests I was thinking just a couple different invocations of jj log, with and without the optional argument. Should I stick them in cli/tests/test_revset_output.rs, or cli/tests/test_log_command.rs?

I think lib/tests/test_revset.rs is better place since we don't change the CLI behavior. test_evaluate_expression_ancestors() have some tests for :x (or ancestors(x).)

@sullyj3
Copy link
Collaborator Author

sullyj3 commented Sep 5, 2023

Ah perfect, I missed the lib tests somehow.

@sullyj3
Copy link
Collaborator Author

sullyj3 commented Sep 5, 2023

Maybe we need to call the count argument differently in the doc since it's the limit of the ancestor lookup. Mercurial calls it a depth. I think generation is also good.

I like depth. In the code, "generation" is used to refer to a range, whereas I think "depth" implies a single number. I'll also change the code to keep it consistent.

@sullyj3
Copy link
Collaborator Author

sullyj3 commented Sep 5, 2023

Just gotta add docs, and I believe the config schema is not applicable to this

@sullyj3 sullyj3 changed the title Add optional count parameter to ancestors() revset function Add optional depth parameter to ancestors() revset function Sep 5, 2023
@sullyj3
Copy link
Collaborator Author

sullyj3 commented Sep 5, 2023

rebased on main

@sullyj3 sullyj3 marked this pull request as ready for review September 5, 2023 14:35
Copy link
Member

@martinvonz martinvonz left a comment

Choose a reason for hiding this comment

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

Thanks for your PR. I think you can squash all 6 commits into one, per
https://github.com/martinvonz/jj/blob/main/docs/contributing.md#code-reviews

lib/src/revset.rs Outdated Show resolved Hide resolved
lib/src/revset.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
docs/revsets.md Outdated Show resolved Hide resolved
lib/tests/test_revset.rs Outdated Show resolved Hide resolved
@sullyj3
Copy link
Collaborator Author

sullyj3 commented Sep 6, 2023

Thanks for your PR. I think you can squash all 6 commits into one, per https://github.com/martinvonz/jj/blob/main/docs/contributing.md#code-reviews

I'm happy to squash, but on my reading contributing.md says not to! It might need updating if that's your preference, unless I'm misunderstanding.

@yuja
Copy link
Collaborator

yuja commented Sep 6, 2023

Thanks for your PR. I think you can squash all 6 commits into one, per https://github.com/martinvonz/jj/blob/main/docs/contributing.md#code-reviews

I'm happy to squash, but on my reading contributing.md says not to!

Perhaps "we don't squash them when the PR is ready" could be misinterpreted, but it means the PR isn't squashed when integrating, so it's up to contributor to organize commits in meaningful way.

I think the first RevsetExpression::ancestors() change can be a separate commit, but the other 5 commits do related code + test + doc changes separately, so they can be squashed into one.

@sullyj3
Copy link
Collaborator Author

sullyj3 commented Sep 6, 2023

Ahh, I see, that makes sense.

@sullyj3 sullyj3 marked this pull request as draft September 7, 2023 07:04
@sullyj3 sullyj3 force-pushed the main branch 4 times, most recently from 6cda4cf to 012822f Compare September 7, 2023 08:19
@sullyj3 sullyj3 marked this pull request as ready for review September 7, 2023 08:21
Copy link
Collaborator

@yuja yuja left a comment

Choose a reason for hiding this comment

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

I'm not sure whether exclusive depth is intuitive or not, but other than that, the change LGTM, thanks.

You'll probably need to cargo fmt the first commit.

lib/src/revset.rs Outdated Show resolved Hide resolved
@martinvonz
Copy link
Member

I'm not sure whether exclusive depth is intuitive or not, but other than that, the change LGTM, thanks.

I'm also not sure, but to be clear, I don't want that to block this PR. We can always change it later if necessary.

@sullyj3
Copy link
Collaborator Author

sullyj3 commented Sep 7, 2023

cargo fmt done!

@sullyj3 sullyj3 requested a review from martinvonz September 7, 2023 16:43
Copy link
Member

@martinvonz martinvonz left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@sullyj3 sullyj3 merged commit 0946934 into jj-vcs:main Sep 7, 2023
15 checks passed
@sullyj3
Copy link
Collaborator Author

sullyj3 commented Sep 7, 2023

Auspicious occasion, that was my first rust open source contribution. Thanks both for your help!

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