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

39 commits

Author SHA1 Message Date
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
Yuya Nishihara
ea96ea3ffe cli: load configs from .jj/repo/config.toml
Since per-repo config may contain CLI settings, it must be visible to CLI.
Therefore, UserSettings::with_repo() -> RepoSettings isn't used, and its
implementation is nullified by this commit.

#616
2023-01-07 11:33:12 +09:00
Ilya Grigoriev
30d98974bb Make change ids in tests repeatable
This will be needed to test functionality for showing shortest
unique prefix for commit and change ids. As a bonus, this also
allows us to test log output with change ids.

As another bonus, this will prevent occasional CI failures like
https://github.com/martinvonz/jj/actions/runs/3817554687/jobs/6493881468.
2023-01-03 23:02:46 -08:00
Ilya Grigoriev
9974d67da2 Test jj log for divergent commits
It turns out we did not have tests that would catch `jj log` failing
to mark divergent commits.
2023-01-02 00:08:55 -08:00
Yuya Nishihara
cec4d6c214 cli: allow multiple diff outputs
"jj log -p --summary" now shows summary and color-words diff, like
"hg log -p --stat".

Handling of "-p" is tricky. I first considered "-p" would turn on the default
diff output, but I found it would be confusing if "jj log -p --git" showed
both color-words and git diffs. So the default format is inserted only if
no --git nor --color-words is explicitly specified.
2022-12-15 11:41:42 +09:00
Yuya Nishihara
69e57daa64 cli: enable diff output by 'log --color-words'
It doesn't make sense that --git implies -p, but --color-words doesn't.
2022-12-15 11:41:42 +09:00
Martin von Zweigbergk
b32598e989 cli: require revision arguments to be non-empty strings
I can't see any reason the user would want to specify revisions
matching the empty string, so let's disallow it. I created a custom
type for revision arguments instead of repeating `value_parser =
NonEmptyStringValueParser::new()`.
2022-11-28 09:17:43 -10:00
Martin von Zweigbergk
d8feed9be4 copyright: change from "Google LLC" to "The Jujutsu Authors"
Let's acknowledge everyone's contributions by replacing "Google LLC"
in the copyright header by "The Jujutsu Authors". If I understand
correctly, it won't have any legal effect, but maybe it still helps
reduce concerns from contributors (though I haven't heard any
concerns).

Google employees can read about Google's policy at
go/releasing/contributions#copyright.
2022-11-28 06:05:45 -10:00
Ruben Slabbert
01817e4321 feature: support relative timestamps as a config option 2022-11-27 08:35:17 +10:00
Waleed Khan
94815a7cb5 log: warn if the provided path looks like a revset 2022-11-21 16:42:48 -08:00
Yuya Nishihara
cb2fcde560 revset: implement file(pattern[, candidates]) predicate
The name "file()" is just copied from hg. I'm not sure if it's good in
jj's context, but I couldn't find a better name.
2022-10-24 01:48:00 +09:00
Tal Pressman
621caa4dcb add default log revset configuration setting 2022-10-02 16:56:18 +09:00
Yuya Nishihara
c9c3735faf cli: add basic support for 'jj log PATH'
In the current implementation, tree is diffed twice if both PATH and -p
are specified. If this adds significant cost, we'll need to reimplement
it without using a revset abstraction (or maybe adjust revset/graph API.)
2022-09-16 13:02:58 +09:00
Martin von Zweigbergk
0865b1ccff cli: show placeholder text for empty commit message
It can be confusing that some commits (typically the working copy)
don't have a description. Let's show a placeholder text in such cases.

I chose the format to match the "(no email configured)" message we
already have.
2022-05-18 09:16:04 -07:00
Martin von Zweigbergk
6c83eb6ae3 cli: teach log flag to show commits in reverse order
This adds a `--reversed` flag to `jj log` to show commits with later
commits further down. It works both with and without the graph.

Since the graph-drawing code is already independent of the
relationship between commits, it doesn't need any updating.
2022-05-15 05:17:54 -07:00
Martin von Zweigbergk
87ba11592b cli: make log -s/--git imply -p
`log -s/--summary` and `log --git` without `-p` don't do anything. I
also don't think it's very useful to pass these flags in an alias,
where you would then sometimes also pass `-p` to see the diff summary
in the output. We already have the `diff.format` config for that use
case. So let's make both of these flags imply `-p`.

I implemented it by making the `diff_format` variable an
`Option<DiffFormat>`, which is set iff we should show a patch. That
way we have the condition in one place, and the places we use it
cannot forget to check it.
2022-05-13 03:19:10 -07:00
Martin von Zweigbergk
710d51c45b tests: move testutils from src/ to tests/ 2022-04-02 14:22:58 -07:00
Yuya Nishihara
a7e3269ed8 log: add -p/--patch option to show diff along with commit meta data
"log -p | less" is the option I often use with hg/git to find interesting
bits from the changelog, and I think it's also valid with jj. Unlike
"hg log -p --stat", "jj log -p --summary" does not show both diff summary
and patch to reflect the internal structure. This behavoir is arguable and
may be changed later.

The logic of show_patch() is extracted from cmd_show().
2022-03-30 16:24:34 -07:00