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

748 commits

Author SHA1 Message Date
Yuya Nishihara
2817e30fc6 cli: ensure child processes are wait()ed on I/O error 2024-03-05 09:23:15 +09:00
Evan Mesterhazy
a09ee4b9a3 Make URLs in docs hyperlinks
`cargo doc` complains that two URLs aren't actually links:

```
warning: this URL is not a hyperlink
  --> lib/src/fsmonitor.rs:66:6
   |
66 | /// (https://facebook.github.io/watchman/). Requires `watchman` to already be
   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://facebook.github.io/watchman/>`
   |
   = note: bare URLs are not automatically turned into clickable links
   = note: `#[warn(rustdoc::bare_urls)]` on by default

warning: `jj-lib` (lib doc) generated 1 warning (run `cargo fix --lib -p jj-lib` to apply 1 suggestion)
 Documenting jj-cli v0.14.0 (/Users/emesterhazy/oss/github.com/martinvonz/jj/cli)
 Documenting testutils v0.14.0 (/Users/emesterhazy/oss/github.com/martinvonz/jj/lib/testutils)
warning: this URL is not a hyperlink
    --> cli/src/cli_util.rs:2077:41
     |
2077 | /// To get started, see the tutorial at https://github.com/martinvonz/jj/blob/main/docs/tutorial.md.
     |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://github.com/martinvonz/jj/blob/main/docs/tutorial.md.>`
     |
     = note: bare URLs are not automatically turned into clickable links
     = note: `#[warn(rustdoc::bare_urls)]` on by default

