Commit graph

1244 commits

Author SHA1 Message Date
Yuya Nishihara
eafbd977a3 templater: add TimestampRange type, migrate operation time to it 2023-02-20 18:20:41 +09:00
Yuya Nishihara
da3c1d2286 templater: extract helpers to build expression of specific types 2023-02-20 18:20:41 +09:00
Yuya Nishihara
c2e0ebca12 templater: implement .into_template() helper on formattable property
So that I can blindly write property.into_template() to convert any property
type to template.
2023-02-20 18:20:41 +09:00
Yuya Nishihara
854a3e64fa templater: split IntoTemplate trait
The next commit will implement .into_template() on Box<dyn TemplateProperty>,
so I want a trait for this particular method.
2023-02-20 18:20:41 +09:00
Ilya Grigoriev
9c51d74b2c cmd: Allow multiple -b for jj rebase
This also makes `rebase_branch` reuse `rebase_descendants`.

This addresses a portion of #1158
2023-02-20 00:36:32 -08:00
Ilya Grigoriev
f04458a245 cmd: Allow multiple -s for jj rebase
This addresses a portion of #1158

One application (not the prettiest, but useful until we have `jj sync`):

    jj rebase -s oldmain+~:main -d main -L
2023-02-20 00:36:32 -08:00
Ilya Grigoriev
53476a77f7 cmd: Make jj restore work if @ is a merge commit
To be clear, this applies to `jj restore` without any arguments.

Fixes #1228
2023-02-19 22:55:53 -08:00
Martin von Zweigbergk
bc9f66dad3 revset: replace RevsetIterator wrapper by extension
The type doesn't seem to provide any benefit. I don't think I had a
good reason for creating it in the first place; it was probably just
unfamiliarity with Rust.
2023-02-19 21:37:26 -08:00
Martin von Zweigbergk
30160f4d20 revset: pass revset, not iterator, into RevsetGraphIterator
I was thinking of replacing `RevsetIterator` by a regular
`Iterator<Item=IndexEntry>`. However, that would make it easier to
pass in an iterator that produces revisions in a non-topological order
into `RevsetGraphIterator`, which would produce unexpected results (it
would result in nodes that are not connected to their parents, if
their parents had already been emitted). I think it makes sense to
instead pass in a revset into `RevsetGraphIterator`.

Incidentally, it will also be useful to have the full revset available
in `RevsetGraphIterator` if we rewrite the algorithm to be more
similar to Mercurial's and Sapling's algorithm, which involves asking
the revset if it contains parent revisions.
2023-02-19 21:37:26 -08:00
Yuya Nishihara
a3efb74cfc commit_templater: make commit/change_id typed again
This basically undoes d6c6cdb45c "templater: store type-erased version of
commit/change id." Since they are looked up differently, they should preserve
the original types.
2023-02-20 13:41:44 +09:00
Samuel Tardieu
863a6e6d09 git push: add --deleted option 2023-02-19 18:18:53 +01:00
Yuya Nishihara
4f9e75c7d1 templater: use macro to implement property kind wrappers 2023-02-19 16:18:39 +09:00
Yuya Nishihara
aaae90a599 commit_templater: turn property structs into functions 2023-02-19 16:18:39 +09:00
Yuya Nishihara
cf1b609de2 commit_templater: rename 'repo lifetime for clarity
FWIW, I'm thinking of making the repo parameter generic over Arc<ReadonlyRepo>
and &MutableRepo. It will allow us cache a parsed commit_summary template.
2023-02-19 16:18:39 +09:00
Yuya Nishihara
c5ddd14c13 commit_templater: extract runtime objects from templater.rs
This should reduce future merge conflicts around use statements.
2023-02-19 16:18:39 +09:00
Yuya Nishihara
c396b4cecf commit_templater: extract parsing functions from template_parser.rs
parse_commit_template() is renamed to commit_templater::parse().
2023-02-19 16:18:39 +09:00
Yuya Nishihara
73b7954060 templater: make common parser types and utility functions public
So the commit templater can be extracted to new module.
2023-02-19 16:18:39 +09:00
Yuya Nishihara
a28396fc86 templater: extract "commit" property variants to separate enum
Now it's ready to split template_parser/templater into base template functions
and "commit" templater. I think Signature and Timestamp are basic types, so
they aren't moved to CommitTemplatePropertyKind. Perhaps, a duration type from
OpTemplate will also be added to CoreTemplatePropertyKind.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
7ee2ff862f templater: rename Property enum to CoreTemplatePropertyKind
I'll add CommitTemplatePropertyKind.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
5474268d22 templater: parameterize property type 2023-02-19 11:31:22 +09:00
Yuya Nishihara
907bddaf1e templater: add conversion trait for common template types
Maybe we can split traits per type (such as IntoTemplate), but a single
trait should be good enough to abstract "Property" enums.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
2be34ab552 templater: proxy Property::<variant>() wrapping through language trait
The idea is that a derived language will do wrap_<core_type>() as
DerivedProperty::Core(CoreProperty::<Type>(property)). This could be dealt
with some From<CoreProperty> trait impls, but the resulting code looked
a mess, and compile errors would be cryptic. I think this is somewhat similar
to serde::Serializer API.

