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

731 commits

Author SHA1 Message Date
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
Yuya Nishihara
bdbb2dec65 templater: migrate core template methods to symbol table
Except for the generic list and template methods. We'll need a bit more
refactoring to migrate List<T> method builders to be compatible with
non-capturing fn() type.
2024-02-28 09:03:04 +09:00
Yuya Nishihara
e1864d90dd templater: extract substr() method body to function
This function isn't trivial, so it's probably better to not inline in the
templater binding.
2024-02-28 09:03:04 +09:00
Martin von Zweigbergk
81e9ba3d51 workspace: make recovery commit empty instead of deleting everything
The recovery commit we create when we run into a stale working copy
with a missing operation currently has an empty tree. Our commit
backend at Google creates an index of which files changed in each
commit. That gets really expensive when a commit deletes all files in
the repo, as these recovery commits do. So for our backend, it is much
better to make the recovery commit empty instead. That's what this
patch does.

It almost doesn't matter functionally what tree we use for it since we
don't care much about the current tree when snapshotting the working
copy. It does matter in a few cases, however. One case is for
conflicts. In that case, it's likely better to use the recovery
commit's parent as base tree (as we do by making the recovery commit
empty) than to use an empty tree, as that would guarantee that all
conflicts would be considered resolved. (Side note: perhaps we should
start looking at the current commit's parent instead of looking at the
current commit when snapshotting, but that's a topic for another day.)
2024-02-27 06:45:25 -08:00
Yuya Nishihara
9ad2fee72b templater: migrate operation template methods to symbol table 2024-02-27 11:00:33 +09:00
Yuya Nishihara
10acfdcb86 templater: extract generic type aliases for method build fn and table
I also added a type alias for HashMap<&'static str, _> because it's tedious to
repeat that in function body.
2024-02-27 11:00:33 +09:00
Yuya Nishihara
523f8b26ec templater: migrate other commit template methods to symbol table 2024-02-27 11:00:33 +09:00
Yuya Nishihara
8226584ae9 templater: inline parse_optional_integer() in method body
If each method body is split to closure, this parse helper will no longer be
able to capture the environment.
2024-02-27 11:00:33 +09:00
Yuya Nishihara
1b4c339203 templater: extract stub function that resolves method name
We'll probably add "Did you mean?" hint there.
2024-02-27 11:00:33 +09:00
Martin von Zweigbergk
a976b5d482 cli: document that we create a new working-copy commit for abandoned one
When we abandon a working-copy commit, we create a new working-copy
commit on top. This behave is very useful, but it's not obvious. Let's
document it.

Thankfully, 2bbefcc338 (rewrite: default to not simplifying ancestor
merges) means that there are much fewer commands where we need to
document this behavior.
2024-02-25 18:52:10 -08:00
Yuya Nishihara
fd4acf679c templater: clone WorkspaceId/OperationId into templater to simplify lifetime
There would be no measurable cost to clone a couple of id objects.
2024-02-26 10:27:45 +09:00
Yuya Nishihara
68b1f869b6 templater: extract Commit methods to HashMap
There are two major goals:
 * provide typo hints in a similar way to revset
 * make methods extensible

The created method table is bound to the 'repo lifetime because of the problem
described in the inline comment. It would be nice if we can build cachable
core method table for<'repo> CommitTemplateLanguage<'repo, '_>, but I couldn't
figure out how.
2024-02-26 10:27:45 +09:00
Yuya Nishihara
0d77ce5ba9 templater: inline capture variables in each method body of Commit type
Each method body will be turned into a closure.
2024-02-26 10:27:45 +09:00
Paulo Coelho
e9243a7638 cli branch list: list tracked branches
Add an option to list tracked branches only

This option keeps most of the current `--all` printing logic, but:

- Omits local Git-tracking branches by default (can be extended to
  support filtering by remote).
- Skip over the branch altogether if it doesn't contain tracked remotes
- Don't print the untracked_remote_refs at the end

Usage:

`jj branch list -t`
`jj branch list --tracked`
`jj branch list --tracked <branch name>`
2024-02-26 01:05:07 +00:00
Martin von Zweigbergk
b695fa1d82 cli: make rebase --skip-empty keep already empty commits
I think the user usually wants to abandon only newly empty commits. I
think they should use `jj abandon` if they want to get rid of already
empty commits. By keeping already empty commits, we don't need to
special-case the working copy and merge commits.
2024-02-25 16:39:05 -08:00
Yuya Nishihara
7525fac12a templater: add special "self" variable to refer to top-level object
This allows us to call alias function with the top-level object.

For convenience, all self.<method>()s are available as keywords. I don't think
we'll want to deprecate them. It would be tedious if we had to specify
-T'self.commit_id()' instead of -Tcommit_id.
2024-02-25 09:01:04 +09:00
Yuya Nishihara
bbf88643cc templater: inline wrap_fn() helpers
If I remember correctly, wrap_fn() was added to help type inference. It no
longer makes sense because the type is coerced by TemplateFunction::new()
and language.wrap_*().
2024-02-25 09:00:56 +09:00
Yuya Nishihara
f0ce448609 templater: merge build_*_keyword_opt() functions into method builders
template_parser::expect_no_arguments(function) is copied to each method body.
We might want to add some helper macros later.
2024-02-25 09:00:56 +09:00