Commit graph

5484 commits

Author SHA1 Message Date
Evan Mesterhazy
a335321c45 Add documentation comments for several types
These comments are intended to make it easier for new developers to get up to
speed with the project. This is just a starting point... there are other types
and functions that could benefit from documentation.
2024-03-02 15:01:55 -05:00
Evan Mesterhazy
b8aa9a1a2b Make a minor simplification to CommitBuilder::write
There's no need to have a block of code at the beginning of the function to
cache the rewrite source id. We can simply check the necessary condition before
calling record_rewritten_commit.

This tweak makes the function a little easier to read since we don't check the
condition until we're ready to do the work.
2024-03-02 13:40:18 -05:00
Evan Mesterhazy
276276ea01 Reorder functions in impl Repo for MutableRepo to match trait
This is just a clean-up to silence a lint that complains that the functions are
defined in a different order than they are in the trait.
2024-03-02 13:40:04 -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
Philip Metzger
494eba82b5 docs: Add a short section on branch movement.
This is something which should've been written down long ago. This is a follow-up upon 
another question from Julia Evans in Discord. 

Thank you again for asking such good questions.
2024-03-02 15:51:58 +01: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
dependabot[bot]
2a3b0eeaec cargo: bump the cargo-dependencies group with 1 update
Bumps the cargo-dependencies group with 1 update: [indexmap](https://github.com/indexmap-rs/indexmap).


Updates `indexmap` from 2.2.4 to 2.2.5
- [Changelog](https://github.com/indexmap-rs/indexmap/blob/master/RELEASES.md)
- [Commits](https://github.com/indexmap-rs/indexmap/compare/2.2.4...2.2.5)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-01 10:29:40 -06: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
Evan Mesterhazy
5c252bd8e4 Add test cases where HexPrefix::new fails due to invalid inputs 2024-03-01 10:00:22 -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
dependabot[bot]
441572f2ca cargo: bump the cargo-dependencies group with 2 updates
Bumps the cargo-dependencies group with 2 updates: [indexmap](https://github.com/indexmap-rs/indexmap) and [syn](https://github.com/dtolnay/syn).


Updates `indexmap` from 2.2.3 to 2.2.4
- [Changelog](https://github.com/indexmap-rs/indexmap/blob/master/RELEASES.md)
- [Commits](https://github.com/indexmap-rs/indexmap/compare/2.2.3...2.2.4)

Updates `syn` from 2.0.51 to 2.0.52
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/2.0.51...2.0.52)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
- dependency-name: syn
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-29 08:38:58 -08:00
Austin Seipp
e8f01ce19a github: add nix-on-macOS to the CI matrix
The aarch64-darwin macOS runners are actually quite speedy, often the fastest
builders anyway. With the recent improvements to the Nix CI speed in 3f7b5a75e,
this shouldn't be a bottleneck, and will catch build regressions.
2024-02-28 13:56:07 -08:00
Austin Seipp
fe3ffda7ef nix: fix nix-on-macOS build
When the `jj-proc-macros` crate was introduced, it triggered an underlying
bug in `nextest`, which is the test harness we use in the Nix build. This is
upstream Nextest bug 267. The long and short of it is that `rustc` fails to
find needed libraries whenever the proc macros are loaded.

This can easily be worked around however, by setting
`DYLD_FALLBACK_LIBRARY_PATH` to an appropriate value in the devShell and in the
`preCheck` phase of the main expression.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-02-28 13:56:07 -08:00
Austin Seipp
29e959d18c nix: s/rust-version/ourRustVersion/g
This naming is just more consistent with the surrounding code.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-02-28 13:56:07 -08: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
dependabot[bot]
2466414f39 cargo: bump the cargo-dependencies group with 1 update
Bumps the cargo-dependencies group with 1 update: [rayon](https://github.com/rayon-rs/rayon).


Updates `rayon` from 1.8.1 to 1.9.0
- [Changelog](https://github.com/rayon-rs/rayon/blob/main/RELEASES.md)
- [Commits](https://github.com/rayon-rs/rayon/compare/rayon-core-v1.8.1...rayon-core-v1.9.0)

---
updated-dependencies:
- dependency-name: rayon
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-28 16:10:31 +00: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
7e127f500a docs: update remaining references on "jj init --git-repo" 2024-02-28 09:03:16 +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