I also rejected the idea of abstracting property types over Box<dyn>. Maybe
it's okay for method dispatching and extraction of some basic types, but it
wouldn't work if we want to implement comparison operators for any compatible
types.

wrap_commit_or_change_id() and wrap_shortest_id_prefix() will be moved to
the CommitTemplateLanguage. I'll add impl_wrap_fns() macro after splitting
the modules.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
52df6f2e81 templater: proxy build_core_method() through language trait
The "core" template parser wouldn't know how to dispatch property of types
added by a derived language. For example, CommitOrChangeId/ShortestIdPrefix
will be moved to the "commit" templater.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
3361130df4 templater: introduce trait that abstracts property kind and keywords
This trait will provide ways to dispatch keyword/method nodes, and wrap
TemplateProperty object with a dedicated "Property" enum.

build_keyword() and context parameter "I"/"C" have been migrated to it.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
4b00fb70d0 templater: extract function that dispatches method call by property type
A derived template language (e.g. commit template) will forward method calls
of the core types to this function.
2023-02-18 01:16:43 +09:00
Yuya Nishihara
7784768dc6 templater: inline PropertyAndLabels into Expression::Property()
It's no longer used at type position.
2023-02-18 01:16:43 +09:00
Yuya Nishihara
84ad048f24 templater: move initial labeling out of keyword function
I'm going to extract functions specific to commit templates, and auto labeling
feature should be a part of the core template language.
2023-02-18 01:16:43 +09:00
Ilya Grigoriev
e4aa2cb2e5 Rename ui.relative-timestamps to ui.oplog-relative-timestamps 2023-02-15 21:26:14 -08:00
Ilya Grigoriev
859b0f680c Make ui.relative-timestamps default to true
This seems like a better default for `jj op log`, which is now the only thing
this option affects.
2023-02-15 21:26:14 -08:00
Martin von Zweigbergk
d8997999f2 repo: replace RepoRef by Repo trait 2023-02-15 19:15:17 -08:00
Martin von Zweigbergk
f6a4cb57da repo: extract a Repo trait for Arc<ReadonlyRepo> and MutableRepo
This will soon replace the `RepoRef` enum, just like how the `Index`
trait replaced the `IndexRef` enum.
2023-02-15 19:15:17 -08:00
Martin von Zweigbergk
b7dad291df repo: make all base_repo() functions return &Arc<ReadonlyRepo>
This is to prepare for a `Repo` trait implemented for
`Arc<ReadonlyRepo>` (not for `ReadonlyRepo` itself).
2023-02-15 19:15:17 -08:00
Martin von Zweigbergk
8a067282c8 repo: make ReadonlyRepo::index() return a &dyn Index
This is just a little preparation for extracting a `Repo` trait that's
implemented by both `ReadonlyRepo` and `MutableRepo`. The `index()`
function in that trait will of course have to return the same type in
both implementations, and that type will be `&dyn Index`.
2023-02-15 19:15:17 -08:00
Yuya Nishihara
3c61e9239c config: remove ui.log-author-format in favor of template alias 2023-02-16 11:43:17 +09:00
Yuya Nishihara
6316ec7442 config: migrate log/show timestamp format away from config knob
Since oplog still relies on ui.relative-timestamps, this config key
isn't removed.
2023-02-16 11:43:17 +09:00
Yuya Nishihara
a00767bc0f config: remove ui.unique-prefixes/log-id-preferred-length in favor of alias 2023-02-16 11:43:17 +09:00
Yuya Nishihara
7913f90869 templater: remove "brackets" short id style in favor of template alias
Though .prefix() + .rest() has to call .shortest() twice, I don't think
the added cost would be significant.
2023-02-16 11:43:17 +09:00
Yuya Nishihara
ed4a696dea templater: add shortest().prefix()/rest() accessors
This ensures that the "brackets" style can be emulated by a template
expression.
2023-02-16 11:43:17 +09:00
Martin von Zweigbergk
29792dab9b cli: avoid a closure in op log code for printing timestamp
I find it easier to read the code without the closure and the extra
indentation. Instead, leverage `formatter.labeled()`.
2023-02-15 09:46:38 -08:00
Yuya Nishihara
1bdee80a0d cli: remove attempt to detect EPIPE caused by bad pager configuration
It turned out bad idea because EPIPE (or SIGPIPE) is kind of a successful
termination. We could show some warning based on pager exit code, but let's
avoid messing up again.

