ok/jj
1
0
Fork 0
forked from mirrors/jj
Commit graph

7119 commits

Author SHA1 Message Date
Ilya Grigoriev
4a48865dbc templates: make op_summary more readable and colorful
This is meant to be a quick fix before I update the demos in the README.
The primary reason to update them is the branch -> bookmark transition,
but I noticed that `jj undo`'s output is currently not very pretty.

I believe printing both the start and end times is excessive for a
summary. For a long-running operation like `jj describe` with the editor
open for a long time, the ending time seems more meaningful.

I was a bit torn on whether to use `format_timestamp(self.time().end())`
or `self.time().end().ago()`. The latter looks better, but is less
configurable and worse for dates long ago. In the future, we could add a
`format_op_summary_timestamp` function and/or a template function that
uses `.ago()` for recent dates and absolute dates for old dates.
2024-10-07 14:36:58 -07:00
Yuya Nishihara
24ff802f58 revset: use Self to refer to expressions of the same type
Just because it's shorter.
2024-10-06 23:03:38 +09:00
Yuya Nishihara
68f48605e9 cli: in color-words diffs, highlight word-level hunks in context lines
Since context lines are styled in the same way as diff lines, it makes sense
to highlight words within context lines.
2024-10-06 09:45:27 +09:00
Yuya Nishihara
1eeeb1462a cli: extract helpers from show_color_words_context_lines()
This should make the next patch a bit easier to read.
2024-10-06 09:45:27 +09:00
Yuya Nishihara
6877ec4316 cli: add diff --ignore-all-space/--ignore-space-change flags
These flags only apply to line-based diffs. This is easy, and seems still useful
to highlight whitespace changes (that could be ignored by line diffing.)

I've added short options only to "diff"-like commands. It seemed unclear if
they were added to deeply-nested commands such as "op log".

Closes #3781
2024-10-06 09:45:27 +09:00
Yuya Nishihara
dc954517b9 cli: extract UnifiedDiff/DiffStatOptions structs
UnifiedDiffOptions could be wrapped by GitDiffOptions, but there are no Git-diff
specific options right now.
2024-10-06 09:45:27 +09:00
Yuya Nishihara
df40a09a5d cli: rename ColorWordsOptions to ColorWordsDiffOptions
I'm going to add an options struct for git diff, but GitOptions, UnifiedOptions,
StatOptions, etc. sound odd.
2024-10-06 09:45:27 +09:00
Yuya Nishihara
383cca4c4d diff: return matching hunk contents from all inputs
We're likely to use the right (or new) context lines in rendered diffs, but
it's odd that the hunks iterator choose which context hunk to return. We'll
also need both contents to calculate left/right line numbers.

Since the hunk content types are the same, I also split enum DiffHunk into
{ kind, contents } pair.
2024-10-06 09:45:27 +09:00
Fedor Sheremetyev
cacd6a3fd0 docs: add link to VisualJJ 2024-10-05 01:18:52 -07:00
Yuya Nishihara
c5f926103a diff: use low-level HashTable in Histogram
This change made some diff benches slow, maybe because the generated code
becomes slightly worse due to the added abstraction? I'll revisit the
performance problem later. There are a couple of ways to mitigate it.

```
group                             new                     old
-----                             ---                     ---
bench_diff_git_git_read_tree_c    1.02     61.0±0.23µs    1.00     59.7±0.38µs
bench_diff_lines/modified/10k     1.00     41.6±0.24ms    1.02     42.3±0.22ms
bench_diff_lines/modified/1k      1.00      3.8±0.07ms    1.00      3.8±0.03ms
bench_diff_lines/reversed/10k     1.29     23.4±0.20ms    1.00     18.2±0.26ms
bench_diff_lines/reversed/1k      1.05    517.2±5.55µs    1.00   493.7±59.72µs
bench_diff_lines/unchanged/10k    1.00      3.9±0.10ms    1.08      4.2±0.10ms
bench_diff_lines/unchanged/1k     1.01    356.8±2.33µs    1.00    353.7±1.99µs
```
(I don't get stable results on my noisy machine, so the results would vary.)
2024-10-05 08:12:30 +09:00
Yuya Nishihara
de137c8f9a diff: implement some ignore-space rules
The added comparison functions correspond to --ignore-all-space and
--ignore-space-change. --ignore-space-at-eol can be combined with the other
flags, so it will have to be implemented as a preprocessing function.
--ignore-blank-lines will also require some change in the tokenizer function.
2024-10-05 08:12:30 +09:00
Yuya Nishihara
f672c92509 diff: add trait for bytes comparison
This could be implemented as a newtype `Wrapper<'a>(&'a [u8])`, but a lifetime
of the wrap function couldn't be specified correctly:

  fn diff(left: &[u8], right: &[u8], wrap_fn: F, ..)
  where
    F: for<'a> Fn(&'a [u8]) -> W<'a>, // F::Output<'a> can't be specified
    W: Copy + Eq + Hash

If the wrapper were of `&Wrapper([u8])` type, `Fn(&[u8]) -> &W` works. However,
it means we can no longer set comparison parameter (such as Regex) dynamically.

