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

Use shorter ID prefixes in configured revset #1603

Merged
merged 14 commits into from
May 12, 2023
Merged

Conversation

martinvonz
Copy link
Member

Checklist

If applicable:

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

I plan to add `revsets.short-prefixes` and `revsets.immutable` soon,
and I think `[revsets]` seems like reasonable place to put them. It
seems consistent with our `[templates]` section. However, it also
suffers from the same problem as that section, which is that the
difference between `[templates]` and `[template-aliases]` is not
clear. We can decide about about templates and revsets later.
I'd like to make the symbol resolution more flexible, both so we can
support customizing it (in custom `jj` binaries) and so we can use it
for resolving short prefixes within a small revset.
@martinvonz martinvonz force-pushed the push-kkxkpzssqmnt branch 2 times, most recently from 3d835fc to fc64b78 Compare May 11, 2023 17:19
@PhilipMetzger
Copy link
Collaborator

SGTM, besides the typo in the last sentence of the sixth commit message I've update the templater to use it. which should be I've updated the templater to use it. I'll defer to @yuja for all revset related changes though.

I do have a question related to the fourth commit as it will impact my PR(#1200). Is there a good pattern for the default SymbolResolver usage?

@martinvonz martinvonz force-pushed the push-kkxkpzssqmnt branch from fc64b78 to 1d5984d Compare May 11, 2023 18:01
@martinvonz
Copy link
Member Author

I do have a question related to the fourth commit as it will impact my PR(#1200). Is there a good pattern for the default SymbolResolver usage?

I don't think it should impact your PR. Were you thinking that we'd implement jj prev 5 by resolving "5" as a revset symbol pointing that many commits back? I think it's better to just parse it as an integer.

@PhilipMetzger
Copy link
Collaborator

No I didn't use the revset symbols, although it could've worked.

But I restructured the PR to use RevsetExpressions recently, using this pattern:

// Similar to cmd_next, on my machine 
let helper = ...;
let current_wc_id = helper.get_wc_id()?;
let parent = current_wc_id.parents().pop();
let all_ancestors = RevsetExpression::ancestors(&parent);
//...

which will need to use the Resolver.

@martinvonz
Copy link
Member Author

No I didn't use the revset symbols, although it could've worked.

But I restructured the PR to use RevsetExpressions recently, using this pattern:

// Similar to cmd_next, on my machine 
let helper = ...;
let current_wc_id = helper.get_wc_id()?;
let parent = current_wc_id.parents().pop();
let all_ancestors = RevsetExpression::ancestors(&parent);
//...

which will need to use the Resolver.

Ah, I see. I think that should actually just use all_ancestors.resolve(&repo) (see the third commit in this series).

@PhilipMetzger
Copy link
Collaborator

Thanks for clearing my concerns.

CHANGELOG.md Show resolved Hide resolved
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.

Nice

lib/src/revset.rs Outdated Show resolved Hide resolved
src/cli_util.rs Show resolved Hide resolved
lib/src/revset.rs Outdated Show resolved Hide resolved
lib/src/id_prefix.rs Show resolved Hide resolved
lib/src/id_prefix.rs Outdated Show resolved Hide resolved
src/cli_util.rs Show resolved Hide resolved
lib/src/id_prefix.rs Outdated Show resolved Hide resolved
@martinvonz martinvonz force-pushed the push-kkxkpzssqmnt branch from 1d5984d to e983ba1 Compare May 12, 2023 05:15
martinvonz added 12 commits May 11, 2023 23:28
I would eventually want the `SymbolResolver` to be customizable (in
custom `jj` binaries), so we want to make sure we always use the
customized version of it.

I left `RevsetExpression::resolve()` unchanged. I consider that to be
for programmatically created expressions.
When creating `RevsetExpression` programmatically, I think we should
use commit ids instead of symbols in the expression. This commit adds
a check for that by using a `SymbolResolver` that always errors
out.
I want to store some lazily calculated data associated with a
repo. The data will depend on the user's config, which means it
shouldn't live in the `ReadonlyRepo` itself. We could store it
directly in `WorkspaceCommandHelper` - and I did that at first - but
it's annoying and risky to remember to reset the cached data when we
update the repo instance (which we do when a transaction
finishes). This commit therefore introduces a wrapper type where we
can store it. Having a wrapper also means that we can use `OnceCell`
instead of more manually initializing it with a `RefCell`.
I would like to copy Mercurial's way of abbreviating ids within a
user-configurable revset. We would do it for both commit ids and
change ids. For that feature, we need a place to keep the set of
commits the revset evaluates to. This commit adds a new
`IdPrefixContext` type which will eventually be that place. The new
type has functions for going back and forth between full and
abbreviated ids. I've updated the templater to use it.
This prepares for adding callbacks to resolve these ids.
This is another step towards resolving abbreviated commit ids within a
configured revset.
I'll use this in `IdPrefixContext` soon.
For the support for shorter prefixes within a revset, we'll want to be
able to check if an id is in the index.
In large repos, the unique prefixes can get somewhat long (~6 hex
digits seems typical in the Linux repo), which makes them less useful
for manually entering on the CLI. The user typically cares most about
a small set of commits, so it would be nice to give shorter unique ids
to those. That's what Mercurial enables with its
`experimental.revisions.disambiguatewithin` config. This commit
provides an implementation of that feature in `IdPrefixContext`.

In very large repos, it can also be slow to calculate the unique
prefixes, especially if it involves a request to a server. This
feature becomes much more important in such repos.
This adds a config called `revsets.short-prefixes`, which lets the
user specify a revset in which to disambiguate otherwise ambiguous
change/commit ids. It defaults to the value of `revsets.log`.


I made it so you can disable the feature by setting
`revsets.short-prefixes = ""`. I don't like that the default value
(using `revsets.log`) cannot be configured explicitly by the
user. That will be addressed if we decide to merge the `[revsets]` and
`[revset-aliases]` sections some day.
By passing the repo as argument to the methods instead, we can remove
the `repo` field and the associated lifetime. Thanks to Yuya for the
suggestion.
@martinvonz martinvonz force-pushed the push-kkxkpzssqmnt branch from 26474ba to 6bfee4a Compare May 12, 2023 06:29
@martinvonz martinvonz enabled auto-merge (rebase) May 12, 2023 06:30
@martinvonz martinvonz merged commit 916b00c into main May 12, 2023
@martinvonz martinvonz deleted the push-kkxkpzssqmnt branch May 12, 2023 06:41
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.

4 participants