ok/jj
1
0
Fork 0
forked from mirrors/jj
Commit graph

1220 commits

Author SHA1 Message Date
Martin von Zweigbergk
ee336a2e45 cli: delete builtin update/up aliases
These don't seem used much, and maybe we (or a customized build) will
want to use the name in the future.
2023-02-10 08:33:05 -08:00
Yuya Nishihara
d7f64c07e0 cli: handle last-minute ui.write() error
This works if the pager exits instantly and jj is slow enough to notice
EPIPE. If the pager exits late, no error would be reported.

Since the pager process is asynchronous, EPIPE could occur in
handle_command_result(). That's why I made it not panic.
2023-02-10 23:30:35 +09:00
Yuya Nishihara
686c1fb522 templater: allow trailing comma
While rewriting the default log template, I find it's annoying that I have
to remove "," from the last line.
2023-02-07 23:19:36 +09:00
Yuya Nishihara
ba1c4f5fe5 cli: replace all $variable matches found in edit/merge-args 2023-02-07 18:32:57 +09:00
Yuya Nishihara
a1bfe33a08 cli: expand $left/$right parameters in merge-tools.<name>.edit-args
And set edit_args = ["$left", "$right"] by default.
2023-02-07 18:32:57 +09:00
Yuya Nishihara
449e84d7ea cli: rename interpolate_mergetool_filename_patterns(), inline caller
I'll add string interpolation support to edit-args.
2023-02-07 18:32:57 +09:00
Yuya Nishihara
baa67fe1db cli: make interpolate_mergetool_filename_patterns() simply work with strings
The assumption here is temp_dir wouldn't contain invalid utf-8 bytes. If it
can contain invalid bytes, maybe we can remove temp_dir from arguments, and
chdir(temp_dir) instead.

This unblocks the use of Regex. We could use regex::bytes, but it's way
more complex as we would have to go back and forth between str/OsStr and
bytes.
2023-02-07 18:32:57 +09:00
Yuya Nishihara
d5f05b7897 cli: implement Default for MergeTool, do not override it with empty args
The default edit_args will be changed to ["$left", "$right"] to support
variable substitution without breaking the existing configuration too much.

The default merge_args could also be set if we could come up with something
meaningful.
2023-02-07 18:32:57 +09:00
Yuya Nishihara
2d17385d2e config: add merge-tools.<name>.edit-args to schema 2023-02-07 18:32:57 +09:00
Samuel Tardieu
605a39b84f jj new --insert-after 2023-02-07 09:16:48 +01:00
Samuel Tardieu
4119aa44a9 jj new --insert-before 2023-02-07 09:16:48 +01:00
Yuya Nishihara
cd164be762 templater: inline extract_entire_prefix_and_trimmed_tail() and simplify 2023-02-07 11:42:39 +09:00
Yuya Nishihara
ebf9887d65 templater: migrate shortest_prefix_and_brackets() over shortest() 2023-02-07 11:42:39 +09:00
Yuya Nishihara
3ccac9cda5 templater: rename shortest_styled_prefix() to shortest()
Now it is the true "shortest prefix" function with the default parameter,
so let's simply call it "shortest()".
2023-02-07 11:42:39 +09:00
Samuel Tardieu
6377b4f502 style: move unix-specific imports into unix section 2023-02-06 13:16:30 +01:00
Martin von Zweigbergk
74bff5c916 doc: include diff format in config schema 2023-02-05 23:36:30 -08:00
Martin von Zweigbergk
8d3d89facc cli: rename diff.format to ui.diff.format
I felt that the config is too narrow to have it's own top-level [diff]
section, and I couldn't think of another good place to have it. I'm
happy to hear other suggestions.
2023-02-05 23:36:30 -08:00
Ilya Grigoriev
de163216c0 Templater: make shortest id functions default to 0 length
This makes them print the shortest unique prefix only.
2023-02-05 22:15:27 -08:00
Ilya Grigoriev
f076fae9b5 Document the fact that jj rebase accepts multiple -d
It was already mentioned towards the end of the introductory text, but that's
easy to miss.

