Commit graph

6874 commits

Author SHA1 Message Date
Yuya Nishihara
db6a58d315 store: switch in-memory cache to LRU-based HashMap to cap memory usage
I just choose "clru" because it already exists in our dependency tree thorough
gix. I don't think LRU is the best cache eviction policy for our use case (a
simpler FIFO-based one might be good enough?), but it wouldn't matter for CLI
or GUI use case. I don't see significant performance degradation with "jj log
--stat -n1000".

RwLock is replaced with Mutex since get() is inherently a mutable operation.
2024-08-29 23:33:37 +09:00
Yuya Nishihara
424623ba91 cargo: add "clru" dependency 2024-08-29 23:33:37 +09:00
Yuya Nishihara
d99a8508e4 rewrite: pass old parent ids in to mut_repo.new_parents() by slice 2024-08-29 08:59:22 +09:00
Yuya Nishihara
1fe9422a6e rewrite: deduplicate parent ids per remap iteration
If merge-heavy history was abandoned, intermediate parent chains can have tons
of duplicates, and the process explodes soon. Instead, we can skip any parent
ids that have been remapped.

We can no longer detect cycles reliably, but I think that's okay so long as
the function terminates.

Fixes #4352
2024-08-29 08:59:22 +09:00
Yuya Nishihara
d76d4a90a7 rewrite: flip inner/outer loops of mut_repo.new_parents()
This is basically a DFS to find leaf nodes. It will help omit duplicated
parent ids early.
2024-08-29 08:59:22 +09:00
dependabot[bot]
8b6bebad40 cargo: bump rustix in the cargo-dependencies group
Bumps the cargo-dependencies group with 1 update: [rustix](https://github.com/bytecodealliance/rustix).


Updates `rustix` from 0.38.34 to 0.38.35
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v0.38.34...v0.38.35)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-28 10:49:58 -05:00
Yuya Nishihara
5af906d924 cli: change default inline threshold of color-words diffs
I played with max-inline-alternation = 3 for a couple of weeks, and it's pretty
good. I think somewhere between 2 and 4 is good default because one or two
remove + add sequences are easy to parse.
2024-08-28 10:33:33 +09:00
Yuya Nishihara
9c9e564dc4 conflicts: pass around conflict contents without materialization
We haven't decided how conflict diffs should be rendered, but whatever style
we'll choose, we'll need raw unmaterialized conflict contents.
2024-08-28 10:23:57 +09:00
Yuya Nishihara
73a8b13e4c conflicts: split materialized value to FileConflict and OtherConflict
FileConflict will be changed to not materialize Merge<BString>. I also updated
the revset engine to ignore non-file conflict. It doesn't make sense to grep
conflict description.
2024-08-28 10:23:57 +09:00
Yuya Nishihara
0c14a0a9ca conflicts: make describe() simply return string
I'll add more callers of id.describe(), and the output size wouldn't be large
enough to avoid allocation by using Write API.
2024-08-28 10:23:57 +09:00
Yuya Nishihara
1ba581b37c conflicts: replace ContentHunk with BString
ContentHunk is basically a nice wrapper around Vec<u8>. I think it would give
little benefit for type safety.
2024-08-28 10:23:57 +09:00
dependabot[bot]
dd8ec3dece 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.23 to 4.5.24
- [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.23...clap_complete-v4.5.24)

---
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-08-27 16:54:37 -05:00
dependabot[bot]
44ed245c8f cargo: bump the cargo-dependencies group with 3 updates
Bumps the cargo-dependencies group with 3 updates: [serde](https://github.com/serde-rs/serde), [serde_json](https://github.com/serde-rs/json) and [syn](https://github.com/dtolnay/syn).


Updates `serde` from 1.0.208 to 1.0.209
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.208...v1.0.209)

Updates `serde_json` from 1.0.125 to 1.0.127
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/1.0.125...1.0.127)

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

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-26 18:08:56 +02:00
dependabot[bot]
708eb8dd0d 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.4 to 3.26.5
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](f0f3afee80...2c779ab0d0)

---
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-08-26 15:26:52 +00:00
Austin Seipp
d928e43073 cli: add name() and about() methods to CliRunner
Useful for third party tools to override, along with the version.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-08-25 12:24:02 -05:00
Yuya Nishihara
6b65f8abec cli: move "untrack" to "file" subcommand
I don't think "jj untrack" is frequently used, and I think it is a "file"
command rather than "workspace".
2024-08-26 01:19:15 +09:00
Yuya Nishihara
3c15f8106a cli: add deprecation comment to cat, chmod, and files 2024-08-26 01:19:15 +09:00
Yuya Nishihara
3762f890f6 cli: extract helper that issues deprecation warning and invoke command fn 2024-08-26 01:19:15 +09:00
Yuya Nishihara
842ebe7f92 docs: add missing single quote to revset-aliases example
Spotted by xzfc.
2024-08-25 23:16:29 +09:00
Yuya Nishihara
3b0b70a451 cli: fix default value of ui.allow-filesets in config schema
It's been enabled since 8fec7500c3 "cli: enable fileset by default."
2024-08-25 23:16:29 +09:00
Essien Ita Essien
f9dc0589c1 next/prev: update error message when no movement targets are found.
If movement commands don't find a target commit, they fail. However,
it's usually not intuitive why they fail because in non-edit mode the
start commit is the parent of the working commit.

