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

67 commits

Author SHA1 Message Date
Martin von Zweigbergk
0075174308 tests: move tests/ under cli/ so they're run again
Thanks to @ilyagr for noticing that they should be moved.
2023-08-05 06:18:59 +00:00
Ilya Grigoriev
e667824ad9 cli templates: change default short id length from 12 to 8
This makes including the change id into the short
commit description in the following commit look less
noisy.
2023-08-02 12:14:04 -07:00
Martin von Zweigbergk
c183b94aef cli: warn when using : revset operator 2023-07-28 22:30:40 -07:00
Yuya Nishihara
b3ae7e7657 revset_graph: preserve original parents order
It seemed awkward if merged PR is sometimes rendered as a first branch.
Instead of sorting edges in index order, let's build a HashSet only when
deduplication is needed.
2023-07-29 05:36:09 +09:00
Yuya Nishihara
d3c031b277 tests: add helper method to capture both stdout/stderr outputs
This pattern is common, and should have a shorthand so that we can easily
add warning messages.
2023-07-03 22:03:05 +09:00
Yuya Nishihara
e601a30b15 cli: make log accept multiple -rREVISION expressions
For scripting scenario, multiple -r options are easier to construct than
concatenating expressions with ")|(".
2023-06-29 19:33:32 +09:00
Waleed Khan
0fff404fb2 cleanup: fix clippy issues 2023-06-05 11:11:17 -05:00
Martin von Zweigbergk
fb17e6a50e revset: use different errors for ambiguous commit/change IDs
I made a typo and got something like this:

```
Error: Commit or change id prefix "wl" is ambiguous
```

Since we can tell commit ids from change ids these days, let's make
the error message say which kind of id it is. Changing that also kind
of forced me to make a special error for empty strings. Otherwise we
would have to arbitrarily say that an empty string is a commit id or
change id. A specific error message for empty strings seems helpful,
so that's probably for the better anyway.
2023-05-31 06:28:32 -07:00
Martin von Zweigbergk
6a9b527987 tests: test lookup of prefixes from the log output just about
It's easier to follow the test if we try to resolve commits from the
`jj log` output just above. That's what we did until I changed it away
from that without thinking in fcda05c69b.
2023-05-22 07:02:32 -07:00
Martin von Zweigbergk
5d2872d76f tests: restore effectiveness of prefix among hidden commits
When I added `revsets.short-prefixes` in 20ef171d7a, I didn't notice
that I made the test of commit prefixes among hidden commits
ineffective because. This restores that by disabling short prefixes in
the test.
2023-05-22 07:02:32 -07:00
Martin von Zweigbergk
eab5218fe5 cli: allow resolving shorter ids within a configured revset
This adds a config called `revsets.short-prefixes`, which lets the
user specify a revset in which to disambiguate otherwise ambiguous
change/commit ids. It defaults to the value of `revsets.log`.


I made it so you can disable the feature by setting
`revsets.short-prefixes = ""`. I don't like that the default value
(using `revsets.log`) cannot be configured explicitly by the
user. That will be addressed if we decide to merge the `[revsets]` and
`[revset-aliases]` sections some day.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
ac31c83e13 cli: rename ui.default-revset to revsets.log
I plan to add `revsets.short-prefixes` and `revsets.immutable` soon,
and I think `[revsets]` seems like reasonable place to put them. It
seems consistent with our `[templates]` section. However, it also
suffers from the same problem as that section, which is that the
difference between `[templates]` and `[template-aliases]` is not
clear. We can decide about about templates and revsets later.
2023-05-11 23:41:24 -07:00
Ilya Grigoriev
0e2579ee6a Switch graph node to use for commit instead of
This follows up on 5c703aeb03.

The only reason for this change is that, subjectively, the result looks better to me. I'm not sure why, but I couldn't get used to the old symbol in spite of its seeming reasonableness. It felt really bold and heavy.

If people agree, we can wait until we need to update the screenshots for some other reason before merging this. Sorry I didn't figure this out while the discussion about the referenced commit was going on.

