Commit graph

1049 commits

Author SHA1 Message Date
Yuya Nishihara
a3d3947499 templater: move epsilon rule out of term rule
Suppose "template" is a sequence of "term"s, it makes more sense to handle
an empty sequence there. It might be even better to disallow empty template
other than the top-level one.
2023-01-29 08:54:14 +09:00
Yuya Nishihara
d1281ef48e templater: ensure "template" node is passed to parse_commit_template_rule()
Assertion will be added by the next commit.
2023-01-29 08:54:14 +09:00
Yuya Nishihara
bf66beab36 templater: fix parsing of parenthesized expression
A "list" is a sequence of more than one "term" nodes, so it shouldn't contain
a single parenthesized node.

Also, a parenthesized "term" rule wasn't handled.
2023-01-29 08:54:14 +09:00
Yuya Nishihara
f7993f0fe9 templater: eliminate whitespace nodes from parse tree 2023-01-29 08:54:14 +09:00
Yuya Nishihara
a85488b11d cli: pretty-print "debug template" output
Since a parsed tree is deeply nested, it's difficult to read as a one-line
string.
2023-01-29 08:54:14 +09:00
Yuya Nishihara
29eb7a16b8 templater: process method chaining from left to right
A method call is typically left associative, and LTR processing is simpler.
2023-01-28 10:53:03 +09:00
Yuya Nishihara
2ae892efab templater: reuse function rule to represent a method chain
A method call is typically parsed as (obj.meth)(), not as obj.(meth()),
but the latter is good enough for our needs. It's unlikely we'll add a
first-class function support.

.into_inner().next().unwrap() mess will be cleaned up by the next commit.
2023-01-28 10:53:03 +09:00
Martin von Zweigbergk
d8942d5f96 cli: rename ui.graph.format to ui.graph.style
I think of it more as style than a format, so using `style` in the
config key makes sense to me.

I didn't bother making upgrades easy by supporting the old name since
this was just released and only a few developers probably have it set.
2023-01-27 10:36:26 -08:00
Martin von Zweigbergk
8248d6e8f6 graphlog: remove use of PhantomData 2023-01-27 10:36:26 -08:00
Martin von Zweigbergk
0b99e5b16e graphlog: enable Sapling's graph styles by default
I would also rename the feature, but I hope we can instead soon make
it a non-optional dependency and delete the feature.
2023-01-27 09:46:57 -08:00
Martin von Zweigbergk
5ec5f4bb5f config: rename [alias] to [aliases], still supporting old name
The name of the [alias] section is inconsistent with other
table-valued sections ([revset-aliases], [colors], [merge-tools]), so
let's rename it. For comparison, `Cargo.toml` also uses plural names
(e.g. `[dependencies]`).
2023-01-26 18:15:23 -08:00
Martin von Zweigbergk
8af38f0d75 cli: consistently use clap::Command, and avoid unnecessary qualification 2023-01-26 18:15:23 -08:00
Martin von Zweigbergk
4a4aebd3bc cli: don't use clap::Error since it's too generic
It's not obvious when you see `Error`, even in the CLI crate, that
it's a `clap::Error`
2023-01-26 18:15:23 -08:00
Yuya Nishihara
bfb56614d4 templater: rename TemplateFunction::new() parameter for consistency 2023-01-26 23:42:13 +09:00
Yuya Nishihara
2c4856c47b templater: remove Box<dyn> from generic wrappers, parameterize type
This basically removes 'a lifetime from these wrappers, and add trait bounds
instead. I have no idea which version would look less scary, but let's see.

I also added trait bounds to constructor functions. They aren't strictly
required, but help type inference of closure (and will probably improve
an error message.)
2023-01-26 23:42:13 +09:00
Aleksandr Mikhailov
e7077909c1 cli: fix jj squash on empty commit
Fixes #787
If `jj squash` is run on an empty commit, it fails with "Error: No changes selected"

