How devansh-rookie/jj works
Purpose and workspace layout
Jujutsu (jj) is a Rust command-line version-control system. It separates VCS semantics from physical storage; the production backend stores commits/files in Git while Jujutsu owns higher-level metadata such as bookmarks, operations, and workspace state. Cargo workspace roots are Cargo.toml, with the user executable in cli/ and reusable core in lib/.
CLI entry and command dispatch
The jj binary starts at cli/src/main.rs, with shared CLI initialization and public wiring in cli/src/lib.rs. Command registration/dispatch is centralized in cli/src/commands/mod.rs; individual command modules implement user workflows, including history rewriting (cli/src/commands/rebase.rs), Git interoperability (cli/src/commands/git/mod.rs), and operation recovery (cli/src/commands/operation/mod.rs).
CLI code is the boundary for argument parsing, configuration/UI, repository opening, working-copy lifecycle, and translating domain failures to terminal output.
Core repository model and transactions
The domain layer models commits, trees, refs/views, operations, repositories, and workspaces. Key ownership and mutation boundaries are lib/src/repo.rs, lib/src/transaction.rs, and lib/src/operation.rs. Commands mutate a transactional repository view, then record a new operation snapshot; this supports operation log, undo/restore, and safe state evolution rather than in-place untracked mutation.
Storage, Git interoperability, and metadata
Storage is abstracted behind backend/store interfaces in lib/src/backend.rs and lib/src/store.rs. The production Git implementation is lib/src/git_backend.rs, with Git integration and remote-oriented behavior in lib/src/git.rs. Git stores commit/file objects and enables ordinary Git remotes; Jujutsu-specific operation, workspace, and head metadata are persisted through separate stores such as lib/src/op_store.rs and lib/src/workspace_store.rs. Git is the material external service/protocol; gitoxide is identified by the README as the Git Rust library.
Working-copy snapshot boundary
Jujutsu treats the working copy as a commit. Filesystem-facing behavior is isolated in lib/src/working_copy.rs and the local implementation lib/src/local_working_copy.rs; CLI snapshot orchestration is in cli/src/commands/util/snapshot.rs. The normal control flow is: snapshot filesystem changes into the working-copy commit, execute a repository transaction, commit an operation, then update the filesystem if the working-copy commit changed. This centralization lets most commands operate on repository commits rather than directly manipulating dirty files.
Revision graph, rewriting, and conflicts
Commit selection and graph evaluation are handled by the revset language and index: lib/src/revset.rs, lib/src/revset_parser.rs, and lib/src/default_index/revset_engine.rs. History transformations—including descendant rebasing—are rooted in lib/src/rewrite.rs. Merge/conflict state is domain data rather than an interrupted command condition, implemented by lib/src/conflicts.rs, lib/src/merge.rs, and lib/src/tree_merge.rs; rewritten descendants can therefore retain or propagate resolvable conflicts.
Configuration, presentation, and extensibility
Layered configuration is resolved in lib/src/config_resolver.rs and surfaced by cli/src/config.rs; built-in defaults live under cli/src/config/. User-facing graph/log/diff output combines CLI formatting with templates, notably cli/src/graphlog.rs, cli/src/templater.rs, and cli/src/template_parser.rs. Extension seams are explicit in examples and interfaces for custom backends, commands, templaters, and working copies under cli/examples/.
Runtime and supporting infrastructure
Primary runtime is native Rust/Cargo on Unix and Windows, with platform-specific locking in lib/src/lock/unix.rs and lib/src/lock/windows.rs. Optional integrations include Watchman filesystem monitoring (lib/src/fsmonitor.rs), external merge/diff tools (cli/src/merge_tools/), GPG/SSH signing (lib/src/gpg_signing.rs, lib/src/ssh_signing.rs), and Gerrit upload (cli/src/commands/gerrit/upload.rs). Documentation is separately built as an Astro site under web/docs/; it is not part of the VCS runtime.
Main entry points: rebase.rs Command workflows · repo.rs Repository view · lib.rs CLI initialization · transaction.rs Repository transaction
Components 20
CLI runtime
User command boundary and presentation.
- jj binary
cli/src/main.rs - CLI initialization
cli/src/lib.rs - Command dispatch
cli/src/commands/mod.rs - Command workflows · Includes rebase, Git, and operation recovery commands.
cli/src/commands/rebase.rs
Repository domain
Transactional VCS semantics owned by Jujutsu.
- Repository view · Owns repository, refs, views, and workspace-facing state.
lib/src/repo.rs - Repository transaction · Stages repository changes before recording an operation.
lib/src/transaction.rs - Operation snapshots · Enables operation log, undo, and restore.
lib/src/operation.rs
Storage and Git
Object storage, metadata persistence, and Git interoperability.
- Store interfaces · Abstracts commit and tree object storage.
lib/src/store.rs - Backend interfaces
lib/src/backend.rs - Git backend · Stores commits and files as Git objects.
lib/src/git_backend.rs - Git integration · Supports Git interoperability and remotes through gitoxide.
lib/src/git.rs - Metadata stores · Persists operation, workspace, and head metadata separately from Git.
lib/src/op_store.rs
Working copy
Filesystem snapshot and update boundary.
- Snapshot orchestration · Coordinates pre-command snapshot and post-command update.
cli/src/commands/util/snapshot.rs - Working-copy interface
lib/src/working_copy.rs - Local working copy · Reads and updates the local filesystem.
lib/src/local_working_copy.rs
Revision and rewrite
Revision selection, graph changes, and conflict modeling.
- Revset evaluation · Parses and evaluates commit-selection expressions using the index.
lib/src/revset.rs - History rewriting · Rebases rewritten descendants and preserves graph evolution.
lib/src/rewrite.rs - Merge conflicts · Represents resolvable conflict state in commits and trees.
lib/src/conflicts.rs
Configuration and integrations
Cross-cutting configuration, presentation, and optional integrations.
- Layered configuration · Resolves configuration for CLI behavior and UI.
lib/src/config_resolver.rs - Graph, templates, and output · Renders logs, diffs, and terminal-facing results.
cli/src/graphlog.rs
Connections 22
- jj binary → CLI initialization: starts
- CLI initialization → Command dispatch: initializes
- Command dispatch → Command workflows: routes commands
- Command workflows → Snapshot orchestration: uses
- Snapshot orchestration → Local working copy: snapshots and updates
- Local working copy → Working-copy interface: implements
- Snapshot orchestration → Repository transaction: wraps mutation
- Command workflows → Repository view: opens and reads
- Command workflows → Revset evaluation: selects commits
- Command workflows → History rewriting: transforms history
- Repository transaction → Repository view: mutates view
- Repository transaction → Operation snapshots: commits snapshot
- Repository view → Store interfaces: uses
- Store interfaces → Backend interfaces: delegates objects
- Backend interfaces → Git backend: implemented by
- Git backend → Git integration: uses Git objects
- Operation snapshots → Metadata stores: persists
- Repository view → Metadata stores: loads state
- Revset evaluation → Repository view: evaluates repository graph
- History rewriting → Merge conflicts: propagates conflict state
- CLI initialization → Layered configuration: loads
- Command workflows → Graph, templates, and output: renders results