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

2316 commits

Author SHA1 Message Date
Yuya Nishihara
bbd49cdf29 tests: stabilize change id in test_resolve_symbol_commit_id()
Hopefully fixes #1024.
2023-01-14 23:49:16 +09:00
Yuya Nishihara
a3a495a140 cargo: drop dependency on "uuid" 2023-01-14 23:48:02 +09:00
Yuya Nishihara
ca2e9fe6d1 git: simply use rand::random() to generate ref preventing gc
We don't care the ref content as long as it is unique, so using threaded
RNG should be fine.

This change means refs/jj/keep will now contain refs of the following
forms:

 - new create_no_gc_ref(): 0f8d6cd9721823906cfb55dac99d7bf5
 - old create_no_gc_ref(): 0f6d93fe-0507-4db8-ad0a-6317f02e27b9
 - prevent_gc(commit_id):  0f9c15100b6f1373f38186357e274a829fb6c4e2
2023-01-14 23:48:02 +09: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
041b42ced6 formatter: rename current_style() to requested_style()
This hopefully clarifies the difference between the function and the
attribute called `current_style`.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
d33721d6fb formatter: rename {add,remove}_label to {push,pop}_label
The labels behave like a stack, and these names hopefully help clarify
that.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
25422b2abd formatter: replace HashMap by Vec for rules
We only ever iterate over the map, we never look up by key.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
fcbc791c3d formatter: add support for underlined text 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
e93a347f9e formatter: add support for bold text 2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
3b4ed096d0 formatter: add support for setting background color 2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
138798ce0a formatter: build style by overwriting matches in priority order
So far, configured color rules only support specifying foreground
color, and a better-matching rule completely overrides a worse
match. I'm about to add support for specifying other style attributes,
and I want a rule setting a background color not to be overridden by a
rule setting a foreground color. For that to work, it's not enough to
just find the best match, so this commit rewrites the algorithm for
finding the desired style so it finds all matching rules instead. It
then starts with the worst match and applies the other matches on top
of it in order or priority. I've implemented that priority to be in
order of the depth of matching labels, starting with deeper (more
specific) labels. The new algorithm doesn't care about how many labels
match.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
db5dbf3540 formatter: make Style::fg_color an Option
We want to be able combine styles by replacing only some of the
attributes (foreground color, underlining, etc.) in the config. We
could implement that having keeping the current style and then update
it based on what we find in the config for a label we just
added. However, it's simpler if we can parse a configured style
without knowing the current style and just return a `Style` with some
fields blank. This commit prepares for that by making the foreground
color field optional.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
2080913d15 formatter: accept foreground color config as {fg = "blue"} 2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
19e23c321b formatter: parse color config eagerly
It's simpler to parse the color config eagerly. It might also be
faster.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
c7b7b5c04b formatter: make room for other styles than foreground color
I'd like to add support for at least bold font, background color, and
underlining. This commit adds a `struct Style` to store that
information. For now, it just contains the foreground color.
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
fbab5e1bd9 formatter: extract repeated code for writing new color code
The implementations of `add_label()` and `remove_label()` had a lot of
duplicated code, and we would soon have more duplication if we didn't
extract it to shared function.
2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
4b80c259cf formatter: avoid updating unchanged self.current_color 2023-01-13 21:47:50 -08:00
Martin von Zweigbergk
8db8da5990 formatter: make color_for_name() a free function
The function doesn't use its `&self` argument anyway.
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
Martin von Zweigbergk
91fe6024b6 formatter: add unit tests
This includes a test for the non-deterministic case reported by
@ilyagr at
https://github.com/martinvonz/jj/pull/941#issuecomment-1363561554.
2023-01-13 21:47:50 -08:00
Yuya Nishihara
cd551bea34 backend: make random ChangeId fully random, remove UUID mask bits 2023-01-14 14:37:45 +09:00
Yuya Nishihara
2144870e5c backend: reimplement random ChangeId generator without using UUID 2023-01-14 14:37:45 +09:00
Yuya Nishihara
2e075f7de0 tests: for unit tests, simply generate unique ChangeId starting from 1
It's u128 just because Index::serialize() expects a 16-byte ChangeId. It
could be u32 with padding, but using u128 saved typing.
2023-01-14 14:37:45 +09:00
Michael Forster
3bd0c50090 Fix nix run
Otherwise nix 2.8 and newer will give this error message:

