Commit graph

6849 commits

Author SHA1 Message Date
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
Yuya Nishihara
5ff4e2d0a2 cli: pass &DiffFormatArgs in to default_diff_format()
Suppose we add -w/--ignore-all-space flag for example, it's probably better to
pass optional parameters by struct, not by separate arguments.
2024-08-21 17:48:52 +09:00
Yuya Nishihara
f76db7fa4b cli: flatten diff-args-to-formats translation
I'll add more parameters to color-words diffs, and the format variant will no
longer be trivially constructible.
2024-08-21 17:48:52 +09:00
Daniel Raniz Raneland
3d5c5b03de Added docs about installation under Gentoo Linux 2024-08-20 22:19:09 -07:00
dependabot[bot]
7449e67142 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.19 to 4.5.20
- [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.19...clap_complete-v4.5.20)

---
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-20 19:55:35 +02:00
dependabot[bot]
88811a7525 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.2 to 3.26.3
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](429e197704...883d8588e5)

---
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-20 19:55:23 +02:00
Essien Ita Essien
bb018a54c3 next/prev: Add config flag to control prev/next edit behaviour.
* We started with a tristate flag where:
    - Auto - Maintain current behaviour. This edits if
      the wc parent is not a head commit. Else, it will
      create a new commit on the parent of the wc in
      the direction of movement.
    - Always - Always edit
    - Never - Never edit, prefer the new+squash workflow.
  However, consensus the review thread is that `auto` mode where we try to infer when to
  switch to `edit mode`, should be removed. So `ui.movement.edit` is a boolean flag now.
    - true: edit mode
    - false: new+squash mode
* Also add a `--no-edit` flag as the explicit inverse of `--edit` and
  ensure both flags take precedence over the config.
* Update tests that assumed edit mode inference, to specify `--edit` explicitly.

NOTE: #4302 was squashed into this commit, so see that closed PR for review history.

Part of #3947
2024-08-20 15:46:00 +01:00
Marie Ramlow
e3fcae2152 merge_tools.toml: add VSCodium as a merge tool
[VSCodium](https://vscodium.com/) is a free/libre distribution of
Microsoft's Visual Studio Code editor, it's functionally more or less
the same, but distributed under a FOSS license, unlike VS Code.

This adds VSCodium as a merge tool.
2024-08-19 22:37:00 -07:00
Austin Seipp
e3ff8f7490 nix: run nix flake update
Just a regularly scheduled update.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-08-19 23:59:29 -05:00
dependabot[bot]
9ccc53dd59 cargo: bump the cargo-dependencies group with 4 updates
Bumps the cargo-dependencies group with 4 updates: [clap_complete](https://github.com/clap-rs/clap), [libc](https://github.com/rust-lang/libc), [syn](https://github.com/dtolnay/syn) and [tokio](https://github.com/tokio-rs/tokio).


Updates `clap_complete` from 4.5.16 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.16...clap_complete-v4.5.19)

Updates `libc` from 0.2.156 to 0.2.158
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Changelog](https://github.com/rust-lang/libc/blob/0.2.158/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.156...0.2.158)

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

Updates `tokio` from 1.39.2 to 1.39.3
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.39.2...tokio-1.39.3)

---
updated-dependencies:
- dependency-name: clap_complete
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
- dependency-name: libc
  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