This also clarifies the doc for `--allow-large-revsets`.
2023-02-05 22:07:28 -08:00
Yuya Nishihara
7bb7d2bd35 cli: rename FullCommandArgs to CommandNameAndArgs
Per discussion in #1198.
2023-02-06 15:03:08 +09:00
Yuya Nishihara
eb95b31b78 cli: split command name and args by FullCommandArgs
If FullCommandArgs is renamed to CommandNameAndArgs, the meaning of .args()
will get fuzzy. This also clarifies that the name part exists even if the
source command string is empty.
2023-02-06 15:03:08 +09:00
Ilya Grigoriev
9cc536e9e0 Mention --allow-large-revsets in hint when one revset resolves to multiple revisions 2023-02-05 21:22:18 -08:00
Ilya Grigoriev
db148af019 Move resolve_destination_revs into mod.rs
It's not very general.
2023-02-05 21:22:18 -08:00
Ilya Grigoriev
4183c69238 Refactor & rename resolve_base_revs to extract the more general function
This extracts the more general `resolve_mutliple_nonempty_revsets_flag_guarded`
out of `resolve_base_revs`. This function should be useful for `rebase -s`,
etc.

`resolve_base_revs` is renamed to `resolve_destination_revs`; that's simply a
better name for it. It is also quite specific to the `new` and `rebase -d`
commands.  It will be moved out of general utilities in the next commit
2023-02-05 21:22:18 -08:00
Ilya Grigoriev
1c6c6dbccc jj rebase -d and jj new: Allow several commits per argument with --allow-large-revsets
Eventually, we should be able to rely on `jj op restore` and the `--allow-large-revsets`.
argument should likely be removed. This is a temporary measure until we figure
out https://github.com/martinvonz/jj/issues/922 and the like.

Fixes https://github.com/martinvonz/jj/issues/571
2023-02-05 21:22:18 -08:00
Ilya Grigoriev
d153ced8ba cli_util: Make resolve_base_revs use IndexSet
This will make deduplication easier in the next commit.
The error message becomes slightly less informative, unfortunately.
2023-02-05 21:22:18 -08:00
Ilya Grigoriev
4268c80c84 Refactor and rename rewrite_multiple_rewriteable_revsets to be more general
We'll soon need that functionality without the checking for rewriteable
part.
2023-02-05 21:22:18 -08:00
Ilya Grigoriev
159c474e2c Move resolve_multiple_rewriteable_revsets to cli_utils.rs 2023-02-05 21:22:18 -08:00
Ilya Grigoriev
8c1a5539ad cli: Include revset in hint for resolve_single_rev
The revset is already printed in the error message, but it's easy to miss since
the error message is in different color.
2023-02-05 21:22:18 -08:00
Ilya Grigoriev
5fb17925eb jj log: option to specify preferred id length
The new option is `ui.log-id-preferred-length`. Setting it to 6
is quite convenient for the `jj` repo, for example.

Screenshot: https://user-images.githubusercontent.com/4123047/216535699-ad1e2ac8-73dd-44be-b28a-ebdebc00c63c.png
2023-02-05 21:18:42 -08:00
Ilya Grigoriev
b87facff7a Templater: Give short id function a total_len argument
This will be tested in the next commit.
2023-02-05 21:18:42 -08:00
Ilya Grigoriev
58828803d4 Templater: Give shortest id functions a total_len argument. 2023-02-05 21:18:42 -08:00
Ilya Grigoriev
1d1fe77cc8 Update outdated config-schema.json for the unique-prefixes option 2023-02-05 21:18:42 -08:00
Yuya Nishihara
097d3a0e6c templater: add generic wrappers for Option<TemplateProperty>
Option<P> allows us to embed optional argument property in tuple.

    let maybe_arg = maybe_pair.map(|pair| parse(...))?;
    chain_properties((self, maybe_arg), |_: &(Context, Option<_>)| ...)