```
>> nix --version; nix run github:martinvonz/jj
nix (Nix) 2.11.1
error: attribute 'defaultApp.x86_64-linux' should have type 'derivation'
```
2023-01-13 15:40:31 -08:00
Ilya Grigoriev
d197eddea6 docs/working-copy.md: Mention jj resolve 2023-01-13 13:26:24 -08:00
dependabot[bot]
eff903634c cargo: bump prost-build from 0.11.5 to 0.11.6
Bumps [prost-build](https://github.com/tokio-rs/prost) from 0.11.5 to 0.11.6.
- [Release notes](https://github.com/tokio-rs/prost/releases)
- [Commits](https://github.com/tokio-rs/prost/compare/v0.11.5...v0.11.6)

---
updated-dependencies:
- dependency-name: prost-build
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-13 21:24:02 +00:00
dependabot[bot]
e6cdd69d83 cargo: bump pest_derive from 2.5.2 to 2.5.3
Bumps [pest_derive](https://github.com/pest-parser/pest) from 2.5.2 to 2.5.3.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.2...v2.5.3)

---
updated-dependencies:
- dependency-name: pest_derive
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-13 07:41:55 -08:00
Ilya Grigoriev
6b064ef54e run_merge_tool, edit_diff: Print command args with -v instead of errors 2023-01-12 23:07:59 -08:00
Martin von Zweigbergk
82829813d6 docs: don't recommend running cargo fmt in the background
Running `cargo fmt` while you're working in an editor means that you
may lose changes because of a race:

1. Your editor reads version X of file
2. `cargo fmt` reads version X
3. You save version Y from your editor
4. `cargo fmt` saves version Z, replacing Y
2023-01-12 11:50:02 -08:00
dependabot[bot]
a1591477bb cargo: bump pest from 2.5.2 to 2.5.3
Bumps [pest](https://github.com/pest-parser/pest) from 2.5.2 to 2.5.3.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.2...v2.5.3)

---
updated-dependencies:
- dependency-name: pest
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-12 09:28:52 -08:00
dependabot[bot]
c4f0f3cfc7 cargo: bump prost from 0.11.5 to 0.11.6
Bumps [prost](https://github.com/tokio-rs/prost) from 0.11.5 to 0.11.6.
- [Release notes](https://github.com/tokio-rs/prost/releases)
- [Commits](https://github.com/tokio-rs/prost/compare/v0.11.5...v0.11.6)

---
updated-dependencies:
- dependency-name: prost
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-12 09:28:25 -08:00
dependabot[bot]
eeac6632a2 cargo: bump git2 from 0.15.0 to 0.16.0
Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.15.0 to 0.16.0.
- [Release notes](https://github.com/rust-lang/git2-rs/releases)
- [Commits](https://github.com/rust-lang/git2-rs/compare/git2-curl-0.15.0...git2-curl-0.16.0)

---
updated-dependencies:
- dependency-name: git2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-12 09:28:02 -08:00
dependabot[bot]
9c0ad817ff cargo: bump zstd from 0.12.1+zstd.1.5.2 to 0.12.2+zstd.1.5.2
Bumps [zstd](https://github.com/gyscos/zstd-rs) from 0.12.1+zstd.1.5.2 to 0.12.2+zstd.1.5.2.
- [Release notes](https://github.com/gyscos/zstd-rs/releases)
- [Commits](https://github.com/gyscos/zstd-rs/commits)

---
updated-dependencies:
- dependency-name: zstd
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-12 09:26:50 -08:00
dependabot[bot]
7c1b796f3e github: bump github/codeql-action from 2.1.37 to 2.1.38
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.1.37 to 2.1.38.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](959cbb7472...515828d974)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-12 09:26:31 -08:00
Yuya Nishihara
32e3a87135 cli: add formatter.labeled() for short 2023-01-12 17:32:18 +09:00
Yuya Nishihara
a3438978a6 cli: migrate ui.write_error() to writeln!() 2023-01-12 17:32:18 +09:00
Yuya Nishihara
ea0c3930bb cli: migrate ui.write_warn() to writeln!() 2023-01-12 17:32:18 +09:00
Yuya Nishihara
4a28962aaa cli: migrate ui.write_hint() to writeln!() 2023-01-12 17:32:18 +09:00
Yuya Nishihara
99b84778ed cli: introduce wrapper to writeln!() a message with label
It's common to write a formatted error/warning message, but we can't use
writeln!() with the current ui.write_*() API, and sometimes we forget to
add "\n" to the message. With this wrapper, ui.write_error("message\n")
will be writeln!(ui.error(), "message"), and trivial formatter.with_label()
call can be replaced with write!(formatter.labeled(...), ...).
2023-01-12 17:32:18 +09:00
Yuya Nishihara
dfe861a5e7 cli: remove unused Formatter::write_from_reader()
It's unused, and we can use std::io::copy() instead.
2023-01-12 17:32:18 +09:00
Ilya Grigoriev
c0fc9a464a jj abandon: Print every abandoned commit
This can be disabled with the new `--quiet` option.

Printing every commit would give the user all the information of how to undo
this or where to `jj restore` from if they realize they need to after the
abandon.
2023-01-11 23:32:39 -08:00
Ilya Grigoriev
ef3071ba09 Improve short_commit_description for commits without a description 2023-01-11 23:32:39 -08:00
Ilya Grigoriev
6765850c7d jj abandon: Report what commit or how many commits were abandoned
There are not tests for `jj abandon`, and I haven't written any yet.
2023-01-11 23:32:39 -08:00
Ilya Grigoriev
c43f0a580a Add tests for the abandon command
I tested some hairy cases, but didn't add any simpler tests.
2023-01-11 23:32:39 -08:00
Ilya Grigoriev
9a3329ee25 jj resolve --list: make output aligned
If all file names are short enough, this will align the conflict
description at 4 spaces past the longest file name, as follows.

```
src/templater.rs            2-sided conflict
src/templater_parsers.rs    2-sided conflict
```

If there is a long file name, conflict descriptions will either start
or column 35 or one space from a file name, whichever is later.

Previously, a single tab was used to separate file name from conflict
description. This didn't look as nice as I hoped when multiple files
are involved. I also don't think `jj` generally uses tabs in output.
The tab uncovered a bug in a watcher program I was using.
2023-01-11 23:29:53 -08:00
Ilya Grigoriev
5b1b35cbfe Update test to prepare for next commit 2023-01-11 23:29:53 -08:00
David Barnett
e6b3b9c09b Add a config edit command to open jj config in editor
Part of #531 to define the overall `config` command.
2023-01-12 01:10:07 -06:00