With this change such squash command will behave like `jj abandon`.
2023-01-26 11:37:20 +01:00
Yuya Nishihara
b9fc6d4203 templater: rewrite divergent property by leveraging IdIndex 2023-01-26 14:10:26 +09:00
Martin von Zweigbergk
10725c095f cleanup: update more "checkout" to "working-copy commit" and similar
I've preferred "working-copy commit" over "checkout" for a while
because I think it's clearer, but there were lots of places still
using "checkout". I've left "checkout" in places where it refers to
the action of updating the working copy or the working-copy commit.
2023-01-25 11:02:59 -08:00
Yuya Nishihara
e874570947 cli: proxy format_commit_summary() through transaction wrapper
At this point, tx.base_repo() is identical to tx.repo(), so the caller doesn't
need to explicitly select the "base" one.
2023-01-25 13:52:43 +09:00
Yuya Nishihara
18e9679613 cli: move run_mergetool/edit_diff/select_diff to transaction wrapper
These functions should use MutableRepo if base_repo.store() != repo.store().
See also #50.
2023-01-25 13:52:43 +09:00
Yuya Nishihara
330adf380f cli: start transaction before starting edit/select_diff()
Other callers do that, so let's make the transaction cover tree merging
and diff editing.
2023-01-25 13:52:43 +09:00
Yuya Nishihara
1b8ecef968 cli: have WorkspaceCommandHelper return &WorkspaceId, clone it by caller
I didn't make this change before because there are many immutable/mutable
borrow conflicts. Now most of the problems are consolidated to the transaction
wrapper, we can simply make it return a reference.
2023-01-25 13:31:41 +09:00
Yuya Nishihara
3d5eb970da cli: wrap transaction started by WorkspaceCommandHelper, borrow helper mutably
This ensures that helper methods that depend on repo aren't used by mistake
while transaction is in progress. Still it provides an escape hatch to invoke
e.g. select_diff() with the base repo, but such invocations are more explicit.

Some MutableRepo methods are proxied through the wrapper to get around
borrowing errors.
2023-01-25 13:31:41 +09:00
Yuya Nishihara
44e7c0632e cli: evaluate rebase set before starting transaction
This should eliminate lifetime issue I would have to deal with in the
next commit. evaluate_revset() only borrows RepoRef, but such precise
dependency can't be expressed as of now.
2023-01-25 13:31:41 +09:00
Yuya Nishihara
c018ef229b repo: proxy shortest unique prefix function through RepoRef
Since this function depends on both index and view, it can't be moved to
one of the storage objects. If we go forward with this approach, some
revset::resolve_*() functions will also be migrated to RepoRef.

This patch slightly changes the function name since a "prefix" might have
various meanings.
2023-01-25 10:47:39 +09:00
Martin von Zweigbergk
b079897a56 cli: propagate failure to record new working-copy id
This code cannot currently fail because we we never pass in the root
commit, but it's more future-proof to propagate the error.
2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
63aa484046 repo: add a specific error type for MutableRepo::check_out() 2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
dd3472924b repo: add a specific error type for MutableRepo::edit()
The new type is just an enum version of `RewriteRootCommit`.  I'll add
another variant soon.
2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
ff592e522f edit: explicitly check that target commit is rewritable
I think the CLI should check if the target of `jj edit` is rewritable
before calling the library to update the repo. The other commands
already do that. Then, if calling `MutableRepo::edit()` fails, it's
always an internal error, which makes error handling simpler in coming
commits.
2023-01-24 12:20:28 -08:00
Samuel Tardieu
e4f6dadfad workspace: add a root subcommand to print the workspace root path 2023-01-24 16:53:54 +01:00
Yuya Nishihara
797189b106 cli: error out if colors section isn't of map type 2023-01-24 15:06:12 +09:00
Yuya Nishihara
7b24df25e4 cli: remove redundant check for undefined "merge-tools" section
The section should be defined by default.
2023-01-24 15:06:12 +09:00
Yuya Nishihara
337246ea51 cli: error out if alias/revset-aliases section isn't of map type
I considered adding .optional() helper to lift Result to Result<Option<_>>,
but it's much simpler to expect all config sections (and maybe all keys?)
are defined by default.

The error message is a bit cryptic, but it should be improved by the following
PR if accepted.

https://github.com/mehcode/config-rs/pull/413
2023-01-24 15:06:12 +09:00
Yuya Nishihara
3b09635f46 cli: rename config/git.toml to misc.toml to add some more random stuff
I could add a file per section, but each file would just contain one or two
lines.
2023-01-24 15:06:12 +09:00
Yuya Nishihara
8163b87a54 templater: store repo in CommitOrChangeId struct
This one was the outlier, and I think propagating 'repo' by context variable
is more correct.
2023-01-24 01:46:41 +09:00
Yuya Nishihara
e15b35ba56 templater: remove unused repo from CommitOrChangeIdShort 2023-01-24 01:46:41 +09:00
Yuya Nishihara
f47552b744 templater: turn output parameter of TemplateProperty into associated type
When implementing FormattablePropertyTemplate, I tried a generic 'property: P'
first, and I couldn't figure out how to constrain the output type.

    impl<C, O, P> Template<C> for FormattablePropertyTemplate<P>
    where
        P: TemplateProperty<C, O>, // 'O' isn't constrained by type
        O: Template<()>,

According to the book, the problem is that we can add multiple implementations
of 'TemplateProperty<C, *>'. Since TemplateProperty is basically a function
to extract data from 'C', I think the output parameter shouldn't be freely
chosen.

https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

