Debian Codegraph @

docs/contributing.md

raw
1 # How to Contribute
2
3 ## Policies
4
5 We'd love to accept your patches and contributions to this project. There are
6 just a few small guidelines you need to follow.
7
8 ### Contributor License Agreement
9
10 Contributions to this project must be accompanied by a Contributor License
11 Agreement. You (or your employer) retain the copyright to your contribution;
12 this simply gives us permission to use and redistribute your contributions as
13 part of the project. Head over to <https://cla.developers.google.com/> to see
14 whether you have already signed the CLA or to sign it.
15
16 You generally only need to submit a CLA once, so if you've already submitted one
17 (even if it was for a different project), you probably don't need to do it
18 again. In other words, the Google CLA is not scoped to a specific project. If
19 you sign the Google CLA, it applies to other Google open-source projects as
20 well (including future projects).
21
22 ### Commit guidelines
23
24 Unlike many GitHub projects (but like many VCS projects), we care more about the
25 contents of commits than about the contents of PRs. We review each commit
26 separately, and we don't squash-merge the PR (so please manually squash any
27 fixup commits before sending for review).
28
29 Each commit should ideally do one thing. For example, if you need to refactor a
30 function in order to add a new feature cleanly, put the refactoring in one
31 commit and the new feature in a different commit. If the refactoring itself
32 consists of many parts, try to separate out those into separate commits. You can
33 use `jj split` to do it if you didn't realize ahead of time how it should be
34 split up. Include tests and documentation in the same commit as the code they
35 test and document.
36
37 The commit message should describe the changes in the commit;
38 the PR description can even be empty, but feel free to include a personal
39 message. We don't use [Conventional Commits] and instead start the commit
40 message with `<topic>: ` rather than like `chore: `, `feat: ` and `fix: `.
41 This means if you modified a command in the CLI, use its name as the topic, e.g.
42 `next/prev: <your-modification>` or `conflicts: <your-modification>`. We don't
43 currently have a specific guidelines on what to write in the topic field, but
44 the reviewers will help you provide a topic if you have difficulties choosing
45 it. [How to Write a Git Commit Message] is a good
46 guide if you're new to writing good commit messages. We are not particularly
47 strict about the style, but please do explain the reason for the change unless
48 it's obvious. If the PR closes an open issue or feature request for the
49 project, include the `Closes #<issue-number>` or `Fixes #<issue-number>` in
50 the commit description.
51
52 If you have been invited to the `jj-vcs/` organization feel free to create
53 branches directly in the repo, ideally prefixed by your name or username. This
54 allows other people to directly check out your work and possibly integrate them
55 in their custom builds of jj.
56
57 [Conventional Commits]: https://www.conventionalcommits.org/en/v1.0.0/
58 [How to Write a Git Commit Message]: https://cbea.ms/git-commit/
59
60 ### Code reviews
61
62 All submissions, including submissions by project members, require review. We
63 use GitHub pull requests for this purpose. Consult
64 [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
65 information on using pull requests.
66
67 The project unfortunately has a shortage of reviewers (a common problem in
68 open-source projects). To maximize the chances of getting a timely review, do
69 what you can to provide reviewers (and other future readers) with the necessary
70 context. For example, if you're adding a new feature, explain why that feature
71 is useful, how it works from the user's point of view, how it's designed, and
72 what the limitations of your design are. If you have considered other designs,
73 it may be useful to mention them. Another way of speeding up reviews is to
74 review others' PRs so the maintainers don't need to spend as much time on them.
75
76 When you address comments on a PR, don't make the changes in a commit on top (as
77 is typical on GitHub). Instead, please make the changes in the appropriate
78 commit. You can do that by creating a new commit on top of the initial commit
79 (`jj new <commit>`) and then squash in the changes when you're done (`jj squash`).
80 `jj git push`
81 will automatically force-push the bookmark.
82
83 Mark conversation threads as resolved when you have addressed them. If you
84 realize that a comment requires non-trivial changes, write a reply instead and
85 ask your reviewer to take another look after updating the code.
86
87 When your first PR has been approved, we typically invite you to the
88 `jj-vcs/contributors` team to give you contributor access,
89 so you can address any remaining minor comments and then merge the PR yourself
90 when you're ready.
91
92 If your employer pays anyone (not necessarily you) to contribute to Jujutsu,
93 please make sure your GitHub username is [recorded](paid_contributors.md).
94 To avoid conflicts of interest, please don't merge a PR that has only been
95 approved by someone from the same organization. Similarly, as a reviewer, there
96 is no need to approve your coworkers' PRs, since the author should await an
97 approval from someone else anyway. It is of course still appreciated if you
98 review and comment on their PRs. Also, if the PR seems completely unrelated to
99 your company's interests, do feel free to approve it.
100
101 ### Community Guidelines
102
103 This project follows [Google's Open Source Community
104 Guidelines](https://opensource.google/conduct/).
105
106 ### Deprecations and Removals
107
108 If your PR removes or renames an option, a command, or config option don't
109 remove it immediately. Instead implement a warning that the command, command
110 option, or config option is deprecated and will be removed in
111 jj `v<current> + 6`. Also add a `// TODO: remove in jj<version+6>+` comment so
112 other contributors can remove it later. As we currently release monthly this
113 translates to a six month deprecation period. This is something the project
114 does to not break workflows and gives users the the option to
115 provide feedback on features we plan to remove or supersede with other
116 approaches.
117
118 Changes to the repo format (everything which is in `.jj/`) are more disruptive.
119 We aim to be backwards-compatible for at least a year (12 releases). Also
120 consider if it's worth being forwards-compatible (i.e making sure that the last
121 N versions of `jj` can read the new format). Examples of such changes are moving
122 repo-level configuration out of the repository or deriving the evolog from the
123 op-log.
124
125 Some things are required to be supported for even longer but that is in the end
126 a maintainer decision. Some examples of this were the `jj checkout/merge`
127 commands (removed after 24 months/releases) or the `--destination` flag for
128 which there is no final removal date yet.
129
130 ## Contributing large patches
131
132 We welcome contributions from anyone.
133
134 If you wish to contribute a new large feature, you are encouraged to discuss
135 it in Discord or a GitHub Discussion first before diving in. Before spending
136 too much time on a particular design, you should see if the community and the
137 maintainers have any feedback on your idea and general approach. It also is a
138 better experience for you as an author if you contributed smaller patches
139 first, so you understand how the project and the community around it works.
140
141 If you open a pull request without discussion first, you may find that the
142 community already has discussed this and found a better approach, or that it
143 already was deemed not to be a fit for the project.
144
145 Since many ideas have come up before, but they haven't been implemented because
146 they might be deceptively nuanced, or there may be strong opinions around them,
147 bringing it up to the community first helps discover past discussions, so your
148 design can be informed by them.
149
150 Once you have vetted your idea with the community, please write a
151 [Design Doc](design_docs.md) which requires an architecture review from
152 multiple stakeholders, see the [process here](design_docs.md#process).
153
154 ## Contributing to the documentation
155
156 We appreciate [bug
157 reports](https://github.com/jj-vcs/jj/issues/new?template=bug_report.md)
158 about any problems, however small, lurking in [our documentation
159 website](https://docs.jj-vcs.dev/prerelease) or in the `jj help
160 <command>` docs. If a part of the bug report template does not apply, you can
161 just delete it.
162
163 Before reporting a problem with the documentation website, we'd appreciate it if
164 you could check that the problem still exists in the "prerelease" version of the
165 documentation (as opposed to the docs for one of the released versions of `jj`).
166 You can use the version switcher in the top-left of the website to do so.
167
168 If you are willing to make a PR fixing a documentation problem, even better!
169
170 The documentation website sources are Markdown files located in the [`docs/`
171 directory](https://github.com/jj-vcs/jj/tree/main/docs). You do not need to
172 know Rust to work with them. See below for [instructions on how to preview the
173 HTML docs](#previewing-the-html-documentation) as you edit the Markdown files.
174 Doing so is optional, but recommended.
175
176 The `jj help` docs are sourced from the "docstring" comments inside the Rust
177 sources, currently from the [`cli/src/commands`
178 directory](https://github.com/jj-vcs/jj/tree/main/cli/src/commands). Working
179 on them requires setting up a Rust development environment, as described
180 below, and may occasionally require adjusting a test.
181
182 ## Learning Rust
183
184 In addition to the [Rust Book](https://doc.rust-lang.org/book/) and the other
185 excellent resources at <https://www.rust-lang.org/learn>, we recommend the
186 ["Comprehensive Rust" mini-course](https://google.github.io/comprehensive-rust/)
187 for an overview, especially if you are familiar with C++.
188
189 ## Style guide
190
191 See [here](style_guide.md).
192
193 ## Setting up a development environment
194
195 To develop `jj`, the mandatory steps are simply
196 to [install Rust](https://www.rust-lang.org/tools/install) (the default
197 installer options are fine), clone the repository, and use `cargo build`
198 , `cargo fmt`,
199 `cargo clippy --workspace --all-targets`, and
200 `cargo test --workspace`. If you are preparing a PR, there are some additional
201 recommended steps.
202
203 ### Summary
204
205 One-time setup:
206
207 rustup toolchain add nightly # wanted for 'rustfmt'
208 rustup toolchain add 1.89 # also specified in Cargo.toml
209 cargo install --locked bacon
210 cargo install --locked cargo-insta
211 cargo install --locked cargo-nextest
212
213 During development (adapt according to your preference):
214
215 bacon clippy-all
216 cargo +nightly fmt # Occasionally
217 cargo nextest run --workspace # Occasionally
218 cargo insta test --workspace --test-runner nextest # Occasionally
219
220 !!! warning
221
222 Build artifacts from debug builds and especially from repeated
223 invocations of `cargo test` can quickly take up 10s of GB of disk space.
224 Cargo will happily use up your entire hard drive. If this happens, run
225 `cargo clean`.
226
227 ### Explanation
228
229 These are listed roughly in order of decreasing importance.
230
231 1. Nearly any change to `jj`'s CLI will require writing or updating snapshot
232 tests that use the [`insta`](https://insta.rs/) crate. To make this
233 convenient, install the `cargo-insta` binary.
234 Use `cargo insta test --workspace` to run tests,
235 and `cargo insta review --workspace` to update the snapshot tests.
236 The `--workspace` flag is needed to run the tests on all crates; by default,
237 only the crate in the current directory is tested.
238
239 2. GitHub CI checks require that the code is formatted with the *nightly*
240 version of `rustfmt`. To do this on your computer, install the nightly
241 toolchain and use `cargo +nightly fmt`.
242
243 3. Your code will be rejected if it cannot be compiled with the minimal
244 supported version of Rust ("MSRV"). Currently, `jj` follows a rather
245 casual MSRV policy: "The current `rustc` stable version, minus one."
246 As of this writing, that version is **1.89.0**.
247
248 4. Your code needs to pass `cargo clippy`. You can also
249 use `cargo +nightly clippy` if you wish to see more warnings.
250
251 5. You may also want to install and use [`bacon`](https://dystroy.org/bacon/),
252 to automatically build, check, and / or run tests.
253
254 6. To run tests more quickly, use `cargo nextest run --workspace`. To
255 use `nextest` with `insta`, use `cargo insta test --workspace
256 --test-runner nextest`.
257
258 On Linux, you may be able to speed up `nextest` even further by using
259 the `mold` linker, as explained below.
260
261 ### Configuring `jj fix` to run `rustfmt`
262
263 Run this in the jj repo:
264
265 ```shell
266 jj config set --repo fix.tools.rustfmt '{ command = ["rustfmt", "+nightly"], patterns = ["glob:**/*.rs"] }'
267 ```
268
269 > Note: users of Nix and `direnv` should drop the `"+nightly"` argument above
270 > since the devShell is already configured to pull in a nightly version of
271 > rustfmt:
272 >
273 > ```shell
274 > jj config set --repo fix.tools.rustfmt '{ command = ["rustfmt"], patterns = ["glob:**/*.rs"] }'
275 > ```
276
277 ### Using `mold` for faster tests on Linux
278
279 On a machine with a multi-core CPU, one way to speed up
280 `cargo nextest` on Linux is to use the multi-threaded [`mold`
281 linker](https://github.com/rui314/mold). This linker may help
282 if, currently, your CPU is underused while Rust is linking test
283 binaries. Before proceeding with `mold`, you can check whether this is
284 an issue worth solving using a system monitoring tool such as `htop`.
285
286 `mold` is packaged for many distributions. On Debian, for example,
287 `sudo apt install mold` should just work.
288
289 A simple way to use `mold` is via the `-run` option, e.g.:
290
291 ```shell
292 mold -run cargo insta test --workspace --test-runner nextest
293 ```
294
295 There will be no indication that a different linker is used, except for
296 higher CPU usage while linking and, hopefully, faster completion. You
297 can verify that `mold` was indeed used by running
298 `readelf -p .comment target/debug/jj`.
299
300 There are also ways of having Rust use `mold` by default, see the ["How
301 to use" instructions](https://github.com/rui314/mold#how-to-use).
302
303 On recent versions of MacOS, the default linker Rust uses is already
304 multi-threaded. It should use all the CPU cores without any configuration.
305
306 ### Set up a RAM disk for faster tests on macOS
307
308 `jj` tests can be sped up significantly on macOS by using a RAM disk instead of
309 the usual `/tmp` directory (on one Mac, the tests sped up ~3 times from 180
310 seconds to 55 seconds). You can set this up as follows:
311
312 ```sh
313 sudo mkdir -p /Volumes/RAMDisk
314 sudo chmod a+wx /Volumes/RAMDisk
315 sudo mount_tmpfs /Volumes/RAMDisk # Add `-e` to make it case-sensitive
316 # Add `-o nobrowse` to hide the tmpfs from Finder
317 ```
318
319 You will need to re-run this after a reboot. Consider making it a script you can
320 run with `sudo`. (The first two commands don't need sudo if you change the dir
321 to somewhere in your HOME, the last one always does.)
322
323 Then, you can rust tests as, for example,
324
325 ```sh
326 TMPDIR=/Volumes/RAMDisk cargo insta test --workspace --test-runner nextest
327 ```
328
329 You can double-check whether or not the RAM disk is mounted with
330
331 ```sh
332 mount | grep tmpfs
333 ```
334
335 <details> <summary> Some details and speculation </summary>
336
337 <!-- MkDocs doesn't support Markdown markup inside `details` :( -->
338
339 Hard drive speed is not the issue here. Experimentally, when <code>/tmp</code>
340 is physical, Ilya experienced the tests doing writes at 60MB/s (as reported by
341 the Activity Monitor) on an SSD that should be many times as fast.
342
343 Instead, it seems to have something to do with file locking and
344 <code>fdatasync</code>. A likely curlprit is the presence of <a
345 href="https://gregoryszorc.com/blog/2018/10/29/global-kernel-locks-in-apfs/">
346 global kernel locks in APFS</a>. There are some benchmarks in
347 <a href="https://github.com/jj-vcs/jj/pull/7493#issuecomment-3289020874">this
348 PR</a>.
349
350 It might be possible to add an entry to `/etc/fstab` to mount tmpfs
351 automatically. If you succeed with this, let us (and Ilya in particular) know!
352
353 </details>
354
355 ### Editor setup
356
357 #### Visual Studio Code
358
359 We recommend at least these settings:
360
361 ```js
362 {
363 "files.insertFinalNewline": true,
364 "files.trimTrailingWhitespace": true,
365 "[rust]": {
366 "files.trimTrailingWhitespace": false
367 }
368 }
369 ```
370
371 #### Zed
372
373 ```js
374 // .zed/settings.json
375 {
376 "ensure_final_newline_on_save": true,
377 "remove_trailing_whitespace_on_save": true,
378
379 "languages": {
380 // We don't use a formatter for Markdown files, so format_on_save would just
381 // mess with others' docs
382 "Markdown": { "format_on_save": "off" }
383 "Rust": {
384 "format_on_save": "on",
385 // Avoid removing trailing spaces within multi-line string literals
386 "remove_trailing_whitespace_on_save": false
387 }
388 },
389
390 "lsp": {
391 "rust-analyzer": {
392 "initialization_options": {
393 // If you are working on docs and don't need `cargo check`, uncomment
394 // this option:
395 //
396 // "checkOnSave": false,
397
398 // Use nightly `rustfmt`, equivalent to `cargo +nightly fmt`
399 "rustfmt": { "extraArgs": ["+nightly"] }
400 }
401 }
402 }
403 }
404 ```
405
406 #### Helix
407
408 ```toml
409 # .helix/languages.toml
410 [language-server.rust-analyzer.config.rustfmt]
411 extraArgs = ["+nightly"]
412 ```
413
414 ### Alternative development setup with Nix
415
416 If you have [Nix](https://nixos.org/) installed, you can use the provided
417 `flake.nix` to get a development environment with all necessary tools
418 pre-configured:
419
420 ```shell
421 nix develop
422 ```
423
424 Once inside the shell, you can run `cargo build`, `cargo test` etc. as usual.
425 Other tools like `uv`, `cargo-insta`, `cargo-nextest` and more are installed,
426 and so you should be able to follow any other recommendations in this guide as
427 needed.
428
429 !!! tip "Editor integration"
430
431 Launch your editor from within the `nix develop` shell so that
432 rust-analyzer and other LSP tools can find the correct toolchain. For
433 example:
434
435 ```shell
436 nix develop
437 code . # or your editor of choice
438 ```
439
440 !!! note "direnv users"
441
442 If you use [direnv](https://direnv.net/) with
443 [nix-direnv](https://github.com/nix-community/nix-direnv), you can `echo
444 "source_env .envrc.recommended" >> .envrc` to automatically activate the
445 development environment when entering the directory.
446
447 ### Alternative development setup with `mise`
448
449 An experimental development setup is available using
450 [`mise`](https://mise.jdx.dev/). If you try it, file bugs,
451 PRs, or tell us on Discord/IRC/discussions if you experience problems
452 or if this config is too inflexible. If we can make it work for most
453 platforms and most people's needs, including people previously unfamiliar
454 with `mise`, we may make `mise` the recommended way to set up a development
455 environment.
456
457 This tool manages the necessary dependencies for you, eliminating the need for
458 a separate setup process. `mise` automatically installs the required tools when
459 they are needed.
460
461 Here are some of the commands you may find yourself using frequently during
462 development:
463
464 * `mise test`: Runs all tests.
465 * `mise test <string>`: Runs tests that contain a specific string. For
466 example, `mise test squash` would run tests with "squash" in their name.
467 * `mise build`: Compiles `jj`.
468 * `mise build:release`: Compiles `jj` in release mode.
469 * `mise build:docs`: Builds the documentation for `jj`.
470
471 For a complete list of all available tasks, you can run `mise tasks` or review
472 the configuration file at `.config/mise.toml`.
473
474 You can customize this configuration using
475 [a `mise.local.toml` file](https://mise.jdx.dev/configuration.html#mise-toml).
476
477 ## Previewing the HTML documentation
478
479 The documentation for `jj` is automatically published online at
480 <https://docs.jj-vcs.dev/>.
481
482 When editing documentation, you should check your changes locally — especially
483 if you are adding a new page, or doing a major rewrite.
484
485 ### Install `uv`
486
487 The only thing you need is [`uv`][uv] (version 0.5.1 or newer).
488
489 `uv` is a Python project manager written in Rust. It will fetch the right Python
490 version and the dependencies needed to build the docs. Install it like so:
491
492 [uv]: https://docs.astral.sh/uv/
493
494 === "macOS/Linux"
495
496 ```shell
497 curl -LsSf https://astral.sh/uv/install.sh | sh
498 ```
499
500 !!! note
501 If you don't have `~/.local/bin` in your `PATH`, the installer will
502 modify your shell profile. To avoid it:
503
504 ```shell
505 curl -LsSf https://astral.sh/uv/install.sh | env INSTALLER_NO_MODIFY_PATH=1 sh
506 ```
507
508 === "Windows"
509
510 ```shell
511 powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
512 ```
513
514 === "Homebrew"
515
516 ```shell
517 brew install uv
518 ```
519
520 === "Cargo"
521
522 ```shell
523 # This might take a while
524 cargo install --git https://github.com/astral-sh/uv uv
525 ```
526
527 === "Other options"
528
529 * Directly download the binaries from GitHub: [uv releases](https://github.com/astral-sh/uv/releases).
530 * Even more options: [Installing uv](https://docs.astral.sh/uv/getting-started/installation/).
531
532 ### Build the docs
533
534 To build the docs, run while inside the `jj` repository:
535
536 ```shell
537 uv run mkdocs serve
538 ```
539
540 Open <http://127.0.0.1:8000> in your browser to see the docs.
541
542 As you edit the `.md` files in `docs/`, the website should be rebuilt and
543 reloaded in your browser automatically.
544
545 !!! note "If the docs are not updating"
546 Check the terminal from which you ran `uv run mkdocs serve` for any build
547 errors or warnings. Warnings about `"GET /versions.json HTTP/1.1" code 404`
548 are expected and harmless.
549
550 #### Offline distribution
551
552 To build the rendered docs for offline distribution or to view them from your file
553 system, run while inside the `jj` repository:
554
555 ```shell
556 MKDOCS_OFFLINE=true uv run mkdocs build
557 ```
558
559 ## Building the entire website
560
561 !!! tip
562 Building the entire website is not usually necessary. If you are editing
563 documentation, the previous section is enough.
564
565 These instructions are relevant if you are working on the versioning of the
566 documentation that we currently do with `mike`.
567
568 The full `jj` website includes the documentation for several `jj` versions
569 (`prerelease`, latest release, and the older releases). The top-level
570 URL <https://docs.jj-vcs.dev> redirects to
571 <https://docs.jj-vcs.dev/latest>, which in turn redirects to
572 the docs for the last stable version.
573
574 The different versions of documentation are managed and deployed with
575 [`mike`](https://github.com/jimporter/mike), which can be run with
576 `uv run mike`.
577
578 On a POSIX system or WSL, one way to build the entire website is as follows (on
579 Windows, you'll need to understand and adapt the shell script):
580
581 1. Check out `jj` (`jj git clone`), cloned from your fork of `jj` (e.g.
582 `github.com/jjfan/jj`). You can also use a pure Git repo if you prefer.
583
584 2. Make sure `github.com/jjfan/jj` includes the `gh-pages` bookmark of the jj repo
585 and run `git fetch origin gh-pages`.
586
587 3. Go to the GitHub repository settings, enable GitHub Pages, and configure them
588 to use the `gh-pages` bookmark (this is usually the default).
589
590 4. Install `uv` as explained in [Previewing the HTML
591 documentation](#previewing-the-html-documentation), and run the same `sh` script
592 that is used in GitHub CI (details below):
593
594 ```shell
595 .github/scripts/docs-build-deploy prerelease main --push
596 ```
597
598 This should build the version of the docs from the current commit,
599 deploy it as a new commit to the `gh-pages` bookmark,
600 and push the `gh-pages` bookmark to the origin.
601
602 5. Now, you should be able to see the full website, including your latest changes
603 to the `prerelease` version, at `https://jjfan.github.io/jj/prerelease/`.
604
605 6. (Optional) The previous steps actually only rebuild
606 `https://jjfan.github.io/jj/prerelease/` and its alias
607 `https://jjfan.github.io/jj/main/`. If you'd like to test out version switching
608 back and forth, you can also rebuild the docs for the latest release as follows.
609
610 ```shell
611 jj new v1.33.1 # Let's say `jj 1.33.1` is the latest release
612 .github/scripts/docs-build-deploy v1.33.1 latest --push
613 ```
614
615 7. (Optional) When you are done, you may want to reset the `gh-pages` bookmark to the
616 same spot as it is upstream. If you configured the "upstream" remote,
617 this can be done with:
618
619 ```shell
620 # This will LOSE any changes you made to `gh-pages`
621 jj git fetch --remote upstream
622 jj bookmark set gh-pages -r gh-pages@upstream
623 jj git push --remote origin --bookmark gh-pages
624 ```
625
626 If you want to preserve some of the changes you made, you can do `jj bookmark
627 set my-changes -r gh-pages` BEFORE running the above commands.
628
629 ### Explanation of the `docs-build-deploy` script
630
631 The script sets up a few environment variables and invokes `uv run mike deploy`
632 with some default arguments and whatever arguments were passed to
633 `docs-build-deploy`. Run `uv run mike help deploy` to find out what the
634 arguments do.
635
636 If you need to do something more complicated, you can use `uv run mike
637 ...` commands. You can also edit the `gh-pages` bookmark directly, but take care
638 to avoid files that will be overwritten by future invocations of `mike`. Then,
639 you can submit a PR based on the `gh-pages` bookmark of
640 <https://docs.jj-vcs.dev/> (instead of the usual `main` bookmark).
641
642 Previously, the version switcher would not work unless the value of the
643 `site_url` config in `mkdocs.yml` matched the actual URL the site is being
644 served from. This bug should now be fixed, but if you are not serving the site
645 from <https://docs.jj-vcs.dev/> and something fails weirdly, you might want
646 to adjust the `site_url` to something like `https://jjfan.github.io/jj`.
647
648 ## Modifying protobuffers (this is not common)
649
650 Occasionally, you may need to change the `.proto` files that define jj's data
651 storage format. In this case, you will need to add a few steps to the above
652 workflow.
653
654 - Install the `protoc` compiler. This usually means either `apt-get install
655 protobuf-compiler` or downloading [an official release]. The
656 `prost` [library docs] have additional advice.
657 - Run `cargo run -p gen-protos` regularly (or after every edit to a `.proto`
658 file). This is the same as running `cargo run` from `lib/gen-protos`. The
659 `gen-protos` binary will use the `prost-build` library to compile the
660 `.proto` files into `.rs` files.
661 - If you are adding a new `.proto` file, you will need to edit the list of
662 these files in `lib/gen-protos/src/main.rs`.
663
664 [an official release]: https://github.com/protocolbuffers/protobuf/releases
665 [library docs]: https://docs.rs/prost-build/latest/prost_build/#sourcing-protoc
666
667 The `.rs` files generated from `.proto` files are included in the repository,
668 and there is a GitHub CI check that will complain if they do not match.
669
670 ## Logging
671
672 You can print internal jj logs using `JJ_LOG`. It acts like the `RUST_LOG`
673 environment variable, frequent in Rust codebases, and accepts one or more
674 [directives]. You can also run `JJ_LOG=debug jj` to get `debug` level logs
675 enabled for all targets. You can also use the `--debug` global option, which
676 turns on `debug` log level for `jj-lib` and `jj-cli` only.
677
678 [directives]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives
679
680 ## Profiling
681
682 ### Introduction
683
684 jj provides two main approaches to profiling:
685
686 1. **Tracing-based profiling** - Uses the Rust `tracing` crate to record spans
687 and events. Good for understanding control flow and finding where time is spent
688 in instrumented code.
689 2. **Sampling-based profiling** - Uses system profilers (perf, dtrace) to sample
690 the call stack. Good for finding hot spots including in uninstrumented code and
691 external libraries.
692
693 ### Tracing-based profiling
694
695 jj uses the `tracing` crate with Chrome Trace Format output.
696
697 Set the `JJ_TRACE` environment variable to generate a trace file:
698
699 ```shell
700 # Generate trace with auto-generated filename (jj-trace-{timestamp}.json)
701 JJ_TRACE= jj st
702
703 # Generate trace with specific filename
704 JJ_TRACE=/tmp/trace.json jj st
705 ```
706
707 To include function argument values in the trace (useful for detailed
708 debugging):
709
710 ```shell
711 JJ_TRACE_INCLUDE_ARGS=1 JJ_TRACE=/tmp/trace.json jj log -r 'ancestors(@, 10)'
712 ```
713
714 The produced profiles can be imported into chrome://tracing (on Google Chrome)
715 or https://ui.perfetto.dev/ (all browsers).
716
717 Only functions annotated with `#[tracing::instrument]` or explicit `trace_span!`
718 macros appear in traces. If you need to profile a specific area that isn't
719 instrumented, you can add `#[instrument]` attributes to the relevant functions.
720
721 ### Sampling-based profiling
722
723 Sampling profilers periodically capture the call stack to identify hot spots. This approach:
724
725 - Has lower overhead than tracing
726 - Captures all code, including uninstrumented functions and external libraries (like gitoxide)
727 - May miss short-lived function calls since it samples rather than traces every
728 call
729
730 #### Using samply
731
732 One easy-to-use sampling profiler
733 is [samply]. For example:
734
735 ```shell
736 cargo install samply
737 samply record jj diff
738 ```
739
740 Then just open the link it prints.
741
742 [samply]: https://github.com/mstange/samply
743
744 #### Using cargo-flamegraph
745
746 [cargo-flamegraph] generates flamegraph visualizations using system profilers:
747
748 ```shell
749 cargo install flamegraph
750 cargo flamegraph --bin jj -- diff
751 ```
752
753 You may need to use `sudo` or install `perf` on your system, see flamegraph's
754 documentation for more.
755
756 [cargo-flamegraph]: https://github.com/flamegraph-rs/flamegraph