jj / How jj debug works

How jj debug works

jj debug is a hidden group of low-level commands for inspecting jj's internals: the index, the stores, the working-copy state, and the parsers for revsets, filesets and templates.

On this page
  1. 1. Command-line surface
  2. 3. End-to-end flow
  3. 4. Core architecture touchpoints

In short: one clap enum, hidden from jj --help, dispatching to fifteen small commands. Each picks how much of jj to load. Most go through the normal workspace helper; the index commands and debug object load only the workspace, so they can run when the repo itself would not load.

The group is DebugCommand, help text "Low-level commands not intended for users", marked #[command(hide = true)] (source). It is the Debug variant of the top-level Command enum (source, dispatch), and cmd_debug matches on it.

1. Command-line surface

SubcommandHelp textLoads
copy-detection"Show information about file copies detected"workspace helper (source)
fileset"Parse fileset expression"workspace helper (source)
index"Show commit index stats"workspace only (source)
index-changed-paths"Build changed-path index"workspace helper (source)
init-simple"Create a new repo in the given directory using the proof-of-concept simple backend"nothing; creates a repo
local-working-copy"Show information about the local working copy state"workspace helper (source)
object (commit, file, operation, symlink, tree, view)"Show information about an operation and its view", the doc comment on the whole enumworkspace only, then the commit or op store (source)
reindex"Rebuild commit index"workspace only (source)
revset"Evaluate revset to full commit IDs"workspace helper (source)
snapshot"[DEPRECATED] Trigger a snapshot in the op log"; also hiddenworkspace helper (source)
stacked-table"Show stats of stacked table"nothing; opens the table store at DIR with key size -n (source)
template"Parse a template"nothing; parses and prints the AST (source)
tree"List the recursive entries of a tree."workspace helper (source)
watchman (status, query-clock, query-changed-files, reset-clock)none on the group; status: "Check whether watchman is enabled and whether it's correctly installed"workspace helper (source)
working-copy"Show information about the working copy state"workspace helper without snapshot (source)

The enum lists the variants in this order (source). The global flags are on the CLI page.

3. End-to-end flow

jj debug: dispatch and what each subcommand loads The top-level Command enum has a hidden Debug variant. cmd_debug matches the DebugCommand and calls one subcommand function. Most subcommands call the workspace helper, which loads the repo at head and snapshots the working copy. index, reindex and object call load_workspace and resolve the operation or read the stores directly, without loading the repo. local-working-copy and the watchman subcommands then call check_local_disk_wc, which fails for any other working-copy implementation. Command::Debug (hidden) #[command(subcommand)] cmd_debug match DebugCommand → cmd_debug_* most: workspace_helper repo at head, working copy snapshotted index, reindex, object: load_workspace repo_loader only; repo never loaded local-working-copy, watchman: check_local_disk_wc downcast to LocalWorkingCopy or fail index store / commit store / op store read or rebuild directly

4. Core architecture touchpoints

PieceRole here
Indexdebug reindex resolves the operation before loading the repo, "The index might have to be rebuilt while loading the repo", then calls reinit and build_index_at_operation on the default index store; any other index type is "Cannot reindex indexes of type '…'" (source, test). debug index prints its stats (test).
Commit store and op storedebug object reads a commit, file, symlink or tree from the store, or an operation or view from the op store, by ID (source).
Revsets, filesets, templatesdebug revset and fileset print each parser's intermediate forms; debug template prints the parsed template tree (source) (fileset test, revset test).
Working copycheck_local_disk_wc downcasts to LocalWorkingCopy, failing with "This command requires a standard local-disk working copy" (source); debug local-working-copy and the watchman queries call it (source, watchman). debug snapshot only warns that it is deprecated and calls the workspace helper, which snapshots; use jj util snapshot (source).
Build featuresdebug watchman fails with "Cannot query Watchman because jj was not compiled with the watchman feature" when that feature is off (source); it is on by default (source).