io::Error occurred in handle_command_result() is still mapped to a BrokenPipe.
panic()-ing there should be wrong.
2023-02-15 15:36:23 +09:00
Martin von Zweigbergk
54156335e4 cli: don't print error about broken pipe
`jj log | head` consistently prints "Error: Broken pipe" for me. I
don't know how the output gets printed after the pipe has been closed,
but neither `git` nor `hg` prints an error, so I think we shouldn't
either.
2023-02-14 21:29:02 -08:00
Yuya Nishihara
0abf9ce8cd cli: move default "show" template to alias
I'm not pretty sure if this is structurally good, but 'jj log -T show'
is useful.
2023-02-15 01:44:33 +09:00
Yuya Nishihara
605eb72883 config: rename [template] section to [templates], drop .graph suffix
This should be more consistent with the other tables.
2023-02-15 00:23:48 +09:00
Yuya Nishihara
9c6fa67b86 config: apply configured id style to commit_summary template
Thanks to 81af5f820b "repo: calculate shortest unique prefix separately for
commit/change", commit_id.shortest() now works even if the repo is MutableRepo.
2023-02-15 00:23:48 +09:00
Yuya Nishihara
bc7ca03da4 config: extract commit_summary template to config/templates.toml 2023-02-15 00:23:48 +09:00
Yuya Nishihara
e996f6859b cli: add dummy load of summary template to WorkspaceCommandHelper::new()
Alternatively, we can make all callers propagate TemplateParseError, but I
don't think format_commit_summary() should have such signature.
2023-02-15 00:23:48 +09:00
Yuya Nishihara
32f4a81329 config: extract "show" template to config/templates.toml
Aside from [template] vs [templates], we might want a "show" template alias
so "jj log -Tshow" serves the role of "hg log -v".
2023-02-15 00:23:48 +09:00
Yuya Nishihara
a5a49c8c12 config: extract default log template to config/templates.toml 2023-02-15 00:23:48 +09:00
Yuya Nishihara
a2bc826cf4 cli: migrate log formatting options to leverage template aliases
No more format!() template expressions.

We might want a separate namespace for configurable "default" aliases, but
let's start with a simple approach. Even if we had [default-templates]
section, it would be practically the same as [template-aliases] so long as
'default-templates.f()' appears as 'f()' in template.
2023-02-15 00:23:48 +09:00
Yuya Nishihara
7e271347d0 cli: remove stale comment about conditional template labeling
We can add boolean.then() for convenience, but it isn't strictly needed.
label(if()) works fine.
2023-02-15 00:23:48 +09:00