For one optional argument, we can instead switch the property functions:

    if let Some(pair) = maybe_pair {
        let arg = pair.map(|pair| parse(...))?;
        chain_properties((self, arg), |_: &(Context, _)| ...)
    } else {
        chain_properties(self, |_: &Context| ...)
    }

If we have various combinations of optional arguments, using Option<P> would
be better.
2023-02-06 12:03:56 +09:00
Yuya Nishihara
13d9dc4460 cli: allow to set ui.diff/merge-editor arguments inline
For stock merge-tools, having name -> args indirection makes sense. For
user-specific settings, it's simpler to set command name and arguments
together.

It might be a bit odd that "name with whitespace" can be parsed differently
depending on the existence of merge-tools."name with whitespace".
2023-02-06 11:28:40 +09:00
Yuya Nishihara
78b63c8137 cli: check value type of ui.diff/merge-editor config 2023-02-06 11:28:40 +09:00
Yuya Nishihara
6f4522e34a cli: move MergeArgsNotConfigured to ExternalToolError
Even though this is an error specific to merge operation, I think it's
rather a tool-level error than conflict resolution.
2023-02-06 11:28:40 +09:00
Yuya Nishihara
2f23d0dd10 cli: specify ui.diff/merge-editor keys statically
This helps me grep source code.
2023-02-06 11:28:40 +09:00
Yuya Nishihara
0163bba347 cli: add basic tests for diff/merge-editor configuration 2023-02-06 11:28:40 +09:00
Samuel Tardieu
39226fc127 style: use helper instead of buiding UserError by hand 2023-02-05 20:23:29 +01:00
Yuya Nishihara
a7e2c06068 config: move src/commands/config-schema.json back to src/
I think this is an oversight of moving things into commands/ module.
2023-02-05 19:02:54 +09:00
Yuya Nishihara
5bfecf112a templater: add parsing rule for integer literal, add i64 property
This will be used as a parameter of id.shortest*() methods. For now, only
decimal literal is supported, and there's no unary negate operator.
"0"-prefix is disallowed because it looks like an octal number.

I don't think we would want multiple integer types in the template language,
so I chose i64 as the integer type of reasonable width.
2023-02-05 17:21:54 +09:00
Yuya Nishihara
353d915326 templater: disallow identifier starting with number 2023-02-05 17:21:54 +09:00
Yuya Nishihara
fe8c41bbd7 templater: extract primary rule, inline maybe_method instead 2023-02-05 17:21:54 +09:00
Yuya Nishihara
e4fbb1fe83 templater: extract "function" parsing to function
It's getting bigger.
2023-02-05 17:21:54 +09:00
Yuya Nishihara
9a5a88238b templater: fix handling of method chaining of parenthesized expression 2023-02-05 17:21:54 +09:00
Yuya Nishihara
16a744fe18 templater: make internal parse_template_str() return expression
An "Expression" object is more useful while writing tests.
2023-02-05 17:21:54 +09:00
Yuya Nishihara
5342d2cfb7 templater: implement string.contains() method as example 2023-02-05 11:53:11 +09:00
Yuya Nishihara
54de6168f2 templater: implement TemplateProperty for tuples up to 4-ary
A method call with arguments will be combined to (self, args...) tuple.
Unary tuple is useless, but is implemented for consistency.

