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

2299 commits

Author SHA1 Message Date
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
Martin von Zweigbergk
697b91243d cli: simplify logic for using short change ID with jj git push --change
The main trick for simplifying this was to move the block printing
"Creating branch ..." outside its current parent block.
2023-01-11 22:53:04 -08:00
Vamsi Avula
1aad250420 Shorten the git push branch when possible using the short change ID hash. 2023-01-12 11:45:13 +05:30
Yuya Nishihara
ba7016788f cli: fix highlighting of checkout commit in "log --no-graph" 2023-01-11 11:33:28 +09:00
dependabot[bot]
fb6181f212 cargo: bump assert_cmd from 2.0.7 to 2.0.8
Bumps [assert_cmd](https://github.com/assert-rs/assert_cmd) from 2.0.7 to 2.0.8.
- [Release notes](https://github.com/assert-rs/assert_cmd/releases)
- [Changelog](https://github.com/assert-rs/assert_cmd/blob/master/CHANGELOG.md)
- [Commits](https://github.com/assert-rs/assert_cmd/compare/v2.0.7...v2.0.8)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-10 08:25:05 -08:00
Yuya Nishihara
cb0b9e590a cli: do not search ancestor paths specified by -R/--repository
If a workspace path is explicitly specified, it must point to the exact
workspace directory. This is the same behavior as 'hg -R'. OTOH, 'git -C'
is the option to chdir, so it makes sense to search .git from that directory.

This also fixes 'jj -R ../..' which would previously look up '../..', '..',
'.', ...
2023-01-10 23:31:26 +09:00
Yuya Nishihara
40a9f75441 workspace: do not look up ancestor paths by Workspace::load()
I don't think Workspace::load() should be permissive in that regard.
WorkspaceLoader could provide such function, but I feel it's more like
CLI business. CLI can also look for parent '.git' directory to suggest
'jj init --git-repo=..' if needed.
2023-01-10 23:31:26 +09:00
Ilya Grigoriev
65de7cb0eb jj log: Change conflicted branches from br? to br??
The divergent changes are marked with ?? (I found a single ? a bit easy to
overlook), and this should be consistent.

Ideally, the conflicted branches would also be red, but this takes a bit
larger changes to `templater.rs`: another `Property` as well as changes to
https://github.com/martinvonz/jj/blob/7f9a0a28/src/template_parser.rs#L385-L395
2023-01-09 22:44:45 -08:00
Ilya Grigoriev
8093bc0614 jj log: Replace divergent label with ?? and red color
This follows up on a [discussion] in a previous PR #941.

[discussion]: https://github.com/martinvonz/jj/pull/941#issuecomment-1363551162

Screenshot: https://user-images.githubusercontent.com/4123047/209286340-bb83df2d-4020-4608-9755-d965477799c3.png
2023-01-09 22:44:45 -08:00
Ilya Grigoriev
5f2a99ac8a Test commit template with divergence 2023-01-09 22:44:45 -08:00
Ilya Grigoriev
a43c47a28c Move a test from test_log_command to test_commit_template 2023-01-09 22:44:45 -08:00
Yuya Nishihara
cef5e8795c cli: use .display() to stringify RepoDoesNotExist error 2023-01-10 11:51:29 +09:00
Yuya Nishihara
d798213cc8 cli: do not look up workspace path more than once, reuse WorkspaceLoader 2023-01-10 11:51:29 +09:00
Yuya Nishihara
c3903cb914 cli: wrap clap::Error within Arc to make CommandError cloneable
This allows us to load workspace by using &Result<T, CommandError>. Even
though load_workspace() wouldn't be called more than once, consuming self
there is annoying.
2023-01-10 11:51:29 +09:00
dependabot[bot]
1df1603b0b cargo: bump regex from 1.7.0 to 1.7.1
Bumps [regex](https://github.com/rust-lang/regex) from 1.7.0 to 1.7.1.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.7.0...1.7.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-09 08:54:02 -08:00
dependabot[bot]
b85e4e136f cargo: bump insta from 1.24.1 to 1.26.0
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.24.1 to 1.26.0.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.24.1...1.26.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-09 08:53:09 -08:00
Martin von Zweigbergk
9257cc34e5 formatter: don't allow rules to match labels out of order
I don't see a good reason to let e.g. "added diff" to match added text
inside a diff when we already allow "diff added" for that. Allowing
both means that we have to decide which should take precedence. With
the recent change to add labels for methods, we no longer depend on it
for the "timestamp author" case ("author timestamp" now
matches). Thanks to @yuja for noticing that dependency.
2023-01-08 23:01:53 -08:00
Martin von Zweigbergk
f46030e549 log: remove redundant "timestamp" label from default template
We now already have the "timestamp" label from the auto-labeling of
method calls.

Without the use of the "email" label in the previous commit, we would
now emit an unnecessary color code when the "author" label is added
but before the "timestamp" is added. So that patch wasn't just about
simplifiying the config :)
2023-01-08 23:01:53 -08:00