I'm not 100% certain how many fonts support each symbol. Please try it out and let me know if it doesn't work for you.

Compare after:

![image](https://user-images.githubusercontent.com/4123047/229251383-563b889d-7233-42e2-a3c5-bf9368a4d1fd.png)

and before:

![image](https://user-images.githubusercontent.com/4123047/229251695-7fd0ff2c-2832-4262-ade5-5120288cccdf.png)
2023-04-02 23:15:37 -07:00
Martin von Zweigbergk
8f1dc49039 cargo: upgrade to clap 4.1
This includes some changes to error messages. Also, the Zsh shell
completion script is now simpler to source.

Fixes #1393.
2023-03-17 22:44:29 -07:00
Martin von Zweigbergk
ed1c2ea1aa cli: disallow jj diff --color-words --git 2023-03-16 08:01:13 -07:00
Martin von Zweigbergk
5c703aeb03 cli: replace o as graph node by when using unicode graph
@joyously found `o` confusing because it's a valid change id prefix. I
don't have much preference, but `●` seems fine. The "ascii",
"ascii-large", and "legacy" graph styles still use "o".

I didn't change `@` since it seems useful to have that match the
symbol used on the CLI. I don't think we want to have users do
something like `jj co ◎-`.
2023-03-12 23:21:05 -07:00
Yuya Nishihara
904e9c5520 cli: add ui.log-word-wrap option
Unlike Mercurial, this isn't a template keyword/function, but a config knob.
Exposing graph_width to templater wouldn't be easy, and I don't think it's
better to handle terminal wrapping in template.

I'm not sure if patch content should be wrapped, so this option only applies
to the template output for now.

Closes #1043
2023-03-11 12:01:17 +09:00
Yuya Nishihara
66458a097e templater: require infix ++ operator to concatenate expressions
This eliminates ambiguous parsing between "func()" and "expr ()".

I chose "++" as template concatenation operator in case we want to add
bit-wise negate operator. It's also easier to find/replace than "~".
2023-03-01 16:39:23 +09:00
Yuya Nishihara
6bbf4c6fcf tests: extract log template function/variable for code readability
Also rewrites some lengthy templates. That's why the test output slightly
changed.
2023-03-01 16:39:23 +09:00
Yuya Nishihara
3c61e9239c config: remove ui.log-author-format in favor of template alias 2023-02-16 11:43:17 +09:00
Yuya Nishihara
7913f90869 templater: remove "brackets" short id style in favor of template alias
Though .prefix() + .rest() has to call .shortest() twice, I don't think
the added cost would be significant.
2023-02-16 11:43:17 +09:00
Yuya Nishihara
ed4a696dea templater: add shortest().prefix()/rest() accessors
This ensures that the "brackets" style can be emulated by a template
expression.
2023-02-16 11:43:17 +09:00
Martin von Zweigbergk
81af5f820b repo: calculate shortest unique prefix separately for commit/change
We now resolve the two kinds of ids in separate spaces, so the
shortest prefixes should also be calculated in separate spaces.
2023-02-13 22:49:21 -08:00
Martin von Zweigbergk
9887d2c3d6 templater: use reverse-alphabet hex for change ids 2023-02-13 22:49:21 -08:00
Martin von Zweigbergk
a67fbb6714 cli: switch default graph style to be Sapling's curved style
We seem to quite unanimously prefer this style, so let's make the
default.
2023-02-12 07:23:29 -08:00
Vamsi Avula
daf7b656e3 config: add and parse ui.log_author_format for use in the default template
Supported values are,

- `none` for no author information,
- `full` for both the name and email,
- `name` for just the name,
- `username` for username part of the email,
- (default) `email` (or any other gibberish for that matter) for the full email.
2023-02-11 20:54:23 +05:30
Yuya Nishihara
cd164be762 templater: inline extract_entire_prefix_and_trimmed_tail() and simplify 2023-02-07 11:42:39 +09:00
Yuya Nishihara
ebf9887d65 templater: migrate shortest_prefix_and_brackets() over shortest() 2023-02-07 11:42:39 +09:00
Yuya Nishihara
3ccac9cda5 templater: rename shortest_styled_prefix() to shortest()
Now it is the true "shortest prefix" function with the default parameter,
so let's simply call it "shortest()".
2023-02-07 11:42:39 +09:00
Martin von Zweigbergk
fcda05c69b tests: reduce subprocessing in unique-prefix tests
The unique-prefixe tests are typically the slowest tests. Here's the
end of my `cargo nextest --workspace` output (from an arbitrary run,
not best-of-5 or anything):

PASS [   5.129s] jujutsu::test_log_command test_log_prefix_highlight_brackets
PASS [   5.220s] jujutsu::test_log_command test_log_prefix_highlight_styled
PASS [   8.523s] jujutsu::test_log_command test_log_prefix_highlight_counts_hidden_commits

These tests create 50-100 commits in a loop. I think much of it comes
from the subprocessing and/or the repeated loading of the repository
in the subprocesses. Rewriting them to use `jj duplicate` for creating
many commits at once speeds them up. Here are the timings after:

PASS [   2.323s] jujutsu::test_log_command test_log_prefix_highlight_styled
PASS [   2.330s] jujutsu::test_log_command test_log_prefix_highlight_brackets
PASS [   3.773s] jujutsu::test_log_command test_log_prefix_highlight_counts_hidden_commits
2023-02-06 12:32:23 -08:00
Martin von Zweigbergk
8d3d89facc cli: rename diff.format to ui.diff.format
I felt that the config is too narrow to have it's own top-level [diff]
section, and I couldn't think of another good place to have it. I'm
happy to hear other suggestions.
2023-02-05 23:36:30 -08:00
Ilya Grigoriev
de163216c0 Templater: make shortest id functions default to 0 length
This makes them print the shortest unique prefix only.
2023-02-05 22:15:27 -08:00
Ilya Grigoriev
58828803d4 Templater: Give shortest id functions a total_len argument. 2023-02-05 21:18:42 -08:00
Yuya Nishihara
e2a5a14463 cli: use label() to highlight "working_copy" commit in log template
I think this is a proper way to label the working-copy commit. This also
fixes "jj obslog" output, but I don't think anyone would care.
2023-02-04 01:58:13 +09:00
Yuya Nishihara
e63ea86841 templater: do not complete "(no commit description)" by default
This allows us to use "if(description,)" to test empty description. And
I think this change is unavoidable if we want to add support for commit
template.
2023-02-01 16:13:43 +09:00
Ilya Grigoriev
3ee87aa5a7 Rename short => shortest 2023-01-30 22:48:38 -08:00
Martin von Zweigbergk
d8942d5f96 cli: rename ui.graph.format to ui.graph.style
I think of it more as style than a format, so using `style` in the
config key makes sense to me.

I didn't bother making upgrades easy by supporting the old name since
this was just released and only a few developers probably have it set.
2023-01-27 10:36:26 -08:00
Martin von Zweigbergk
0b99e5b16e graphlog: enable Sapling's graph styles by default
I would also rename the feature, but I hope we can instead soon make
it a non-optional dependency and delete the feature.
2023-01-27 09:46:57 -08:00
Martin von Zweigbergk
3ccdd1f98a tests: pass string instead of bytes to add_config()
I don't think need to write non-UTF8 bytes to our config files. If we
ever do (maybe to test that we give the user a reasonable error
message), we add a custom function for that.
2023-01-26 12:48:30 -08:00
Martin von Zweigbergk
e1d49cc67f tests: use dotted notation in TOML when it saves lines 2023-01-26 12:48:30 -08:00
Yuya Nishihara
a7541e1ba4 repo: add workaround for shortest prefix calculation of root ids
This is ugly, but we need a special case because root_change_id and
root_commit_id aren't equal but share the same prefix bytes. In practice,
no one would care for the shortest root id prefix, but we'll need to deal
with a similar problem when migrating prefix id resolution to repo layer.
2023-01-22 12:03:08 +09:00
Yuya Nishihara
139fe08419 templater: fix id of brackets-prefix format to respect total length
I think the intent of '- 1' here is the separator length, which was
originally ':'. Alternatively, we can ensure that prefix + remainder is
always 12 chars.
2023-01-19 16:41:50 +09:00
Ilya Grigoriev
19d341d32a Templater: naive implementation of shortest prefix highlight for ids
This creates a templater function `short_underscore_prefix` for commit and
change ids. It is similar to `short` function, but shows one fewer hexadecimal
digit and inserts an underscore after the shortest unique prefix.

Highlighting with an underline and perhaps color/bold will be in a follow-up
PR.

The implementation is quadratic, a simple comparison of each id with every
other id. It is replaced in a subsequent commit. The problem with it is that,
while it works fine for a `jj`-sized repo, it becomes is painfully slow with a
repo the size of git/git. 

Still, this naive implemenation is included here since it's simple, and could
be used as a reference implementation. 

The `shortest_unique_prefix_length` function goes into `repo.rs` since that's
convenient for follow-up commits in this PR to have nicer diffs.
2023-01-17 22:01:09 -08:00
Martin von Zweigbergk
31ad0cd2ed formatter: reset color around newlines
There are several reasons for this:

 * We can more easily skip styling a trailing blank line, which other
   internal code then can correctly detect as having a trailing
   newline. This fixes the TODO in tests/test_commit_template.rs.

 * Some tools (like `less -R`) add an extra newline if the final
   character is not a newline (e.g. if there's a color reset after
   it), which led to an annoying blank line after the diff summary in
   e.g. `jj status`.

 * Since each line is styled independently, you get all the necessary
   escapes even when grepping through the output.

 * Some terminals extend background color to the end of the terminal
   (i.e. past the newline character), which is probably not what the
   user wanted.

 * Some tools (like `less -R`) get confused and lose coloring of lines
   after a newline.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
6ae671960c formatter: don't write escape codes until we write text
We often end up writing escape codes for one style and then
immediately after, we write escape codes for another style. That seems
harmless, but it's a little ugly. More importantly, it prepares for
not emitting any escapes for turning off attributes at the end of
formatted contents across multiple lines (see next commit).
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
2a9c37a693 formatter: remove hack for making bright colors bold
We can now configure the working-copy commit and the head operation to
use bold font, so we no longer need the hack to make bright colors
bold.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
5cf2b6615a formatter: use crossterm for colors
Let's use `crossterm` to make `ColorFormatter` a little more readable,
and maybe also more portable.

This uses the `SetForegroundColor()` function, which uses the escapes
for 256-color support (code 38) instead of the 8-color escapes (codes
30-37) combined with bold/bright (code 1) we were using before. IIUC,
most terminals support the 16 base colors when using the 256-color
escape even if they don't support all the 256 colors. It seems like an
improvement to use actual color codes for the bright colors too,
instead of assuming that terminals render bold as bright (even though
most terminals do).

Before this commit, we relied on ANSI escape 1 - which is specified to
make the font bold - to make the color brighter. That's why we call
the colors "bright blue" etc. When we switch from using code 30-37 to
using 38 to let our color config just control the color (not using
escape1), we therefore lose the bold font on many terminals (at least
in iTerm2 and in the terminal application on my Debian work
computer). As a workaround, I made us still use escape 1 when the
bright colors are used. I'll make boldness a separately configurable
attribute soon. Then we'll be able to remove this hack.

With the switch to `crossterm`, we also reset just the foreground
color (code 39) instead of resetting all attributes (code 0). That
also seems like an improvement, probably making it easier for us to
later support different background colors, underlining, etc.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
efd652d7ea log: add test showing bugs in graph when the template uses color 2023-01-13 21:47:50 -08:00
Ilya Grigoriev
a43c47a28c Move a test from test_log_command to test_commit_template 2023-01-09 22:44:45 -08:00
Martin von Zweigbergk
1b4992e11c tests: create new file for tests of commit template
An important part of the `jj log` output is the commit template. I
suspect we'll have many more tests for that, so let's move it to a
separate file. The main `test_log_command.rs` can focus on which
commits to display.
2023-01-08 12:32:31 -08:00