Commit Graph

2944 Commits

Author SHA1 Message Date
dependabot[bot]
08d0a33554 github: bump github/codeql-action from 2.2.6 to 2.2.7
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.2.6 to 2.2.7.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](16964e90ba...168b99b3c2)

---
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-03-15 10:01:04 -07:00
Yuya Nishihara
86318bf530 templater: add timestamp.format() method
A format string is parsed statically due to error handling restriction.
I think it covers almost all use cases.
2023-03-15 12:14:42 +09:00
Yuya Nishihara
b6a5d63b09 time_util: add functions to parse format spec and apply it later
In templater, it's easier to handle invalid format string at parsing stage, so
I want to build formatting items upfront. Since the formatting items borrow
the input string by reference, we need to manually convert them to the owned
variants.
2023-03-15 12:14:42 +09:00
Yuya Nishihara
731a94e4f2 time_util: cache parsed result of default time format
While measuring overhead of interpreter version of the template engine, I
noticed the templater spend some time in chrono. I don't think this would
matter in practice, but it's easy to cache the formatting items.

    % jj log -r'all()' -T'".\n"' --no-graph | wc -l
    2996

    % hyperfine --warmup 3 --runs 20 "jj log --ignore-working-copy -r 'all()' -Tshow --no-graph"
    (original)
      Time (mean ± σ):     120.0 ms ±  18.7 ms    [User: 97.5 ms, System: 22.5 ms]
      Range (min … max):    96.7 ms … 144.1 ms    20 runs
    (new)
      Time (mean ± σ):     106.2 ms ±  12.3 ms    [User: 86.1 ms, System: 20.1 ms]
      Range (min … max):    96.3 ms … 130.4 ms    20 runs

Regarding the template engine rewrites, I'm yet sure that the interpreter
version is strictly better. It's simpler, but could make some caching story
difficult. So I'm not gonna replace the engine anytime soon.
2023-03-15 12:14:42 +09:00
Martin von Zweigbergk
5afe5091a0 revset: add default_ prefix to graph iterator module
The current revset graph iterator is the default one, which the
default revset engine provides.
2023-03-14 05:32:02 -07:00
Martin von Zweigbergk
3871efd2f9 revset: move ReverseRevsetGraphIterator into revset module
The iterator is not specific to the implementation in
`revset_graph_iterator`, so it belongs in the standard `revset`
module.
2023-03-14 05:32:02 -07:00
Martin von Zweigbergk
f62fac24ac revset: move graph iteration onto Revset trait
We want to allow custom revset engines define their own graph
iterator. This commit helps with that by adding a
`Revset::iter_graph()` function that returns an abstract iterator.

The current `RevsetGraphIterator` can be configured to skip or include
transitive edges. It skips them by default and we don't expose option
in the CLI. I didn't bother including that functionality in the new
`iter_graph()` either. At least for now, it will be up to the
implementation whether it includes such edges (it would of course be
free to ignore the caller's request even if we added an option for it
in the API).
2023-03-14 05:32:02 -07:00
Martin von Zweigbergk
28cbd7b1c5 revset: move evaluation into index
This commit adds an `evaluate_revset()` function to the `Index`
trait. It will require some further cleanup, but it already achieves
the goal of letting the index implementation decide which revset
engine to use.
2023-03-14 05:32:02 -07:00
Martin von Zweigbergk
eed0b23009 revset: move current implementation to new module
We want to allow customization of the revset engine, so it can query
server indexes, for example. The current revset implementation will be
our default implementation for now. What's left in the `revset` module
after this commit is mostly parsing code.
2023-03-14 05:32:02 -07:00
dependabot[bot]
a99622763f github: bump github/codeql-action from 2.2.5 to 2.2.6
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.2.5 to 2.2.6.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](32dc499307...16964e90ba)