Adding the start commit change hash to the error message makes it easier
for the user to figure out what is going on.

Also, specifying 'No **other** descendant...' helps make it clear what
`jj` is really looking for.

Part of #3947
2024-08-25 09:58:04 +01:00
Yuya Nishihara
8d166c7642 templater: integrate copy tracking in commit.diff() template 2024-08-24 15:47:08 +09:00
Martin von Zweigbergk
b78c83e9fe status: report copies and renames 2024-08-23 18:51:02 -07:00
Martin von Zweigbergk
fc09be1a62 changelog: simply bullet about diff formats supporting copies/renames
Since only `--name-only` doesn't support copies/renames, it's simpler
to say that than to list the formats that do.
2024-08-23 18:51:02 -07:00
Martin von Zweigbergk
acdcb578bc copies: in unsupported backends, return an empty stream instead of error
The native backend currently errors out if you ask it about copies. So
does the test backend. I think it's better to return an empty stream
of copies so it doesn't prevent other functionality.
2024-08-23 18:51:02 -07:00
Martin von Zweigbergk
b05593fdf5 docs: add git ls-files to command comparison table
This came up in #4323.
2024-08-22 22:30:31 -07:00
Yuya Nishihara
f1be5c59f3 cleanup: consistently import std::fmt 2024-08-23 13:05:27 +09:00
Yuya Nishihara
87fb169266 cleanup: remove redundant ::{self} from use declarations 2024-08-23 13:05:27 +09:00
Yuya Nishihara
4ffd3a3055 diff: pass tree diff stream in to inner show_*() functions as before 2024-08-23 10:29:12 +09:00
Yuya Nishihara
f5187fa063 copies: determine copy/rename operation by CopiesTreeDiffStream
Not all callers need this information, but I assumed it's relatively cheap to
look up the source path in the target tree compared to diffing.

This could be represented as Regular(_)|Copied(_, _)|Renamed(_, _), but it's
a bit weird if Copied and Renamed were separate variants. Instead, I decided
to wrap copy metadata in Option.
2024-08-23 10:29:12 +09:00
Yuya Nishihara
b6060ce6dd copies: wrap source path in Option to save allocation
Most diff entries should have no copy sources.
2024-08-23 10:29:12 +09:00
Yuya Nishihara
08262eb152 copies: extract (source, target) path pair to separate type
This patch adds accessor methods as I'm going to change the underlying data
types. Since entry values are consumed separately, these methods are implemented
on CopiesTreeDiffEntryPath, not on *TreeDiffEntry.
2024-08-23 10:29:12 +09:00
Yuya Nishihara
43bf195314 merged_tree: rename diff entry field from "value" to "values"
It seems a slightly better, and aligns with the local variable name in
materialized_diff_stream().
2024-08-23 10:29:12 +09:00
Yuya Nishihara
10cbb513fa copies: define CopiesTreeDiffEntry struct before stream type
I'm going to add some methods, and I don't want to insert them in between
the stream type and impls.
2024-08-23 10:29:12 +09:00
Matt Kulukundis
e67aac6d5c Update dependencies and bump the version for gix 2024-08-22 20:06:34 -04:00
Matt Kulukundis
ac7fa1abb9 docs: improve md format for jj fix 2024-08-22 16:03:44 -04:00
Matt Kulukundis
8ead72e99f formatting only: switch to Item level import ganularity 2024-08-22 14:52:54 -04:00
dependabot[bot]
c5af500724 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.3 to 3.26.4
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](883d8588e5...f0f3afee80)

---
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-08-22 16:29:06 +00:00
dependabot[bot]
458381f062 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.20 to 4.5.22
- [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.20...clap_complete-v4.5.22)