- dependency-name: tokio
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-19 16:00:36 +00:00
dependabot[bot]
1e2faedce7 github: bump codespell-project/actions-codespell
Bumps the github-dependencies group with 1 update: [codespell-project/actions-codespell](https://github.com/codespell-project/actions-codespell).


Updates `codespell-project/actions-codespell` from 2.0 to 2.1
- [Release notes](https://github.com/codespell-project/actions-codespell/releases)
- [Commits](94259cd8be...406322ec52)

---
updated-dependencies:
- dependency-name: codespell-project/actions-codespell
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-19 17:54:49 +02:00
Marijan Smetko
0852724c76 Warn user about the working copy when configuring the author 2024-08-19 17:09:30 +02:00
Martin von Zweigbergk
3acb89e7cc merged_tree: remove TreeDiffEntry::source 2024-08-18 22:16:41 -07:00
Martin von Zweigbergk
721aa1238c copies: add a separate diff stream item type with copy info
The goal is to have the new item type know if it represent a copy, a
rename, a deleted rename source, or a regular copy-unrelated item.
2024-08-18 22:16:41 -07:00
Martin von Zweigbergk
70598498b0 merged_tree: provide separate version of diff_stream() with copy info
I plan to provide a richer version of `TreeDiffEntry` with copy info
(and to make `TreeDiffEntry` itself "poorer"). Most callers want to
know about copies/renames, but at least working copy implementations
probably don't. This patch adds separate `diff_stream()` and
`diff_stream_with_copies()` so we can provide the simpler interface
for callers that don't need copy info.
2024-08-18 22:16:41 -07:00
Martin von Zweigbergk
bce8550db1 merged_tree: inline next_impl() and poll_next_impl() 2024-08-18 22:16:41 -07:00
Martin von Zweigbergk
ad86dd1c1b copies: inline adjust_for_copy_tracking()
We now have only one caller, and it's in a different module, so it
makes more sense to move it there.
2024-08-18 22:16:41 -07:00
Martin von Zweigbergk
e670837ff6 copies: implement copy support in MergedTree::diff_stream() as adapter
The support for copy tracing is already simply added to the stream
just before yielding the item, so we can easily implement it as a
stream adapter. That ensures that we use the same logic for the
iterator- and stream-based versions. More importantly, it enables
further cleanups and a simpler interface.
2024-08-18 22:16:41 -07:00
Martin von Zweigbergk
fd9a236be5 copies: move CopyRecords to new copies module
Copy/rename handling is complicated. It seems worth having a module
for it. I'm going to add more content to it next.
2024-08-18 22:16:41 -07:00
Yuya Nishihara
6101a66a76 diff: inline Diff::default_refinement() in diff()
There are no callers other than tests and benches.
2024-08-19 11:54:58 +09:00
Yuya Nishihara
864dd73856 tests: use diff::diff() instead of Diff::default_refinement()
Diff::default_refinement() will be removed.
2024-08-19 11:54:58 +09:00
Yuya Nishihara
db0a4bccc5 diff: make diff() function accept any number of inputs
So that more tests can leverage diff::diff() helper.

I also removed the fast path for identical inputs. This function is only used by
tests and benches, and production code usually compares content hashes first.
2024-08-19 11:54:58 +09:00
Martin von Zweigbergk
aa0fbd9f3f drop "support" for legacy tree config
The tree-level conflicts have worked well in practice and we don't
want to allow users to use legacy trees for new commits. We don't
really support legacy trees very well since 0590f8bece anyway.
2024-08-18 07:19:50 -07:00
Essien Ita Essien
e2a5c83e5c Follow ups on post-submission comments for #4282.
* Derive a bunch of standard and useful traits for `movement_util::Direction`
  as it is a simple type. Importantly `Copy`.
* Return `&'static str` from Direction.cmd()
* Refactor out `MovementArgs` to reduce the number of arguments
  to `movement_util::move_to_commit`.
* Implement `From<&NextArgs/&PrevArgs>` for MovementArgs

Part of #3947
2024-08-18 10:43:08 +01:00
Yuya Nishihara
1be955ea4e diff: simplify conditions whether to emit color-words context lines
This appears to fix redundant "    ..." line for empty diffs.
2024-08-18 12:40:07 +09:00
Yuya Nishihara
9beb57018a diff: split color-words diffing to line-based and refinement stages
This allows us to select rendering function hunk by hunk. For example, a hunk
with lots of small changes could be rendered without interleaving left/right
words. Another good thing is that context line handling can be simplified as
the whole context hunk is available.
2024-08-18 12:40:07 +09:00