Skip to content

feat(jj): add Jujutsu VCS backend - #32

Merged
simonepri merged 1 commit into
mainfrom
feat/jj-vcs-backend
May 29, 2026
Merged

simonepri merged 1 commit into
mainfrom
feat/jj-vcs-backend

Conversation

@simonepri

@simonepri simonepri commented May 29, 2026 •

Copy link
Copy Markdown
Owner

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 diff doesn't reflect jj's working-copy-as-a-commit semantics, and pure-jj repos may not have git on PATH at all.

JjVcsProvider composes NoneVcsProvider (from #28/#30) and overrides diff() (via jj diff --git), suppressions() (via jj log), and search_string_in_files() (jj file list + parallel aho-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> --version probe surfaces a clear install hint when the chosen backend isn't on PATH.

@simonepri
simonepri force-pushed the feat/jj-vcs-backend branch 2 times, most recently from d4300da to 3bcac80 Compare May 29, 2026 11:38
## 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
simonepri force-pushed the feat/jj-vcs-backend branch from 3bcac80 to 20a32cb Compare May 29, 2026 11:39
@simonepri
simonepri merged commit 1a190d4 into main May 29, 2026
6 checks passed
@simonepri
simonepri deleted the feat/jj-vcs-backend branch May 29, 2026 12:14
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.

[Feature Request] Support path to diff file or via stdin

1 participant