---
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-03-13 17:43:41 +00:00
dependabot[bot]
1e55fa6c9b cargo: bump whoami from 1.3.0 to 1.4.0
Bumps [whoami](https://github.com/ardaku/whoami) from 1.3.0 to 1.4.0.
- [Release notes](https://github.com/ardaku/whoami/releases)
- [Changelog](https://github.com/ardaku/whoami/blob/stable/CHANGELOG.md)
- [Commits](https://github.com/ardaku/whoami/compare/v1.3.0...v1.4.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-13 10:42:22 -07:00
dependabot[bot]
c47ffa43f0 cargo: bump serde from 1.0.154 to 1.0.155
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.154 to 1.0.155.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.154...v1.0.155)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-13 10:42:05 -07:00
dependabot[bot]
f5de5707b2 cargo: bump chrono from 0.4.23 to 0.4.24
Bumps [chrono](https://github.com/chronotope/chrono) from 0.4.23 to 0.4.24.
- [Release notes](https://github.com/chronotope/chrono/releases)
- [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chronotope/chrono/compare/v0.4.23...v0.4.24)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-13 10:41:49 -07:00
dependabot[bot]
3b40231285 cargo: bump toml_edit from 0.19.4 to 0.19.5
Bumps [toml_edit](https://github.com/ordian/toml_edit) from 0.19.4 to 0.19.5.
- [Release notes](https://github.com/ordian/toml_edit/releases)
- [Commits](https://github.com/ordian/toml_edit/compare/v0.19.4...v0.19.5)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-13 10:41:21 -07:00
Martin von Zweigbergk
6a57456067 revset: remove is_empty() implementation from trait
Now that there's a single implementation of `Revset`, I think it makes
more sense for `is_empty()` to be defined there. Maybe different
revset engines have different ways of implementing it. Even if they
don't, this is trivial to re-implement in each revset engine.
2023-03-13 07:20:35 -07:00
Martin von Zweigbergk
2d1b13b338 revset: make ToPredicateFn private, decouple public type from private
As the comment above `ToPredicateFn` says, it could be a private
type. This commit makes that happen by making the private `Revset`
implementations (`DifferenceRevset` etc.) instead implement an
internal revset type called `InternalRevset`. That type is what
extends `ToPredicateFn`, so the public type doesn't have to. The new
type will not need to implement the new functions I'm about to add to
the `Revset` trait.
2023-03-13 07:20:35 -07:00
Martin von Zweigbergk
9e6c139fa0 revset: create wrapper for current revset implementation
We don't want the public `Revset` interface to know about
`ToPredicateFn`. In order to hide it, I'm wrapping the internal type
in another type, so only the internal type can keep implementing
`ToPredicateFn`.
2023-03-13 07:20:35 -07:00
Martin von Zweigbergk
6c9cefb8a0 revset: make evaluate_revset() private and use it internally
I'd like to be able to change the return type of `evaluate_revset()`
to be an internal type. Since all external callers currently call the
function via `RevsetExpression::evaluate()`, it turns out it's easy to
make it private. To benefit from an internal type, we also need to
make the recursive calls be directly to the internal function.
2023-03-13 07:20:35 -07:00
Martin von Zweigbergk
ada48c6f71 revset: rename file() test for consistency
This should have been part of bbd6ef0c7b.
2023-03-13 07:20:35 -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
Martin von Zweigbergk
82101bc7e0 cli: let graphlog provide a default node symbol
I'm about to make the default (non-working-copy) node symbol be a
unicode symbol, but we only want that when using a unicode graph, so
users with a terminal that doesn't support unicode can get plain ASCII
output by setting e.g. `ui.graph.style = "ascii"`.
2023-03-12 23:21:05 -07:00
Martin von Zweigbergk
cb86efac61 demos: clarify command for finding operation to undo
The command grepped for 'o ' and picked the third line. That was meant
to match the graph nodes only, but it also matched the 'jj co master'
line. Let's match only 'o' at the beginning of the line, and throw in
another space for good measure (since that's what we get from the new
default graph style from Sapling).
2023-03-12 23:21:05 -07:00
Martin von Zweigbergk
74ffe7f688 index: remove num_commits() from API 2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
0a7de2540f tests: call num_commits() on specific implementation
This removes the last calls to `Index::num_commits()`.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
efc9cc9885 cli: avoid a call to Index::num_commits()
I'm trying to remove the function from the trait.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
52e4bee3fe index: remove stats() from API
The `stats()` function is specific to the default implementation, so
it shouldn't be part of the `Index` trait.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
5423feb8e1 tests: call stats() on specific implementation
This removes the remaining calls to `Index::stats()`.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
59b40d8380 tests: avoid some unnecessary calls to index().stats()
The tests adding and removing heads to the repo mostly want to verify
that the set of heads is expected. Some of them also check that
commits are available in the index. But they shouldn't care about the
exact index stats.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
121b86c89c tests: remove an obsolete TODO about unreachable commits in index
I don't think there's much to gain from making the index match exactly
what's reachable from the view. FWIW, our cloud-based implementation
at Google will probably make everyone's commits visible in the index
regardless of which operation they're at.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
8c5c0f0e83 cli: make jj debug index get stats from specific implementation
We don't want custom index implementations to have to conform to the
same kind of stats as the default implementation. This commit also
makes the command error out on non-default index types.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
504a2b3fd0 cli: add test of jj debug reindex, do full reindexing
I broke the commands in a27da7d8d5 and thought I just fixed it in
c7cf914694a8. However, as I added a test, I realized that I made it
only reindex the commits since the previous operation. I meant for the
command to do a full reindexing of th repo. This fixes that.
2023-03-12 22:08:31 -07:00
Yuya Nishihara
23bed2731c templater: extract evaluation interface and build_() functions to new module
I'm thinking of rewriting the evaluation part as a simple interpreter. It
will increase the runtime cost (about a few microseconds per entry I suppose),
but will greatly reduce the complexity of generic property function chaining.

The extracted template_builder module is the part I'm going to reimplement.
2023-03-13 11:45:17 +09:00
Yuya Nishihara
91d309a93c templater: extract little helper that parses text and expands aliases
The caller doesn't have to care about alias expansion.
2023-03-13 11:45:17 +09:00
Yuya Nishihara
b380ca0cf7 templater: move split_email() to text_util module
It's not specific to templating.
2023-03-13 11:45:17 +09:00
Martin von Zweigbergk
63b3c0899a index: make jj debug reindex actually reindex
I broke `jj debug reindex` in a27da7d8d5. From that commit, we no
longer delete the pointer to the old index, so nothing happens when we
reload the index. This commit fixes that, and also makes the command
error out if run on a repo with a non-default index type.
2023-03-12 03:23:59 -07:00
Martin von Zweigbergk
ff1b6ce3d1 index: extract a MutableIndex trait
This is yet another step towards making the index pluggable. The
`IndexStore` trait seems reasonable after this commit. There's still a
lot of work to remove `IndexPosition` from the `Index` trait.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
b02fac7786 index: drop pub keyword from functions on private types
It has no effect, and these functions were not meant to be public.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
65a6353f06 index: stop implementing Index trait on wrapper type
Since `ReadonlyIndex` and `Index` are different types, we don't need
to implement `Index` on `ReadonlyIndexWrapper`.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
2eab85964a index: extract a ReadonlyIndex trait
I didn't make `ReadonlyIndex` extend `Index` because it needed an
`as_index()` to convert to `&dyn Index` trait object
anyway. Separating the types also gives us flexibility to implement
the two traits on different types.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
d2457d3f38 index: wrap ReadonlyIndex in new type, hiding Arc
Not all index implementations may want to store the readonly index
implementation in an Arc. Exposing the Arc in the interface is also
problematic because `Arc<IndexImpl>` cannot be cast to `Arc<dyn
Index>`.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
6ab8d9d0d0 index: merge index_store.rs into index.rs
These two files are closely related, and `Index` and `IndexStore` are
expected to be customized together, so it seems better to keep them in
a single file.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
e5ba9d9e42 index: move current implementation to default_index_store.rs
The idea is that `index.rs` contains the interface, similar to
`backend.rs` for commits, and `op_store.rs` for operations.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
8fc2062a38 index: move DefaultIndexStore to new default_index_store.rs 2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
37151e0ff9 index: load store based on type recorded in .jj/repo/index/type
This is another step towards allowing a custom `jj` binary to have its
own index type. We're going to have a server-backed index
implementation at Google, for example.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
3e4e0dc916 index_store: extract trait
This is a step towards making the index storage pluggable. The
interface will probably change a bit soon, but let's start with
functions that match the current implementation.

I called the current implementation the `DefaultIndexStore`. Calling
it `SimpleIndexStore` (like `SimpleOpStore` and `SimpleOpHeadsStore`)
didn't seem accurate.
2023-03-11 22:22:46 -08: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
2a32d81542 graphlog: expose width() method to precompute graph width 2023-03-11 12:01:17 +09:00
Yuya Nishihara
6539381155 ui: allow to override terminal width with $COLUMNS variable
Writing text wrapping tests would be difficult without env/config overrides.
The logic is pretty much the same as ui.termwidth() of Mercurial.
2023-03-11 12:01:17 +09:00
Yuya Nishihara
afdf9e19f2 ui: simplify size() to only return width, rename it to term_width()
I'm going to add $COLUMNS override, and it should work even if ioctl() on tty
failed. This means that the return type has to be (Option<u16>, Option<u16>).
Since we don't use the row count, I decided to drop it.
2023-03-11 12:01:17 +09:00
Martin von Zweigbergk
b6cac0c6aa docs: add a SECURITY.md
I've set up a jj-security@googlegroups.com list. The template comes
from Google's internal web.

I have no experience with GitHub's Security Advisory database, but it
seems like a good practice, so let's use it.
2023-03-10 14:31:36 -08:00