Another idea is to add some filter function of `Fn(&[u8]) -> Cow<'_, [u8]>`
type, but I don't think we would want to pay the allocation cost in
hashing/comparison code. `Fn(&[u8]) -> impl Iterator<Item = &[u8]>` might work,
but it would be equally complex.
2024-10-05 08:12:30 +09:00
Yuya Nishihara
dfaa52c88a cargo: add hashbrown dependency
We'll use low-level HashTable to customize Eq/Hash without implementing newtype
wrappers.

Unneeded default features are disabled for now. Note that the new default
hasher, foldhash, is released under the Zlib license, which isn't currently
included in the allow list.
2024-10-05 08:12:30 +09:00
Samuel Tardieu
6368544f4f style: use explicit loop instead of .for_each() in simple cases 2024-10-04 22:29:13 +02:00
Samuel Tardieu
43711de61c style: use .filter_map() instead of .flat_map() where appropriate 2024-10-04 22:29:13 +02:00
Samuel Tardieu
12f4d6d17b style: avoid using .to_owned()/.to_vec() on owned objects
`.clone()` is more explicit when we already have an object
of the right type.
2024-10-04 22:29:13 +02:00
Samuel Tardieu
3f2ef2ee04 style: add semicolon at the end of expressions used as statements 2024-10-04 22:29:13 +02:00
Samuel Tardieu
46e2723464 style: inline variables into format strings 2024-10-04 22:29:13 +02:00
Samuel Tardieu
62f582e6ab style: remove useless uses of .iter()
Most collection references implement `.into_iter()` or its mutable version,
so it is possible to iterate over the elements without using an explicit
method to do so.
2024-10-04 22:29:13 +02:00
Samuel Tardieu
3f0703ca2c cargo: inherit lints configuration from workspace 2024-10-04 22:29:13 +02:00
Samuel Tardieu
794db9dae0 style: do not return a Result when this is not needed 2024-10-04 22:29:13 +02:00
Martin von Zweigbergk
801b243678 docs: mention snapshot.auto-track in config.md too
I forgot to add the `snapshot.auto-track` config option to `config.md`
when I added it. This patch copies it from `working-copy.md` and
modifies it slightly.
2024-10-04 12:42:22 -07:00
dependabot[bot]
266b804326 github: bump github/codeql-action in the github-dependencies group
Bumps the github-dependencies group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 3.26.10 to 3.26.11
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](e2b3eafc8d...6db8d6351f)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-04 11:45:53 -05:00
Samuel Tardieu
fb12e48fc9 cli: add short method summary to its documentation 2024-10-04 17:09:54 +02:00
Samuel Tardieu
8ba33b7383 lib: add short method summary to its documentation 2024-10-04 17:09:54 +02:00
Samuel Tardieu
87840a5c2c testutils: add short method summary to its documentation 2024-10-04 17:09:54 +02:00
Samuel Tardieu
ac95a86584 proc-macros: add short method summary to its documentation 2024-10-04 17:09:54 +02:00
Samuel Tardieu
e2408078bf cli: add pointer to the documentation in case of fileset syntax error 2024-10-04 17:09:43 +02:00
Yuya Nishihara
af556aa01c tests: rename test_file_print_command.rs to_file_show_command.rs 2024-10-04 20:52:59 +09:00
Matt Stark
6878b5047b Fix: Disallow revset function names starting with a number. 2024-10-04 15:25:11 +10:00
Theodore Ehrenborg
3d26af876f docs: update stale references to singular file() revset 2024-10-03 22:39:42 +02:00
dependabot[bot]
f23d40ce5e cargo: bump clap_complete in the cargo-dependencies group
Bumps the cargo-dependencies group with 1 update: [clap_complete](https://github.com/clap-rs/clap).


Updates `clap_complete` from 4.5.30 to 4.5.32
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.30...clap_complete-v4.5.32)

---
updated-dependencies:
- dependency-name: clap_complete
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-03 18:07:25 +02:00
Samuel Tardieu
2f9561a4b8 CI: add a last name to the list of spelling exceptions 2024-10-03 00:21:56 +02:00
Samuel Tardieu
acdc42fd9f doc: add comment to explain the syntax of folded examples 2024-10-02 19:37:18 +02:00
Martin von Zweigbergk
67c2ae0a9e release: release version 0.22.0 2024-10-02 10:25:20 -07:00
dependabot[bot]
d1b2e7ea82 cargo: bump the cargo-dependencies group with 3 updates
Bumps the cargo-dependencies group with 3 updates: [clap](https://github.com/clap-rs/clap), [clap_complete](https://github.com/clap-rs/clap) and [indexmap](https://github.com/indexmap-rs/indexmap).


Updates `clap` from 4.5.18 to 4.5.19
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.18...clap_complete-v4.5.19)

Updates `clap_complete` from 4.5.29 to 4.5.30
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.29...clap_complete-v4.5.30)

