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

cli: diff: add fileset-alias option #4962

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bryceberger
Copy link

@bryceberger bryceberger commented Nov 24, 2024

Following discussion in #4961.

The original problem was wanting to hide paths from the diff view. I failed to read the docs and realize that ~patterns are available, and already solve that.

However, there are a few ergonomic issues with this:

  • ~... may be interpreted by the shell, so the excluded paths should be quoted
  • Some paths are common to ignore, and annoying to type repeatedly (Cargo.lock, etc)
  • Path is even longer if you're not at the root of the repository (~root-file:Cargo.lock)

The template system provides a nice solution for frequently used commands. It would be nice if there was a similar system for filesets.

Example

[fileset-aliases]
no-lock = "~root-glob:*.lock"
jj diff -P no-lock

Open questions:

  • Should combining aliases and user-provided paths be allowed?
  • Better name / abbreviation? -P was chosen from "P"ath, but I'm not attached to it.

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)

@yuja
Copy link
Collaborator

yuja commented Nov 24, 2024

The fileset-aliases idea is to substitute parsed tree of fileset (or path) expression. You can see how this is implemented in cli/src/template_parser.rs and lib/src/revset.rs. (It's a bit odd that alias substitution isn't made in revset_parser.rs, but that's just for a historical reason.) We'll need to write some plumbing code.

@bryceberger
Copy link
Author

Ah, so to have something like jj diff no_lock directly use the no_lock alias? In that case, what would happen if the user wants to interact with a file whose name is shadowed by an alias?

@martinvonz
Copy link
Member

Ah, so to have something like jj diff no_lock directly use the no_lock alias? In that case, what would happen if the user wants to interact with a file whose name is shadowed by an alias?

Then they would probably have to escape it with e.g. cwd:no_lock

@bryceberger
Copy link
Author

bryceberger commented Nov 24, 2024

Copied implementations from fileset_parser.rs until it worked. The implementation in 6b1e2d3 adds a dsl_util::expand_aliases() step to fileset::parse().

Since this tries to expands all ExpressionKind::Identifier, jj diff <path> no longer always matches <path>, depending on user configuration. Workarounds:

  • Quote the path: jj diff '"path"' (double quoted because of shell expansions. This makes an ExpressionKind::String instead of ExpressionKind::Identifier, which is not expanded.)
  • Add a file pattern: jj diff file:path

@yuja
Copy link
Collaborator

yuja commented Nov 25, 2024

Since this tries to expands all ExpressionKind::Identifier, jj diff <path> no longer always matches <path>, depending on user configuration. Workarounds:

Correct. It's up to user to choose sane alias symbols such as NO_LOCK (assuming file names are usually lower case), no_lock() (function call), etc.

The change generally looks good to me, thanks.

lib/src/fileset.pest Outdated Show resolved Hide resolved
lib/src/revset.rs Outdated Show resolved Hide resolved
@bryceberger bryceberger force-pushed the fileset-alias branch 2 times, most recently from 6e0f91d to dac4b19 Compare November 26, 2024 22:55
@bryceberger
Copy link
Author

Implementation (of non-function) aliases should be completed, feel free to review under that assumption.

Todo:

  • docs
  • tests

cli/src/cli_util.rs Outdated Show resolved Hide resolved
lib/src/fileset.rs Outdated Show resolved Hide resolved
@bryceberger bryceberger force-pushed the fileset-alias branch 2 times, most recently from c293f52 to 91f6e9d Compare November 28, 2024 19:09
@bryceberger bryceberger marked this pull request as ready for review November 28, 2024 19:09
Additionally, adds alias handling to cli_util.

The implementation is mostly copied from the similar parts in
cli/template_parser.
This propogates `[fileset-aliases]` to everywhere they're used. Chiefly,
they need to be accessible inside of expressions like:

    jj log -T 'self.diff("...").summary()'
    jj log -r 'diff_contains("words", "...")'
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