This tuple_impls! macro is based off the serde one as the Rust core one
requires unstable feature.
2023-02-05 11:53:11 +09:00
Yuya Nishihara
a4be118981 templater: check number of method arguments 2023-02-05 11:53:11 +09:00
Yuya Nishihara
28c1989257 templater: add helper to extract argument pairs 2023-02-05 11:53:11 +09:00
Yuya Nishihara
945f9c1552 templater: pass parse_keyword() down to method parsing functions
It's needed to parse argument expressions.
2023-02-05 11:53:11 +09:00
Yuya Nishihara
db172aa7c9 templater: process property composition by parse_<type>_method()
This prepares for adding method arguments support. Since a method argument
should be evaluated in the surrounding scope, its type will be
'TemplateProperty<I>', not 'TemplateProperty<J>' for the receiver type 'J'.
Then, the receiver of type 'TemplateProperty<I, Output = J>', and arguments
of type 'TemplateProperty<I, Output = Pn>' will be composed to an input of
type 'TemplateProperty<I, Output = (J, Pn...)>'.

wrap_fn() is removed since it's only useful for nullary methods, and we
no longer need Box<dyn> to abstract the return value.
2023-02-05 11:53:11 +09:00
Yuya Nishihara
bdf809c6c3 templater: do not turn method arguments into iterator by caller
parse_<type>_method() will need args_pair.as_span() to report invalid
argument error.
2023-02-05 11:53:11 +09:00
Yuya Nishihara
5072469eca templater: extract generic parsing functions
We'll probably need a better abstraction, but a parameterized keyword
function is a good first step. This unblocks the use of parse_term() for
context-less properties (or literals). I'm going to add a proper support
for context-aware method arguments, but literals can be parsed without it.