Updates `indexmap` from 2.5.0 to 2.6.0
- [Changelog](https://github.com/indexmap-rs/indexmap/blob/master/RELEASES.md)
- [Commits](https://github.com/indexmap-rs/indexmap/compare/2.5.0...2.6.0)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
- dependency-name: clap_complete
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
- dependency-name: indexmap
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-02 16:17:46 +00:00
Lukas Wirth
72c5bbb4e6 Be more specific when warning the user about missing identity configs
Check if only the email or the name are missing in the config and specifically name the missing one, instead of always defaulting to potentially both missing.
2024-10-02 18:10:46 +02:00
Martin von Zweigbergk
f8e30fb1de bookmarks: update docs to try to clarify mapping to Git branches
I also removed a few instances suggesting that we might map bookmarks
to something else in Git in the future (I don't think we have any such
plans).
2024-10-01 06:46:32 -07:00
Yuya Nishihara
4f8ae69367 diff: keep absolute ranges to support unchanged regions of different lengths
We have two options to achieve "diff --ignore-*-space":
 a. preprocess contents to be diffed, then translate hunk ranges back
 b. add hooks to customize eq and hash functions
I originally thought (a) would be easier, but actually, there aren't many
changes needed to implement (b). And (b) should have a fewer logic errors.

This patch removes assumption that each unchanged region has the same content
length. It won't be true if whitespace characters are ignored.
2024-10-01 21:24:02 +09:00
Yuya Nishihara
e28fdac48e diff: extract helper that returns texts between two UnchangedRanges 2024-10-01 21:24:02 +09:00
Yuya Nishihara
055f15b6a8 diff: don't destructure UnchangedRange in a loop, rename base_range field
I'll replace offsets with absolute [Range, ..] to support unchanged regions of
different lengths. All fields in UnchangedRange will be ranges.
2024-10-01 21:24:02 +09:00
Yuya Nishihara
db226d9f64 revset: fix crash on "log --at-op 00000000 -r 'root()'"
Spotted while refactoring IdPrefixContext.
2024-10-01 21:23:47 +09:00
Yuya Nishihara
0a8d8dad67 cli: make default log revset work without working-copy commit
Spotted while adding an error propagation path from IdPrefixContext.
2024-10-01 20:04:06 +09:00
Yuya Nishihara
1f5835c267 cli: simplify help about default "log -r"
Since we've moved the default log revset to config/*.toml at 3dab92d2, we don't
have to repeat the default value. It can be queried by "jj config list". I also
split the help paragraphs.
2024-10-01 20:04:06 +09:00
Yuya Nishihara
0ac6df7073 revset: make present(unknown@) recover from missing working copy error
Missing working-copy commit is similar situation to unknown ref, and should
be caught by present().
2024-10-01 20:04:06 +09:00
Yuya Nishihara
68176d965e diff: do not translate word-range indices by collect_unchanged_ranges()
Intersection of unchanged ranges becomes a simple merge-join loop, so I've
removed the existing tests. I also added a fast path for the common 2-way
diffs in which we don't have to build vec![(pos, vec![pos])].

One source of confusion introduced by this change is that WordPosition means
both global and local indices. This is covered by the added tests, but I might
add separate local/global types later.
2024-10-01 06:31:22 +09:00
Yuya Nishihara
483db9d7d2 diff: reuse result vec when recurse into unchanged_ranges()
It's silly that we build new Vec for each recursion stack and merge elements
back. I don't see a measurable performance difference in the diff bench, but
this change will help simplify the next patch. If a result vec were created for
each unchanged_ranges() invocation, it would probably make more sense to return
a list of "local" word positions. Then, callers would have to translate the
returned positions to the caller's local positions.
2024-10-01 06:31:22 +09:00
Yuya Nishihara
f6277bbdb8 diff: remove redundant check for empty ranges from unchanged_ranges() recursion
It's cheap to create an empty Vec, and I'm going to remove it anyway.
2024-10-01 06:31:22 +09:00
dependabot[bot]
fd2c377a4a github: bump github/codeql-action in the github-dependencies group
Bumps the github-dependencies group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 3.26.9 to 3.26.10
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](461ef6c76d...e2b3eafc8d)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-30 18:49:51 +02:00
dependabot[bot]
0021744203 cargo: bump the cargo-dependencies group with 4 updates
Bumps the cargo-dependencies group with 4 updates: [once_cell](https://github.com/matklad/once_cell), [regex](https://github.com/rust-lang/regex), [syn](https://github.com/dtolnay/syn) and [tempfile](https://github.com/Stebalien/tempfile).


Updates `once_cell` from 1.19.0 to 1.20.1
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](https://github.com/matklad/once_cell/compare/v1.19.0...v1.20.1)

Updates `regex` from 1.10.6 to 1.11.0
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.10.6...1.11.0)

Updates `syn` from 2.0.77 to 2.0.79
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/2.0.77...2.0.79)

Updates `tempfile` from 3.12.0 to 3.13.0
- [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Stebalien/tempfile/compare/v3.12.0...v3.13.0)

---
updated-dependencies:
- dependency-name: once_cell
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cargo-dependencies
- dependency-name: regex
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cargo-dependencies
- dependency-name: syn
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
- dependency-name: tempfile
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-30 18:49:39 +02:00