---
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-08-22 11:20:36 -05:00
Yuya Nishihara
352a4a0eea copies: filter rename source entries by CopiesTreeDiffStream 2024-08-22 20:17:19 +09:00
Yuya Nishihara
47ff9ad231 copies: break method chaining in CopiesTreeDiffStream::poll_next()
So that it can be wrapped within a while loop + continue.
2024-08-22 20:17:19 +09:00
Yuya Nishihara
7684ab5994 diff: omit rename source entries from color-words diffs
Rename source entries will be handled by CopiesTreeDiffStream.
2024-08-22 20:17:19 +09:00
Yuya Nishihara
2cffcc9323 copies: provide source path mapping by CopyRecords
All for/has_source/target() combinations are added for API consistency.
2024-08-22 20:17:19 +09:00
Yuya Nishihara
5e356ffd24 diff: filter out uninteresting copy records by matcher
Git reports a rename source as deleted if the rename target is excluded. I
think that's because Git restricts the search space to the specified paths. For
example, Git doesn't also recognize a rename if the source path is excluded
whereas jj does.

I don't think we need to copy the exact behavior of Git, so this patch just
moves matcher application to earlier stage. This change will help remove
collect_copied_sources().

The added get_copy_records() helper could be moved to jj_lib, but we'll probably
want a stream version of this function in library, and writing a stream adapter
isn't as simple as iterator.
2024-08-22 20:17:19 +09:00
Yuya Nishihara
d85e66bbb4 copies: turn add_records() into non-stream API, block_on_stream() by caller
This is simpler, and I think it's generally better to not spawn executor in
library code.
2024-08-22 20:17:19 +09:00
Yuya Nishihara
a83dadd5a9 diff: add option to display complex color-words diffs without inlining
In this patch, I use the number of adds<->removes alternation as a threshold,
which approximates the visual complexity of diff hunks. I don't think user can
choose the threshold intuitively, but we need a config knob to try out some.
I set `max-inline-alternation = 3` locally. 0 and 1 mean "disable inlining"
and "inline adds-only/removes-only lines" respectively.

I've added "diff.<format>" config namespace assuming "ui.diff" will be
reorganized as "ui.diff-formatter" or something. #3327

Some other metrics I've tried:
```
// Per-line alternation. This also works well, but can't measure complexity of
// changes across lines.
fn count_max_diff_alternation_per_line(diff_lines: &[DiffLine]) -> usize {
    diff_lines
        .iter()
        .map(|line| {
            let sides = line.hunks.iter().map(|&(side, _)| side);
            sides
                .filter(|&side| side != DiffLineHunkSide::Both)
                .dedup() // omit e.g. left->both->left
                .count()
        })
        .max()
        .unwrap_or(0)
}

// Per-line occupancy of changes. Large diffs don't always look complex.
fn max_diff_token_ratio_per_line(diff_lines: &[DiffLine]) -> f32 {
    diff_lines
        .iter()
        .filter_map(|line| {
            let [both_len, left_len, right_len] =
                line.hunks.iter().fold([0, 0, 0], |mut acc, (side, data)| {
                    let index = match side {
                        DiffLineHunkSide::Both => 0,
                        DiffLineHunkSide::Left => 1,
                        DiffLineHunkSide::Right => 2,
                    };
                    acc[index] += data.len();
                    acc
                });
            // left/right-only change is readable
            (left_len != 0 && right_len != 0).then(|| {
                let diff_len = left_len + right_len;
                let total_len = both_len + left_len + right_len;
                (diff_len as f32) / (total_len as f32)
            })
        })
        .reduce(f32::max)
        .unwrap_or(0.0)
}

// Total occupancy of changes. Large diffs don't always look complex.
fn total_change_ratio(diff_lines: &[DiffLine]) -> f32 {
    let (diff_len, total_len) = diff_lines
        .iter()
        .flat_map(|line| &line.hunks)
        .fold((0, 0), |(diff_len, total_len), (side, data)| {
            let l = data.len();
            match side {
                DiffLineHunkSide::Both => (diff_len, total_len + l),
                DiffLineHunkSide::Left => (diff_len + l, total_len + l),
                DiffLineHunkSide::Right => (diff_len + l, total_len + l),
            }
        });
    (diff_len as f32) / (total_len as f32)
}
```
2024-08-21 17:48:52 +09:00
Yuya Nishihara
be9b7ed88f diff: pad last newline by show_color_words_diff_line()
Though this is needed only for the last line, checking it for each line is
cheap. As I'm going to add another rendering style, the condition to pad "\n"
would become more complicated.
2024-08-21 17:48:52 +09:00
Yuya Nishihara
bb686c1459 diff: extract helper that prints color-words line numbers 2024-08-21 17:48:52 +09:00
Yuya Nishihara
6b2e191b2b diff: extract helpers that process word-level diffs without interleaving
These functions will be reused by non-inline version of color-words diffs.
2024-08-21 17:48:52 +09:00
Yuya Nishihara
decd913cea cli: introduce options struct specific to color-words diffs
I'll add a threshold whether to inline word changes.
2024-08-21 17:48:52 +09:00