parse_keyword() closure is passed by reference to avoid infinite expansion.
2023-02-05 11:53:11 +09:00
Yuya Nishihara
1b78fb5b5d templater: add shorthand for Result<T, TemplateParseError>
This will appear in "impl Fn(..) -> .." and we can't alias it.
2023-02-05 11:53:11 +09:00
Martin von Zweigbergk
24bc34a0e9 cli: make hints cyan instead of blue
It's hard to read dark blue on black, at least with iTerm2's default
color scheme. Cyan makes it much more readable. That's the color
`cargo` uses. We could also consider coloring only the "Hint:" part
like `cargo` does. For errors, `cargo` colors the "Error:" part red
and uses bold/bright white for select parts of the message.
2023-02-04 11:16:34 -08:00
Martin von Zweigbergk
0625a26121 cli: fix typo in "rewriteable"
It's apparently spelled without the second "e".
2023-02-04 11:16:17 -08:00
Yuya Nishihara
1972eccad1 cli: leverage separate() function to concatenate log template fields 2023-02-04 15:19:02 +09:00
Yuya Nishihara
fbd6657e3f cli: omit log template separator if author.email() is empty 2023-02-04 15:19:02 +09:00
Yuya Nishihara
eb3aeb42dc cli: do not include separator in labeled log template fields 2023-02-04 15:19:02 +09:00
Yuya Nishihara
13b5661094 templater: add separate(sep, contents...) function
This is a copy of Mercurial's separate() function.
2023-02-04 15:19:02 +09:00
Yuya Nishihara
84ee0edc51 templater: add Template::has_content() to filter out empty expressions
This allows us to insert a separator between non-empty template fragments.
Since FormattablePropertyTemplate::has_content() needs to extract
a TemplateProperty, using this function means the property function will
be evaluated twice, one by .has_content() and later by .format(). The cost
is basically the same as 'if(prop, " " prop)'.
2023-02-04 15:19:02 +09:00
Yuya Nishihara
5850575d53 templater: add separate variants for exact/range argument count errors
I believe this isn't a good abstraction, but I need to add one more variant
for "at least n arguments" error. A stringified count like "2 to 3" could be
embedded in an error variant, but I don't think it's good idea to build error
message in that way.
2023-02-04 15:19:02 +09:00
Martin von Zweigbergk
0e90cdedbc cli_util: always run custom global-args-processing function
The way I added support for processing custom global arguments - by
using the existing `dispatch_fn` - meant that it wouldn't be run if
`CliRunner::add_global_args()` was called before
`CliRunner::add_subcommand()` and the custom subcommand wasn't
run. That's clearly not what I intended. This commit fixes that by
adding a separate list of functions for processing global args.
2023-02-03 22:18:51 -08:00
Martin von Zweigbergk
0ea8da064d cli_util: make CliRunner builder functions mutate self
It's easier to mutate `self` than to create a new instance. It does
increase the risk of forgetting to update a field when adding a new
field or a new function, so maybe that's why @yuja did it this way?
2023-02-03 22:18:51 -08:00
Martin von Zweigbergk
60086100a1 cli: split up cmd_config() into one function per subcommand
This style matches our other commands, and will probably be helpful as
the `jj config` command grows.
2023-02-03 19:16:48 -08:00
Martin von Zweigbergk
db817c8dcd cli: extract types for ConfigSubcommand variants 2023-02-03 19:16:48 -08:00
Martin von Zweigbergk
86e1b39ef1 cli: remove unnecessary lifetime in validate_branch_names_exist()
The lifetime isn't in the output and doesn't seem to constrain the
inputs either, so I think it had no effect.
2023-02-03 19:16:48 -08:00
Martin von Zweigbergk
4bff2ca172 cli: split up cmd_branch() into one function per subcommand
The function was getting long, and the new structure matches our other
commands.
2023-02-03 19:16:48 -08:00
Martin von Zweigbergk
0d15a02281 cli: extract types for BranchSubcommands variants
This matches how the other commands are defined. It will also help
split up the large `cmd_branch()` function.
2023-02-03 19:16:48 -08:00
Martin von Zweigbergk
086398dd55 init: provide more info when workspace init fails
We classified all errors from initialization as "The target repo
already exists". That's incorrect when the error came from the
backend.
2023-02-03 14:49:59 -08:00
Yuya Nishihara
e2a5a14463 cli: use label() to highlight "working_copy" commit in log template
I think this is a proper way to label the working-copy commit. This also
fixes "jj obslog" output, but I don't think anyone would care.
2023-02-04 01:58:13 +09:00
Yuya Nishihara
e2eda9f72f templater: inline "current_working_copy" keyword
Maybe I didn't make this change before because the closure needs to capture
WorkspaceId by value. Since the inlined version looks pretty simple, let's
go forward to do that.
2023-02-04 01:58:13 +09:00
Samuel Tardieu
edfa03f017 config: add schema for git.push configuration entry 2023-02-03 16:04:37 +01:00
Samuel Tardieu
af9471e65c git fetch: accept several remotes
The "--remote" option can be repeated, and the "git.fetch" key
is now a list.
2023-02-03 16:04:37 +01:00
Martin von Zweigbergk
e161bedd11 cli_util: elide a lifetime 2023-02-02 21:03:30 -08:00
Martin von Zweigbergk
c1799b27a6 cli: say "snapshot working copy" in the operation description
This is user-visible, but it didn't seem important enough to mention
in the changelog. I can easily be convinced that it should be.
2023-02-02 21:03:30 -08:00
Martin von Zweigbergk
6b7f8e5eab cli_util: rename commit_working_copy() to snapshot_working_copy() 2023-02-02 21:03:30 -08:00
Martin von Zweigbergk
b0a6493d20 cli: rename --no-commit-working-copy to --ignore-working-copy
We have moved from saying "committing the working copy" towards saying
"snapshotting the working copy". More importantly, the option also
means that we don't update the working copy at the end. I went with
the `--ignore-working-copy` name suggested by Ilya. I also updated the
documentation of the option.
2023-02-02 21:03:30 -08:00
Yuya Nishihara
45a018ec6b templater: report invalid argument count as error
We'll probably need a helper to extract N..M arguments, but let's revisit
it later.
2023-02-03 12:06:04 +09:00
Yuya Nishihara
baf911459f templater: report invalid argument type as error 2023-02-03 12:06:04 +09:00
Yuya Nishihara
4eff802d87 templater: report keyword/function/method name error 2023-02-03 12:06:04 +09:00
Yuya Nishihara
8653cc885a templater: wrap inner parsing functions with Result<T> 2023-02-03 12:06:04 +09:00
Yuya Nishihara
7090fa0374 templater: report syntax error, don't panic()
Even though the template syntax is experimental, panicking parser makes
it difficult to write tests. So let's add minimal error handling. The error
types are basically copied from the revset module.

