Skip to content

cli: run: add sparse patterns options - #9980

Draft
mirkomartn wants to merge 2 commits into
jj-vcs:mainfrom
mirkomartn:gs/run-sparse-patterns
Draft

cli: run: add sparse patterns options#9980
mirkomartn wants to merge 2 commits into
jj-vcs:mainfrom
mirkomartn:gs/run-sparse-patterns

Conversation

@mirkomartn

Copy link
Copy Markdown

This is a way to add sparse patterns to the run command. Current implementation is very simple if not crude, but I don't think the final version (if accepted) will differ substantially. I left a few comments with TBD items, probably best discussed inline.

I do want to emphasize one thing though, namely, that --remove pattern doesn't perform nearly as well as what should be an otherwise equivalent set of --clear and --add commands, and I'm not sure whether this is expected or not (didn't have time to dig into it yet, as I only run into it preparing the example below while opening this PR). Most likely, this is an error on my side, so please review with this in mind.

If there proves to be interest in the feature, I'll add tests and check off other items of the list.

I think this can really make a difference, for example (in short, having a 4GB file, jj run -- ls won't complete in under 10s, but now we can exclude the big file using a sparse pattern and then it do so instantly (not with --remove though)):

gasper@capablanca /tmp> jj git init foo && cd foo && touch haha hihi hoho hehe
Initialized repo in "foo"
gasper@capablanca /t/foo> dd if=/dev/zero of=chungus bs=1G count=4 && jj --config snapshot.max-new-file-size=4G st
4+0 records in
4+0 records out
4294967296 bytes transferred in 0.686670 secs (6254776379 bytes/sec)
Working copy changes:
A chungus
A haha
A hehe
A hihi
A hoho
Working copy  (@) : wstwunnx 47decb2c (no description set)
Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set)
gasper@capablanca /t/foo> gtimeout 10 jj run -- ls
gasper@capablanca /t/foo [124]> gtimeout 1 /Users/gasper/repos/jj/target/debug/jj run --remove chungus -- ls
gasper@capablanca /t/foo [124]> gtimeout 1 /Users/gasper/repos/jj/target/debug/jj run --clear --add haha --add hehe --add hihi --add hoho -- ls
haha
hehe
hihi
hoho
Nothing changed.
gasper@capablanca /t/foo> gtimeout 1 /Users/gasper/repos/jj/target/debug/jj run --clean -- ls
gasper@capablanca /t/foo [124]> gtimeout 1 /Users/gasper/repos/jj/target/debug/jj run --remove chungus -- ls
gasper@capablanca /t/foo [124]>

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/updated tests to cover my changes
  • I fully understand the code that I am submitting (what it does,
    how it works, how it's organized), including any code drafted by an LLM.
  • For any prose generated by an LLM, I have proof-read and copy-edited with
    an eye towards deleting anything that is irrelevant, clarifying anything
    that is confusing, and adding details that are relevant. This includes,
    for example, commit descriptions, PR descriptions, and code comments.

Expose SparseSetArgs so that it can be used
for exposing the same set of arguments for
sparse set subcommand as part of another
command as well.

It might be desirable to offer knobs for
setting sparse patterns as part of another
command (such as `run` or `workspace`).
@mirkomartn
mirkomartn requested a review from a team as a code owner August 13, 2026 13:46
This uses previously exposed sparse::SparseSetArgs
to add a familiar interface for setting sparse
patterns in the "workspace" in which the command
is run. This gives the user an option to forego
expensive materializations when unneeded.

For example, if a user only needs to run a command
only for two files `bar` and `foo`, they can now do
so with:

`jj run --clear --add bar --add foo -- <command>`
@mirkomartn
mirkomartn force-pushed the gs/run-sparse-patterns branch from 1cf3a5e to fba9130 Compare August 13, 2026 14:01
@mirkomartn

Copy link
Copy Markdown
Author

Re: --remove performing poorly, just two dbg! statements later I'm a bit wiser. It seems that the problem is that the pre-existing sparse patterns are empty, so --remove leaves it at that. This means, w.r.t. the example, running jj run --clear --add chungus first, I should then observe jj run --remove chungus taking the expected effect. I guess I should somehow populate the sparse patterns first, when the tree file is first created. I look into it soon.

@mirkomartn
mirkomartn marked this pull request as draft August 13, 2026 14:30
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.

1 participant