Repository navigation
feat(jj): add Jujutsu VCS backend - #32
Merged
Merged
Conversation
simonepri
force-pushed
the
feat/jj-vcs-backend
branch
2 times, most recently
from
May 29, 2026 11:38
d4300da to
3bcac80
Compare
## Problem Issue #18: jj users get incorrect or unusable results because the tool only supported git. `git diff` doesn't reflect jj's view of the world (working-copy-as-a-commit semantics, different revset syntax), and in pure-jj repos `git` isn't on PATH at all. The earlier "supporting raw patch input goes against the backend-agnostic logic" reasoning still holds — the right fix is a proper jj backend, not an external diff source. ## Solution ### New backend: `JjVcsProvider` `src/vcs_jj.rs` composes `NoneVcsProvider` the same way `GitVcsProvider` does, overriding the three VCS-dependent trait methods: - `diff()` → `jj diff --git -r <revset>`, parsed through `udiff`. - `suppressions()` → `jj log --no-graph -T 'description ++ "\n"' -r <revset>`, scanned for `NO_IFTTT=`. - `search_string_in_files()` → enumerate via `jj file list`, then parallel `aho-corasick` scan with `rayon`. Two automata (needle + filter) so `MatchKind::Standard`'s non-overlapping advance doesn't swallow filter patterns sharing a prefix with the needle. Probe-first read via a new `read_text_or_skip` helper bounds peak memory under parallel walks: a multi-gigabyte binary blob never gets fully read. Binary detection matches `NoneVcsProvider::read_file` (NUL byte or invalid UTF-8 in the first 8 KB). Symlinks are skipped to mirror `git grep`'s non-following behavior. No `git grep` or `ripgrep` runtime dep. The `read_file` / `file_exists` / `try_resolve_path` / `is_strict` / `validate_files` methods delegate to the inner `NoneVcsProvider`. ### Shared helpers - `aho-corasick` promoted from transitive (via `globset`/`regex`) to direct dep so its use in the search path is explicit. - `udiff` promoted from `#[path]` submodule of `vcs_git` to a top-level `pub(crate) mod udiff` so both backends can share one instance (avoids `clippy::duplicate_mod`). - `strip_git_prefix` renamed to `strip_diff_prefix` and moved into `udiff.rs` — the `a/`/`b/` prefix is a unified-diff convention shared by `git diff --git` and `jj diff --git`, not git-specific in itself. - `absolute_path`, `is_glob_pattern`, `normalize_input_path`, `normalize_repo_relative_path`, and `is_symlink` moved into `vcs_none.rs` as `pub(crate)` free items — `NoneVcsProvider` is the shared base, so these naturally live with it. ### CLI - `--vcs <git|jj>` flag with auto-detection: walks ancestors of cwd looking for `.jj/` (jj backend) or `.git/` (git backend); `.jj/` wins per-ancestor so colocated jj-on-git repos pick jj by default. - Eager binary-availability probe (`<bin> --version`) at startup for both backends with install-hint errors when missing. Makes the implicit "git is on PATH" assumption explicit alongside adding jj. - `check::check` takes `&dyn VcsProvider` already; the CLI now hands it a `Box<dyn VcsProvider>` so either backend plugs in identically. ### Tests 13 new tests: - 9 in `vcs_jj_test.rs` mirroring the git backend's coverage: search with filter, binary skip, symlink skip, diff with explicit revset, diff symlink filter, suppressions (parametrized), glob expansion via `jj file list`. - 4 in `cli_test.rs`: explicit `--vcs jj` diff with co-change violation, auto-detection from `.jj/` exercising the diff path (forces a revset only jj can resolve so misrouting fails the test), explicit `--vcs git` wiring, error path for `--vcs jj` outside a workspace. Missing `jj` panics with `expect("jj must be available; run mise install")` — mirrors how the git tests treat git. `mise.toml` provisions `jujutsu`; CI runs `mise install` already. ### Docs Readme gets a "Supported backends" section, the `--vcs` flag is documented in the CLI reference, the FAQ entry for non-git VCS now points to the new section.
simonepri
force-pushed
the
feat/jj-vcs-backend
branch
from
May 29, 2026 11:39
3bcac80 to
20a32cb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #18.
Add a first-class Jujutsu (jj) backend so users in jj or jj-on-git colocated repos get correct diff/suppression/search results.
git diffdoesn't reflect jj's working-copy-as-a-commit semantics, and pure-jj repos may not havegiton PATH at all.JjVcsProvidercomposesNoneVcsProvider(from #28/#30) and overridesdiff()(viajj diff --git),suppressions()(viajj log), andsearch_string_in_files()(jj file list+ parallelaho-corasick). New--vcs <git|jj>flag auto-detects by walking ancestors for.jj/(wins) or.git/, so colocated repos pick jj by default; an eager<bin> --versionprobe surfaces a clear install hint when the chosen backend isn't on PATH.