Commit Graph

2932 Commits

Author SHA1 Message Date
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
Martin von Zweigbergk
9ff422396a github: pin version of codespell action by hash
The security scanner complained about this. It is what we do with all
other actions.
2023-03-10 13:00:03 -08:00
Yuya Nishihara
c52efd9df3 templater: add fill(width, content) function
The parameter order follows indent()/label() functions, but this might be
a bad idea because fill() is more likely to have optional parameters. We can
instead add template.fill(width) method as well as .indent(prefix). If we take
this approach, we'll probably need to add string.fill()/indent() methods,
and/or implicit cast at method resolution. The good thing about the method
syntax is that we can add string.refill(), etc. for free, without inventing
generic labeled template functions.

For #1043, I think it's better to add a config like ui.log-word-wrap = true.
We could add term_width/graph_width keywords to the templater, but the
implementation would be more complicated, and is difficult to use for the
basic use case. Unlike Mercurial, our templater doesn't have a context map
to override the graph_width stub.
2023-03-10 16:07:55 +09:00
Yuya Nishihara
ec554f6df2 cli: implement word wrapping function for labeled output 2023-03-10 16:07:55 +09:00
Yuya Nishihara
1c852b7fb9 cli: implement word wrapping function for bytes
wrap_bytes() is similar to textwrap::wrap(), but can process arbitrary bytes.
More importantly, it guarantees that byte offsets can be reconstructed from
the split slices. This allows us to interleave push/pop_label()s with split
text fragments.

We could calculate byte offsets upfront, but using slice API is more
convenient. That's why I didn't add inner function returning Vec<Range>.
2023-03-10 16:07:55 +09:00
Yuya Nishihara
c5046235b5 formatter: pass data range to replay callback instead of data slice
New word-wrap function will be implemented in two passes. The first pass
splits byte slice to lines, and the second pass inserts "\n" based on that
while interleaving push/pop_label() calls and text fragments. Since the second
pass combines multiple data sources, byte indices are more convenient than
slices there.
2023-03-10 16:07:55 +09:00
Yuya Nishihara
b41bdb548a templater: generalize IndentTemplate as reformatting template
New fill() function will also use this struct.
2023-03-10 16:07:55 +09:00
Yuya Nishihara
2af2aca7ff templater: extract indent function to text_util module
This prepares for adding generic template object for reformatting.
2023-03-10 16:07:55 +09:00
Yuya Nishihara
82604eda02 cli: extract complete_newline() to text_util module
I'll add more text formatting functions there.
2023-03-10 16:07:55 +09:00
Yuya Nishihara
e8fd12aff6 templater: add list.join(separator) method
The implementation is a bit tricky since we have to combine a property
(of C -> Vec<Template<()>> type) and a separator of Template<C> type.
2023-03-10 12:58:32 +09:00
Yuya Nishihara
6c146de2e8 templater: add string.lines() method
This wouldn't be used much in practice, but is useful for writing tests of
list methods.
2023-03-10 12:58:32 +09:00
Yuya Nishihara
f8f24399f2 templater: rename ListTemplate and "list" parsing node to "concat"
It's getting confusing since we now have a list property type.

expand/normalize_list() functions aren't renamed since they are also applied
to a list of function arguments.
2023-03-10 12:58:32 +09:00
Yuya Nishihara
aff5cd01d2 templater: while building, process template as a property variant
This is simpler, and it also unblocks the use of a Template<C> in method
return value position.
2023-03-10 12:58:32 +09:00