Commit graph

2909 commits

Author SHA1 Message Date
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
Yuya Nishihara
0f87649696 templater: add helper to create Expression with/without labels
These functions aren't suffixed with _property, since Expression::Template()
will be flattened into P::Template().
2023-03-10 12:58:32 +09:00
Martin von Zweigbergk
e5a4c2e75b readme: don't say that this is my 20% project
The project has been my full-time project since around last summer, so
it's incorrect to say that it's my 20% project.
2023-03-09 16:41:54 -08:00
dependabot[bot]
a26bf965a5 cargo: bump serde from 1.0.153 to 1.0.154
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.153 to 1.0.154.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.153...v1.0.154)

---
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-09 08:23:54 -08:00
dependabot[bot]
87c44f454d cargo: bump libc from 0.2.139 to 0.2.140
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.139 to 0.2.140.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.139...0.2.140)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-09 08:23:37 -08:00
dependabot[bot]
f422068d62 cargo: bump serde from 1.0.152 to 1.0.153
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.152 to 1.0.153.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.152...v1.0.153)

---
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-08 09:20:54 -08:00
Yuya Nishihara
6af265a388 templater: move Box::new() wrapping to language.wrap_() functions
Now all callers do wrap_<type>(Box::new(...)), so its responsibility can be
moved to the callee without extra boxing.
2023-03-08 16:14:24 +09:00
Yuya Nishihara
96f4d8798c templater: remove redundant TemplateProperty wrapping from method chaining
TemplateFunction takes a property and a function to apply to the property
value. That's exactly what a method call does.
2023-03-08 16:14:24 +09:00
dependabot[bot]
4e7430a81a cargo: bump pest_derive from 2.5.5 to 2.5.6
Bumps [pest_derive](https://github.com/pest-parser/pest) from 2.5.5 to 2.5.6.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.5...v2.5.6)

---
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-03-07 17:32:21 +01:00
Martin von Zweigbergk
e509a299e5 cli: print commands in alphabetical order
Until https://github.com/clap-rs/clap/issues/1553 is fixed, I don't
think we can do better than alphabetical order (without a lot of
work).
2023-03-06 21:35:34 -08:00
Yuya Nishihara
4984e611f4 templater: add "parent_commit_ids" keyword
A list type isn't so useful without a map operation, but List<CommitId>
is at least printable. Maybe we can experiment with it to craft a map
operation.

If a map operation is introduced, this keyword might be replaced with
"parents.map(|commit| commit.commit_id)", where parents is of List<Commit>
type, and the .map() method will probably return List<Template>.
2023-03-07 11:33:15 +09:00
Yuya Nishihara
0b27f8371a templater: make Literal(str) or str usable as a template 2023-03-07 11:33:15 +09:00
Yuya Nishihara
7b206e6fb5 templater: add helper to format template properties with separator
contents will be an Iterator<Item = &P> where P is a Template<()>.
2023-03-07 11:33:15 +09:00
dependabot[bot]
7da0994d58 cargo: bump thiserror from 1.0.38 to 1.0.39
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.38 to 1.0.39.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/1.0.38...1.0.39)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-06 18:48:04 +00:00
dependabot[bot]
ee7b9dc030 cargo: bump serde_json from 1.0.93 to 1.0.94
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.93 to 1.0.94.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.93...v1.0.94)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-06 10:26:35 -08:00
dependabot[bot]
1656117e6a cargo: bump pest from 2.5.5 to 2.5.6
Bumps [pest](https://github.com/pest-parser/pest) from 2.5.5 to 2.5.6.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.5...v2.5.6)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-06 10:20:09 -08:00
tp-woven
39cbabf58e Clarify that files() is relative 2023-03-06 13:54:38 +09:00
Samuel Tardieu
decca920c7 git push: do not consider @- if @ has non-empty content or description 2023-03-05 23:50:20 +01:00
Samuel Tardieu
616058c2fa lib: add Commit::is_discardable() 2023-03-05 23:50:20 +01:00
Yuya Nishihara
5d184e6694 cli: in "show" template, indent description like Git does 2023-03-04 12:10:53 +09:00
Yuya Nishihara
8f8a9c91bc templater: add indent(prefix, content) function
The argument order is different from Mercurial's indent() function. I think
indent(prefix, content) is more readable for lengthy content. However,
indent(content, prefix, ...) might be better if we want to add an optional
firstline_prefix argument.
2023-03-04 12:10:53 +09:00
Yuya Nishihara
558aa15e6e templater: remove Template::has_content() superseded by FormatRecorder 2023-03-04 12:10:53 +09:00
Yuya Nishihara
974a5145e0 templater: reimplement separate() by using buffered formatter
template.format(context, &mut recorder) wouldn't fail right now, but we
might add a runtime template error in future. So I added error handling there.
2023-03-04 12:10:53 +09:00
Yuya Nishihara
233d37f678 formatter: add buffer that records both data and push/pop_label() calls
Template functions like indent() or fill() need to manipulate labeled
output. Since indent() is line oriented, it could be implemented as a
post-processing filter. OTOH, fill()/wrap() inserts additional "\n"s. If we
do that as a post process, colorized text could be split into multiple lines,
and would mess up graph log output. By using FormatRecorder, we can apply
text formatting in between labels.

I thought we could disallow text wrapping of labeled template fragments, but
the example in #1043 suggests that we do want to wrap(whole_template_output)
rather than simple description.wrap().
2023-03-04 12:10:53 +09:00