I made write_commit_summary() fall back to the default template if user
template had syntax error. It should be better than reporting parse error
after e.g. "jj abandon" finished successfully.
2023-02-03 12:06:04 +09:00
David Barnett
14982d750e (Minor fix) Don't request pager for config edit, only config list 2023-02-02 19:17:05 +01:00
David Barnett
8ee919dcbb Don't output implicit defaults from "config list"
Accept an --include-defaults arg to enable including those.

Listing a nonexistent name is no longer an error, but does output a
warning to stderr when no config entries match to explain why there's no
other output.
2023-02-01 19:49:57 -06:00
Yuya Nishihara
d6592573d0 templater: abstract Dynamic/LabelTemplate over labels type, unify them 2023-02-02 01:12:23 +09:00
Yuya Nishihara
1911734acc templater: add wrapper that turns template back to string property
I have no idea whether or not any template expressions are intentionally
allowed as a label, but it makes sense to write something like
'label("phase-" phase, ...)' (if we had a phase keyword.) So I decided to
add .into_plain_text() instead of stricter .try_into_string().
2023-02-02 01:12:23 +09:00
Yuya Nishihara
6da43734cb templater: migrate trivial commit keywords to closure wrapper
Perhaps, non-trivial keywords can be extracted to free functions, and both
parsing and property functions can be eventually moved to a commit templater
module?
2023-02-01 17:54:35 +09:00
Yuya Nishihara
846be15132 templater: add CommitOrChangeId constructor to help inline keywords 2023-02-01 17:54:35 +09:00
David Barnett
dc0e3c1855 Add ui.unique-prefixes and git.auto-local-branch to config schema 2023-02-01 01:21:26 -06:00
Yuya Nishihara
e63ea86841 templater: do not complete "(no commit description)" by default
This allows us to use "if(description,)" to test empty description. And
I think this change is unavoidable if we want to add support for commit
template.
2023-02-01 16:13:43 +09:00
Yuya Nishihara
12d8c4ef01 cli: have complete_newline() return String instead of mutating
String -> String function is more convenient in one liner, and it's unlikely
we'll use this function in hot loop.
2023-02-01 16:13:43 +09:00
Yuya Nishihara
e4cb1afd61 templater: fix crash on "".first_line() 2023-02-01 16:13:43 +09:00
Samuel Tardieu
6e9d3879fd split: give warning when given paths don't match anything 2023-02-01 07:15:38 +01:00
David Barnett
16d287340a Update schema for [colors] to allow either string or table values 2023-01-31 22:24:01 -06:00
Yuya Nishihara
259314b442 templater: reuse parse_commit_term() to coerce if() condition to bool
This should fix some inconsistent parsing of condition term.
2023-02-01 10:25:28 +09:00
Yuya Nishihara
553bee6ac4 templater: extract method that coerces property to boolean 2023-02-01 10:25:28 +09:00
Yuya Nishihara
5eee7186ba templater: add enum that holds property or template
This allows us to merge parse_boolean_commit_property() into
parse_commit_term(). We'll probably need similar type coercion methods
for the other basic types.

I considered adding something like Property::Template(), which could be
reused for map operation (e.g. 'revset().map(commit_id).join(" ")'.)
However, a mapped commit template would be different from the top-level
commit template regarding the lifetime of the context.
"Expression::<Commit>::Template()" takes "for<'b> &'b Commit" as an argument,
whereas a mapped template property would capture Commit object somewhere.
2023-02-01 10:25:28 +09:00