Commit graph

533 commits

Author SHA1 Message Date
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
Daniel Raniz Raneland
3d5c5b03de Added docs about installation under Gentoo Linux 2024-08-20 22:19:09 -07: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
Essien Ita Essien
a6d8009097 Define builtin_immutable_heads() as a default revset alias.
* Add `builtin_immutable_heads()` in the `revsets.toml`.
* Redefine `immutable_heads()` in terms of `builtin_immutable_heads()`
* Warn if user redefines `builtin_immutable_heads()`, `mutable()` or
  `immutable()`.
* Update module constant in revset_util.rs from BUILTIN_IMMUTABLE_HEADS
  to USER_IMMUTABLE_HEADS to avoid confusion since it points at
  `immutable_heads()` **and** we now have a revset-alias
  literally named `builtin_immutable_heads()`.
* Add unittest
* Update CHANGELOG
* Update documentation.

Fixes: #4162
2024-08-14 11:32:16 +01:00
Aaron Bull Schaefer
e803bed845 config: expand tilde in ssh key filepaths
Add home directory expansion for SSH key filepaths. This allows the
`signing.key` configuration value to work more universally across both
Linux and macOS without requiring an absolute path.

This moved and renamed the previous `expand_git_path` function to a more
generic location, and the prior use was updated accordingly.
2024-08-13 08:06:43 -07:00
Ilya Grigoriev
206c0cf830 docs: document how to compile a statically linked binary on Mac
I feel like this is worth documenting, as it shouldn't require
Homebrew.
2024-08-11 20:10:37 -07:00
Ilya Grigoriev
b2123282e8 tutorial: link to Steve Klabnik's tutorial, mention jj log -r ::
I was thinking of updating the tutorial in #4168, but conversations like [this
one on
Discord](https://discord.com/channels/968932220549103686/968932220549103689/1269803837070377076)
suggest that many people aren't reading it anyway.

So, this is an attempt to quickly patch up the most relevant things before the
upcoming release.
2024-08-06 11:27:08 -07:00
Martin von Zweigbergk
417f19d58a docs: minor updates to description of branch conflicts
Closes #4220.
2024-08-05 18:20:37 -07:00
Fedor Sheremetyev
c43096ba96 docs: Fix example with Git conflicts markers 2024-08-02 10:36:38 -07:00
Martin von Zweigbergk
5b2259445e FAQ: remove workaround for fixed bug (#2476) 2024-08-01 09:07:32 -07:00
Stephen Jennings
6c41b1bef8 revset: add author_date and committer_date revset functions
Author dates and committer dates can be filtered like so:

    committer_date(before:"1 hour ago") # more than 1 hour ago
    committer_date(after:"1 hour ago")  # 1 hour ago or less

A date range can be created by combining revsets. For example, to see any
revisions committed yesterday:

    committer_date(after:"yesterday") & committer_date(before:"today")
2024-08-01 09:04:07 -07:00
Danny Hooper
89f5d16dc0 cli jj fix: add ability to configure multiple tools for different filesets
The high level changes include:
 - Reworking `fix_file_ids()` to loop over multiple candidate tools per file,
   piping file content between them. Only the final file content is written to
   the store, and content is no longer read for changed files that don't match
   any of the configured patterns.
 - New struct `ToolsConfig` to represent the parsed/validated configuration.
 - New function `get_tools_config()` to create a `ToolsConfig` from a `Config`.
 - New tests; the only old behavior that has changed is that we don't require
   `fix.tool-command` if `fix.tools` defines one or more tools. The general
   approach to validating the config is to fail early if anything is weird.

Co-Authored-By: Josh Steadmon <steadmon@google.com>
2024-07-25 13:40:18 -05:00
Yuya Nishihara
d6e97883df cli: port description template to templater
This implements a building block of "signed-off-by line" #1399 and "commit
--verbose" #1946. We'll probably need an easy way to customize the diff part,
but I'm not sure if it can be as simple as a template alias function. User
might want to embed diffs without "JJ: " prefixes?

Perhaps, we can deprecate "ui.default-description", but it's not addressed in
this patch. It could be replaced with "default_description" template alias,
but we might want to configure default per command. Suppose we add a default
"backout_description" template, it would have to be rendered against the
source commit, not the newly-created backout commit.

The template key is named as "draft_commit_description" because it is the
template to generate an editor template. "templates.commit_description_template"
sounds a bit odd.

There's one minor behavior change: the default description is now terminated
by "\n".

Closes #1354
2024-07-25 22:39:00 +09:00
Yuya Nishihara
8fec7500c3 cli: enable fileset by default
I've tested it for months and found no problems.
2024-07-24 10:49:46 +09:00
Stephen Jennings
03b6d380f5 git: add git.private-commits setting for preventing commits from being pushed
The user can define the setting `git.private-commits` as they desire. For
example:

    git.private-commits = 'description(glob:"wip:*")'

If any commits are in this revset, then the push is aborted.

If a commit would be private but already exists on the remote, then it does
not block pushes, nor do its descendents block pushes unless they are also
contained in `git.private-commits`.

Closes #3376
2024-07-23 08:45:51 -07:00
Julien Vincent
feceb622f1 Add hunk.nvim to list of community tools 2024-07-22 15:29:54 -06:00
Yuya Nishihara
ddc601fbf9 str_util: add regex pattern
This patch adds minimal support for the regex pattern. We might have to add
"regex-i:" for completeness, but it can be achieved by "regex:'(?i)..'".
2024-07-22 12:00:52 +09:00
Yuya Nishihara
5649ee4f45 fileset: parse glob characters as identifier
It's inconvenient that we have to quote glob patterns as 'glob:"*.rs"'. Suppose
filesets are usually specified in shell, it's better to allow unquoted strings
if possible. This change also means we'll probably abandon #2101 "make the
parsing of string arguments stricter."

Note that we can no longer introduce ? operator or [] subscript syntax in
filesets.

Closes #4053
2024-07-18 13:49:10 +09:00
Yuya Nishihara
895eead4b8 revset: add diff_contains(text[, files]) to search diffs
The text pattern is applied prior to comparison as we do in Mercurial. This
might affect hunk selection, but is much faster than computing diff of full
file contents. For example, the following hunk wouldn't be caught by
diff_contains("a") because the line "b\n" is filtered out:

    - a
      b
    + a

Closes #2933
2024-07-18 01:01:16 +09:00
Vladimír Čunát
0c8f881fcd docs/git-comparison.md: update the Signed_commits bullet 2024-07-17 17:12:34 +02:00
Yuya Nishihara
d1912bf016 templater: add commit.diff().<format>() methods
This patch adds TreeDiff template type to host formatting options. The main
reason of this API design is that diff formats have various incompatible
parameters, so a single .diff(files, format[, options..]) method would become
messy pretty quickly. Another reason is that we can probably add custom
summary templating support as diff.files().map(|file| file.path()..).

RepoPathUiConverter is passed to templater explicitly because the one stored
in RevsetParseContext is behind Option<_>.
2024-07-17 18:52:49 +09:00
Vincent Ging Ho Yim
79b326d56b cli_util: add missing word in conflict resolution instructions 2024-07-17 08:10:25 +02:00
Yuya Nishihara
a757fddcf1 revset: parse file() argument as fileset expression
Since fileset and revset languages are syntactically close, we can reparse
revset expression as a fileset. This might sound a bit scary, but helps
eliminate nested quoting like file("~glob:'*.rs'"). One oddity exists in alias
substitution, though. Another possible problem is that we'll need to add fake
operator parsing rules if we introduce incompatibility in fileset, or want to
embed revset expressions in a fileset.

Since "file(x, y)" is equivalent to "file(x|y)", the former will be deprecated.
I'll probably add a mechanism to collect warnings during parsing.
2024-07-16 10:18:57 +09:00
Yuya Nishihara
ea3a574e36 cli: include untracked remote branches in default immutable_heads()
I used to use "remote_branches() & ~mine()" to exclude "their" branches from
the default log, and I don't think that's uncommon requirement. Suppose
untracked branches are usually read-only, it's probably okay to make them
immutable by default.
2024-07-15 23:41:07 +09:00
Scott Taylor
2dd75b5c53 revset: add tracked/untracked_remote_branches()
Adds support for revset functions `tracked_remote_branches()` and
`untracked_remote_branches()`. I think this would be especially useful
for configuring `immutable_heads()` because rewriting untracked remote
branches usually wouldn't be desirable (since it wouldn't update the
remote branch). It also makes it easy to hide branches that you don't
care about from the log, since you could hide untracked branches and
then only track branches that you care about.
2024-07-13 10:43:21 -05:00
Philip Metzger
0690922ca1 FAQ: Add some more variants on how to deal with temporary files
The people in #323 think that we should document all patterns there are to deal with ignored files.
2024-07-11 20:01:57 +02:00
Emily
93d76e5d8f str_util: support case‐insensitive string patterns
Partially resolve a 1.5‐year‐old TODO comment.

Add opt‐in syntax for case‐insensitive matching, suffixing the
pattern kind with `-i`. Not every context supports case‐insensitive
patterns (e.g. Git branch fetch settings). It may make sense to make
this the default in at least some contexts (e.g. the commit signature
and description revsets), but it would require some thought to avoid
more confusing context‐sensitivity.

Make `mine()` match case‐insensitively unconditionally, since email
addresses are conventionally case‐insensitive and it doesn’t take
a pattern anyway.

This currently only handles ASCII case folding, due to the complexities
of case‐insensitive Unicode comparison and the `glob` crate’s lack
of support for it. This is unlikely to matter for email addresses,
which very rarely contain non‐ASCII characters, but is unfortunate
for names and descriptions. However, the current matching behaviour is
already seriously deficient for non‐ASCII text due to the lack of any
normalization, so this hopefully shouldn’t be a blocker to adding the
interface. An expository comment has been left in the code for anyone
who wants to try and address this (perhaps a future version of myself).
2024-07-10 05:58:34 +01:00
Yuya Nishihara
44a39017f0 diff: highlight word-level changes in git diffs
The output looks somewhat similar to color-words diffs. Unified diffs are
verbose, but are easier to follow if adjacent lines are added/removed + modified
for example.

Word-level diffing is forcibly enabled. We can also add a config knob (or
!color condition) to turn it off to save CPU time.

I originally considered disabling highlights in block insertion/deletion, but
that wasn't always great. This can be addressed separately as it also applies
to color-words diffs. #3958
2024-07-05 16:07:12 +09:00
Benjamin Tan
0c0e001262 git init: add revset alias for trunk() when intializing with existing git repository 2024-07-04 23:04:19 +08:00
Benjamin Tan
d8899e1ae7 git clone: add revset alias for trunk() 2024-07-04 23:04:19 +08:00
Matt Kulukundis
aaa99e6dc7 diff: add a file-by-file variant for external diff tools 2024-07-03 20:09:17 -04:00
Yuya Nishihara
5a85254bde docs: add customization example of color-words diff style
The default style is compatible with various terminal emulators, but I suspect
that many people wouldn't like underlines. Let's add an example to override it.
2024-07-02 18:47:36 +09:00
Philip Metzger
3b2197c74a docs: Add a Design Doc blueprint.
This should be the template for all new Design Docs, minor deviations aside.
Hopefully this makes the process a bit easier.
2024-06-30 15:37:40 +02:00
Philip Metzger
c4777e4721 docs: Formalize our design docs process a bit.
This adds the basic outline of _when_ a Design Doc should be written. See the next
commit in the stack for the blueprint. 

By adding this we hopefully can prevent unnecessary churn from new and longtime contributors, 
when they want to add a major feature or rewrite a core part of Jujutsu. The text is written
as a guideline, not a rule.
2024-06-30 15:37:40 +02:00
Martin von Zweigbergk
8d67b1412e cleanup: leverage BoxStream/BoxFuture type aliases
Thanks to @fowles for bringing these to my attention.
2024-06-26 11:34:52 +09:00
Ilya Grigoriev
46b37aca2f docs: replace jj files -> jj file list
`jj files` is now deprecated
2024-06-24 21:01:55 -07:00
dploch
1a78ba5eaf copy-info: initial design doc 2024-06-24 13:26:12 -04:00
Martin von Zweigbergk
31b8f07fa0 docs: hyphenate "community-built" 2024-06-20 05:34:02 +09:00
Martin von Zweigbergk
2cdb767991 docs: explain that jj was started 3 years before Sapling announcement
Someone at work asked me why I started jj when Sapling already
existed. Let's clarify that I started it before.
2024-06-20 05:24:28 +09:00
Martin von Zweigbergk
9257d0946e docs: use bullet lists in revset examples to save vertical space 2024-06-20 05:21:03 +09:00
Martin von Zweigbergk
3ebad154ca docs: add examples for some revset functions too 2024-06-19 19:57:22 +09:00
Ilya Grigoriev
a6d470dbc3 docs revsets.md: fixup 4d08c2c
This makes the examples in
https://martinvonz.github.io/jj/prerelease/revsets/#operators render
properly at the cost of worse (but readable) rendering on GitHub.

Also fixes a typo.
2024-06-17 22:58:25 -07:00
Philip Metzger
30f54862dd docs: Add a page for community built tools.
Thank you all for building tools around it.
2024-06-17 19:47:13 +02:00
Matt Kulukundis
8aa71f58f3 feat: add an option to monitor the filesystem asynchronously
- make an internal set of watchman extensions until the client api gets
  updates with triggers
- add a config option to enable using triggers in watchman

Co-authored-by: Waleed Khan <me@waleedkhan.name>
2024-06-16 23:24:22 -04:00
Martin von Zweigbergk
4d08c2cce8 docs: include examples for operators
There's been a lot of questions about the subtle differences between
`..` and `::`. I hope these examples will help with that.

We should also add examples to the revset functions (e.g. `heads()` is
not obvious how it works), but that can come later.
2024-06-17 12:23:46 +09:00
Martin von Zweigbergk
182cf6d5e2 docs: explain what .. etc are shorthand for
`..` is shorthand for `root()..visible_head()`, for example. We don't
seem to explain that anywhere. I hope mentioning that will help
readers understand the relationship between the shorthands and the
full `x..y`, and also to see the correspondence between `..` and `::`
(in how their default left and right operands are the same).
2024-06-17 12:23:46 +09:00
Ilya Grigoriev
4a63506e9f docs CLI Reference: make the warning in the beginning less scary
I am currently not aware of any severe differences between the generated
markdown and `jj help`, though this could change if we look over the
text carefully or if we start using `clap` features we weren't using
before.
2024-06-15 20:30:40 -07:00
Yuya Nishihara
a7bff04af8 revset, templater: implement arity-based alias overloading
Still alias function shadows builtin function (of any arity) by name. This
allows to detect argument error as such, but might be a bit inconvenient if
user wants to overload heads() for example. If needed, maybe we can add some
config/revset syntax to import builtin function to alias namespace.

The functions table is keyed by name, not by (name, arity) pair. That's mainly
because std collections require keys to be Borrow, and a pair of borrowed
values is incompatible with owned pair. Another reason is it makes easy to look
up overloads by name.

Alias overloading could also be achieved by adding default parameters, but that
will complicate the implementation a bit more, and can't prevent shadowing of
0-ary immutable_heads().

Closes #2966
2024-06-14 23:11:29 +09:00
Kyle J Strand
03a0921e12 give descendants a range arg 2024-06-13 18:54:57 -06:00
Ilya Grigoriev
2d0b715ad0 docs: update windows docs to mention minus, update minus docs
Quick fix to #3850.
2024-06-10 11:47:34 -07:00