With this change, I can express the type constraint as follows:

    impl<C, P> Template<C> for FormattablePropertyTemplate<P>
    where
        P: TemplateProperty<C>,
        P::Output: Template<()>,
2023-01-24 01:46:41 +09:00
Yuya Nishihara
df085a4bd5 templater: label author/committer name in default formatting
Just for consistency with .name() method call.
2023-01-23 15:23:26 +09:00
Yuya Nishihara
47e6ceb5fa templater: display both name and email by author/committer keywords
This is an example of labeled output of structured value types. I think
"{name} <{email}>" is a good default formatting, but I should note that
the signature also contains timestamp field.
2023-01-23 15:23:26 +09:00
Yuya Nishihara
4e661ecd40 templater: format context-less property value instead of coercing to string
This unblocks labeled outputs for these value types.
2023-01-23 15:23:26 +09:00
Yuya Nishihara
431395a7ee templater: generalize Literal/Constant wrapper for any context-less template
Now we have 'impl Template<()> for String', 'LiteralTemplate(String)' is
a bit redundant. Let's generalize it for any 'Template<()>'. I noticed
'ConstantTemplateProperty' serves as a similar role, so unified these.
2023-01-23 15:23:26 +09:00
Yuya Nishihara
23ab89d200 templater: implement context-less Template::format() on value types
This is a slightly better version of the one I described in:
https://github.com/martinvonz/jj/pull/1098#issuecomment-1399476487

These impls will replace coerce_to_string() to support labeled outputs.
We could allow arbitrary context type 'C', but I feel uncomfortable with
that. So let's start with () until we find it doesn't work out.
2023-01-23 15:23:26 +09:00
Yuya Nishihara
c1f0ca9b5a templater: rewrite Property match arms with generic function
We might want to go further by rewriting the Property enum with trait, but
let's start small.
2023-01-23 15:23:26 +09:00
Yuya Nishihara
d2b8240648 templater: inline TemplateFormatter into write_commit_summary()
It's not used extensively, and I don't think this abstraction is useful
for the moment.
2023-01-23 15:23:26 +09:00
Martin von Zweigbergk
e716168368 cli: also sanitize non-colored output printed to a terminal
This makes us sanitize ANSI escape bytes in the output if it goes to
the terminal, even when it's not colored (by us), such as when using
`--color=never`. That means that e.g. `jj cat
tests/test_commit_template.rs` will not be colored, but `jj cat
tests/test_commit_template.rs | cat` will be. Sanitizing output sent
to the terminal might help reduce some security threats based on
hiding content by using ANSI escapes.

We could add a config option for sanitizing the output, but I'm not
sure it'll be useful.
2023-01-22 17:45:12 -08:00
Martin von Zweigbergk
13a177f211 cli: sanitize ANSI escapes when writing colored output is enabled
Since `ColorFormatter` itself outputs ANSI escape codes, we should not
let the caller also include ANSI escape codes. This commit makes
`ColorFormatter` replace them by a unicode "␛".
2023-01-22 17:45:12 -08:00
Martin von Zweigbergk
7527656d9b formatter: expose raw output and use for graphlog
For graphlog output, we use a separate formatter for each commit. The
output from the formatter is written to a buffer in memory. Then we
write it to graphlog renderer. Since the buffer already has any color
codes, we should not pass it through the top-level formatter (the one
bound to stdout). It hasn't mattered much so far, but it will when we
start sanitizing output written to formatters. This commit adds a
method to the `Formatter` trait for getting access to the raw
underlying output. It also starts passing that output to the graphlog
renderer.
2023-01-22 17:45:12 -08:00
Martin von Zweigbergk
522025e091 log: remove unused and inconsistent log label
We add a top-level `log` label to the output from `jj log`, but we
never define any colors based on it. More importantly, it was
inconsistent between the graph and non-graph cases. When showing the
graph, any colors set based on it would only apply to the graph itself
[1] because we use a separate formatter for each commit in the
graphlog and that formatter didn't inherit the `log` label. So let's
just remove the label for now. We can consider adding it back for each
commit later. That's what we do for `jj op log`, but it's simpler in
that case because it doens't have a `--no-graph` version.

 [1] Well, mostly; it would also apply to any uncolored element
     immediately right of the graph.
2023-01-22 17:45:12 -08:00
Martin von Zweigbergk
842b3e5591 formatter: remove write_bytes() method
The caller can just as easily use `write_all()`.

Maybe we should also remove the `write_str()` method.
2023-01-22 17:45:12 -08:00
Yuya Nishihara
1a6e71170e templater: remove string.short() method
I think this is a remainder of 68ad712e12 "Templater: Combine Change and
Commit id templates." It doesn't make sense that description.short() prints
the first 12 characters.
2023-01-23 00:29:55 +09:00