warning: `jj-cli` (lib doc) generated 1 warning (run `cargo fix --lib -p jj-cli` to apply 1 suggestion)
```

This commit fixes the warnings by making the watchman URL a hyperlink and by
disabling the lint for the jj-cli error. Disabling the link is the right thing
to do because the comment is captured by clap and printed when `jj --help`
runs and any markdown formatting like `<>` is passed through.
2024-03-04 16:05:42 -05:00
Yuya Nishihara
7ce25f8408 cli: add --tool=<name> option to diff/merge editing commands
I didn't add e2e tests to all commands, but the added tests should cover
diff_editor/diff_selector/merge_editor() calls.

Closes #2575
2024-03-04 01:33:43 +09:00
Yuya Nishihara
4a47cba319 merge_tools: add Diff/MergeEditor constructors that look up tools by name
The tool name is parsed in the same way as diff_util::diff_formats_from_args().
2024-03-04 01:33:43 +09:00
Yuya Nishihara
0f42c56b5c merge_tools: box external tool variant to minimize stack size
The ExternalMergeTool struct has four 24-byte fields plus one bool. It could
be shrunk by dropping Vec/String capacity, but the resulting type would still
be bigger compared to the default Builtin variant.
2024-03-04 01:33:43 +09:00
Ilya Grigoriev
96bf190234 Nightly clippy fixes
There are a few additional warnings because of
https://github.com/rust-lang/rust-clippy/issues/12377, which is a
nightly-only bug that will hopefully be fixed.
2024-03-02 18:19:14 -08:00
Evan Mesterhazy
2f7b15b7b1 Add documentation comments for operation, transaction, and view types 2024-03-02 15:35:41 -05:00
Yuya Nishihara
f76830ab12 cli: translate last-minute EPIPE internally in handle_command_result() 2024-03-03 01:11:46 +09:00
Yuya Nishihara
ed1d2fde27 cli: move handle_command_result() to command_error module, make it less public
I don't think extensions would have to use this function, so made it pub(crate).
2024-03-03 01:11:46 +09:00
Yuya Nishihara
97024e5be4 cli: extract CommandError and helper functions to new module
The cli_util module is big enough to slow down Emacs, so let's split it up.
This change is an easy one.
2024-03-03 01:11:46 +09:00
Martin von Zweigbergk
4b1948c38e cli: don't use "check-out" as a verb (because it's not) 2024-03-02 06:59:09 -08:00
Yuya Nishihara
85586854f2 cli: add thin wrapper that runs --interactive diff editor conditionally
I considered inlining tx.select_diff(), but that looked a bit cryptic because
the arguments orders are reasonably different. This thin wrapper will help
enforce the common interactive editing behavior.
2024-03-02 23:33:45 +09:00
Yuya Nishihara
5df7a42915 merge_tools: move "ui.diff-instructions" to CLI and config/misc.toml
There are no users of this option in jj-lib. Let's simplify it.
2024-03-02 23:33:45 +09:00
Yuya Nishihara
b118e2f208 merge_tools: inline edit_diff() into DiffEditor::edit() 2024-03-02 23:33:45 +09:00
Yuya Nishihara
5cc89dde57 merge_tools: capture base_ignores and "ui.diff-instructions" by DiffEditor
For the same reason as the previous commit. The editor has nothing to be done
with the transaction.
2024-03-02 23:33:45 +09:00
Yuya Nishihara
fc4aa36a80 merge_tools: move run_mergetool() to MergeEditor::edit_file()
This makes sense because the editor doesn't interact with the transaction.
2024-03-02 23:33:45 +09:00
Yuya Nishihara
42f9ced423 cli: canonicalize cwd earlier and rely on that 2024-03-02 21:16:36 +09:00
Yuya Nishihara
ee4a06d847 cli: inline CommandHelper::new()
This constructor has too many arguments enough to introduce a parameter struct,
which would be identical to the CommandHelper type. Let's simply inline it as
there are no external callers.
2024-03-02 21:16:36 +09:00
Yuya Nishihara
b926fd844a merge_tools: extract configuration error to separate type
write!(ui.hint(), ..) error is suppressed because it seemed weird if the
configuration error had io::Error variant. The write error isn't important
anyway.
2024-03-02 10:31:27 +09:00
Yuya Nishihara
003b40d276 merge_tools: load diff/merge editor settings by caller
This moves the config loading closer to CLI args where --tool=<name> option
will be processed. The factory function are proxied through the command helper
so that the base_ignores can be attached there later.
2024-03-02 10:31:27 +09:00
Yuya Nishihara
863a26440e merge_tools: introduce Diff/MergeEditor newtypes
I'm going to make them be loaded by caller, and these newtypes will provide
extra compile-time safety (plus nicer API to be added later.) The error types
will be cleaned up later patches.
2024-03-02 10:31:27 +09:00
Yuya Nishihara
529acb3d16 merge_tools: process "ui.diff-instructions" option by caller
This gets rid of the last UserSettings dependency from edit_diff_external().
I'm going to remove it from edit_diff() too, and let callers pass a
preconfigured MergeTool struct instead.

These changes will make it easier to add --tool=<name> argument #2575.
2024-03-02 10:31:27 +09:00
Yuya Nishihara
fbabd0c9a7 merge_tools: take diff editor instruction as Option<&str>
This clarifies that the instructions text can be omitted. All callers appear to
pass non-empty instructions, though.
2024-03-02 10:31:27 +09:00
Yuya Nishihara
51496de9fb merge_tools: don't enable fsmonitor (and file size limit) in temporary snapshot
Because the snapshot directory is removed at the end of the function, it doesn't
make sense to enable watchman in it. The max_new_file_size parameter might be
somewhat useful, but it's unlikely that the temporary directory contains
gigantic node_modules tree for example. OTOH, the base_ignores matters since it
may contain common ignore patterns like *~.

This eliminates most of the UserSettings dependencies from this function.
2024-03-02 10:31:27 +09:00
dploch
570fd29ba3 commit_templater: support extensions of the template language 2024-03-01 10:42:51 -05:00
dploch
16755546bb commit_templater: make a bunch of types public for extensions 2024-03-01 10:42:51 -05:00
dploch
18670ff6e0 template_builder: support extending the core template build fn table 2024-03-01 10:42:51 -05:00
Yuya Nishihara
82b3017fda templater: add string.len() and list.len() methods 2024-03-01 08:51:20 +09:00
Yuya Nishihara
0656409904 templater: make .substr() be byte-index based, round towards origin
I'm going to add string.len() method which will return a length in bytes. The
number of the UTF-8 code points is useless metrics, and strings here are often
ASCII bytes, so let's simply use byte indices in substr().

If the given index is not at a char boundary, it will be rounded. I considered
making it an error, but that would be annoying. I would want to see something
printed by author.name().substr() even if it contained latin characters.

I've extracted index normalization function which might be used by other string
methods. The remaining part of substr() is trivial, so inlined it.
2024-03-01 08:51:20 +09:00
Yuya Nishihara
0831ed09b6 templater: extract fallible i64->isize conversion to helper function 2024-03-01 08:51:20 +09:00
Yuya Nishihara
9698a13747 cli: don't ignore 'diff --tool=:builtin', report error
Before, --tool=:builtin argument was ignored and the tool was loaded from
"ui.diff.tool" option. Since there is no single builtin diff format, :builtin
doesn't make sense here. Maybe we can translate ":<format>" to the internal
diff format instead, but that will also mean "ui.diff.tool" and ".format" can
be merged.

This partially reverts 409356fa5b "merge_tools: enable `:builtin` as default
diff/merge editor."
2024-03-01 08:51:06 +09:00
Yuya Nishihara
8148daa229 merge_tools: extract function that doesn't look up :builtin merge tool
The :builtin tool only applies to merge or diff editor.
2024-03-01 08:51:06 +09:00
Yuya Nishihara
d7ad054168 merge_tools: inline get_tool_config_from_args()
I'm going to split get_tool_config() to fix "diff --tool=:builtin", and it
doesn't make sense to duplicate get_tool_config_from_args() per backing
get_tool_config() functions.
2024-03-01 08:51:06 +09:00
Yuya Nishihara
601b75c556 tests: move strip_last_line() to common module 2024-03-01 08:51:06 +09:00
Yuya Nishihara
1d4860c9b5 templater: propagate <out-of-range date> as an error
Since we've added runtime error handling, it makes sense to not stringify an
error in time_util.
2024-02-29 01:30:43 +09:00
Yuya Nishihara
2007b9be53 templater: use cached current timestamp to calculate .ago()
For better or worse, this produces more stable output. It's also a bit faster.
2024-02-29 01:30:43 +09:00
Martin von Zweigbergk
bce8cb901f merge-tools: make :builtin materialize conflicts
This make :builtin render conflicts as conflict markers instead of
panicking. To support conflicts properly, we also need to parse the
conflict markers (calling `update_from_content()`) after the user
closes the editor.
2024-02-28 07:49:26 -08:00
Yuya Nishihara
aa79582092 templater: translate UTF-8 conversion error to runtime error
This isn't a problem as of now, but we'll probably add commit.diff() or
something later.
2024-02-29 00:39:31 +09:00
Yuya Nishihara
26c182a0b0 templater: turn some integer overflow into evaluation error
FWIW, this kind of errors can be checked at parsing phase if we implement
constant folding. I don't think that would matter in practice, though.
2024-02-29 00:39:31 +09:00
Yuya Nishihara
0519954d4f templater: make property functions return result
Also removed some trivial unwrap()ing.
2024-02-29 00:39:31 +09:00
Yuya Nishihara
42aa5f0bd3 templater: add runtime error type and propagation path
A runtime error will be printed inline. This simplifies error handling, and I
think it's better behavior overall. "jj log" won't be terminated just because
"gpg" crashed during signature verification for example. When property
evaluation failed, the error propagates to the closest template expression, and
the error message is printed there. Then, template output continues as long as
the output stream is open.

If we add revset() function for example, dynamic revset evaluation error will be
displayed inline. Static revset expression will still be processed at parsing
phase (to cache the evaluation result), and the error will be reported early.

One caveat: a string argument passed to e.g. .contains(needle) can be a
template, so the evaluation error would be swallowed there.
2024-02-29 00:39:31 +09:00
Yuya Nishihara
7be7c6f3cd cli: don't panic on repository initialization in missing cwd
It's unlikely to fail, but possible under racy situation.
2024-02-28 09:03:16 +09:00
Yuya Nishihara
fd0ace4c26 cli: remove redundant --git-repo path canonicalization
It was moved to CLI at 42252a2f00 "cli: on `jj init --git-repo=.`, use
relative path to `.git/`." As far as I can tell, .canonicalize() is needed
to calculate relative path, which is now processed differently in
Workspace::init_external_git() and GitBackend::init_external().
2024-02-28 09:03:16 +09:00
Yuya Nishihara
4c16c05be1 cli: move --git-repo path normalization back from workspace
This reverts dc074363d1 "no-op: Move external git repo canonicalization into
Workspace::init_git_external." As I said in the PR comment, appending ".git"
is normalization of the user input, which is IMHO more appropriate to be done
in the CLI layer.
2024-02-28 09:03:16 +09:00
Yuya Nishihara
8d0414549b cli: unblock "jj git init --colocate" in existing Git repo directory
I'm not sure what's the conclusion in #2747, but I don't think there is a
disagreement on allowing --colocate to import existing Git repo.
2024-02-28 09:03:16 +09:00
Yuya Nishihara
356037379a cli: narrow scope of canonicalized cwd in git_init()
It's only needed to calculate relative path of canonicalized workspace_root,
and I'm going to remove it.
2024-02-28 09:03:16 +09:00
Yuya Nishihara
7bc4521862 templater: expand similarity hint with aliases
-Tbuiltin now shows the list of the builtin templates, which seems useful.
2024-02-28 09:03:04 +09:00
Yuya Nishihara
71a9dc8304 templater: add similarity hint to no such method/keyword errors
The translation from method error to keyword error can go wrong if the context
object had n-ary methods (n > 0), which isn't the case as of now. For
simplicity, arguments error is mapped to "self.<name>(..)" suggestion.

Local variables and "self" could be merged without using extra method, but
we'll need extend_*_candidates() to merge in symbol/function aliases anyway.
2024-02-28 09:03:04 +09:00
Yuya Nishihara
de1e4a39f4 revset: add hint to innermost error
This seems more useful if aliases are nested. The innermost error usually
contains the problem, and the outer errors are contexts where aliases are
expanded.
2024-02-28 09:03:04 +09:00
Yuya Nishihara
a235aa51f6 templater: move build_core_method() to table object
Just for convenience.
2024-02-28 09:03:04 +09:00