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

942 commits

Author SHA1 Message Date
Yuya Nishihara
0c4f4c8767 cli: extract evaluation part of resolve_single_rev_with_hint_about_all_prefix()
I'm going to reorganize "single"/"default_single" revset functions in a way
that resolve_single_rev_with_hint_about_all_prefix() is inlined.
evaluate_revset_to_single_commit() could be a private method of
WorkspaceCommandHelper, but I want to minimize the code that has to be hosted
there.
2024-04-02 15:17:12 +09:00
Yuya Nishihara
f04402e3c7 cli: extract function that creates "not a single revision" error
This function isn't small, so let's split up into two parts. The extracted
function is the part which depends on the commit summary template.
2024-04-02 15:17:12 +09:00
Evan Mesterhazy
ebe8e6adba Update jj split tests to show what happens to branches
When a commit is split, any branches pointing to it are moved to the second
commit created by the split. This is true even if the --siblings option is
used.


#3419
2024-04-01 21:19:29 -04:00
Evan Mesterhazy
976320726d Add a --siblings option to the jj split command
If the --siblings option is used, the target commit is split into two sibling
commits instead of parent and child commits. Any children of the original
commit will have both siblings as their new parents.


#2274
2024-04-01 19:22:47 -04:00
Evan Mesterhazy
c3ee86d92a Split rebase_descendants into two functions
This refactor will allow us to reuse new `rebase_descendants` function for the
`jj split --siblings` feature (#2274) and later possibly for `jj parallelize`
(#1079).
2024-04-01 19:22:47 -04:00
Martin von Zweigbergk
7b3f8e8cb6 resolve: remove --quiet flag, rely on global one 2024-04-01 13:00:27 -07:00
Martin von Zweigbergk
adf3b50209 cli: add a global --quiet flag, which silences status messages
Note that `jj resolve` already had its own `--quiet` flag. The output
with `--quiet` for that command got a lot quieter with the global
`--quiet` also taking effect. That seems reasonable to me.
2024-04-01 13:00:27 -07:00
Martin von Zweigbergk
4962d9af3b ui: make hint_*() methods return Option
Same reasoning as the previous patch: we can avoid doing work when
`--quiet` is passed.
2024-04-01 13:00:27 -07:00
Martin von Zweigbergk
e38e2904bb ui: make status() return a dyn Write, add status_formatter()
When the caller needs a formatter, it's because they're doing
something non-trivial. When the user passed `--quiet` (see upcoming
patch), we should ideally skip doing related work for print the
formatting output. It helps if the `Ui` object doesn't even return a
`Formatter` then, so the caller is forced to handle the quiet case
differently.

Thanks to Yuya for the suggestion.
2024-04-01 13:00:27 -07:00
Martin von Zweigbergk
b940f1a092 errors: don't use the ui.hint*() helpers
I'm about to make hints not get printed with `--quiet`, but error
hints are probably still useful to get. They shouldn't be a problem
for scripts since the script would have to deal with the error anyway.
2024-04-01 13:00:27 -07:00
Martin von Zweigbergk
aeaab8aad3 cli: add a Ui::status() helper for writing non-error to stderr
This clarifies that status messages are not errors, and allows us to
implement a global `--quiet` flag for silencing status messages.
2024-04-01 13:00:27 -07:00
Simon Wollwage
320f50e00f cli: rename --all to --all-remotes for branch list 2024-04-01 10:12:13 +09:00
Yuya Nishihara
6004efb3b2 cli: replace last use of evaluate_revset() with evaluate_programmatic()
evaluate_programmatic() should be allowed here. AFAIK, the contract is that
the expression should never contain any bare symbols and "fallible" symbol-like
expressions, which doesn't apply to branches() and remote_branches() functions.

evaluate_revset() is removed because there are no callers. However, it's simple
and basic function, so we might want to reintroduce it if needed.
2024-04-01 10:08:44 +09:00
Yuya Nishihara
b3d3b26656 cli: make check_rewritable() not evaluate revset to commit objects 2024-04-01 10:08:44 +09:00
Yuya Nishihara
784d735ecc cli: add convenient method to intersect user revset with other expression
This pattern is common, and most callers of evaluate_revset() can now be
migrated to the wrapper API.
2024-04-01 10:08:44 +09:00
Yuya Nishihara
690270670e cli: add convenient wrapper for user revset evaluation
Many callers of resolve_revset() and evaluate_revset() will be migrated to
this wrapper. "single" and "default_single" APIs won't be replaced because
they require more contexts to construct error messages.

id_prefix_context() now uses bare revset::parse() to avoid dependency cycle.
2024-04-01 10:08:44 +09:00
Evan Mesterhazy
75e938c6b8 Fix the description of the --source arg in the jj rebase --help docs 2024-03-31 16:42:38 -04:00
Simon Wollwage
8eed08b8b6 cli: allow branch list to combine -r and -a 2024-03-31 23:37:22 +09:00
Yuya Nishihara
a6615bf36d cli: render string pattern suggestion as a hint
Templater doesn't have the one yet, but I think it belongs to the same
category.

For clap::Error, we could use clap's own mechanism to render suggestions as
"tip: ...", but I feel "Hint: ..." looks better because our error/hint message
is capitalized.
2024-03-30 23:53:17 +09:00
Yuya Nishihara
d759ba11f1 revset: don't stringify StringPatternParseError
This helps to add hint at the CLI layer.
2024-03-30 23:53:17 +09:00
Yuya Nishihara
339b199ee3 templater: merge ParseIntError into generic Expression error
It was only needed to attach the source error object, which is now handled
by the outer error type.
2024-03-30 23:53:17 +09:00
Yuya Nishihara
76f3b80e8a templater: consolidate "unexpected expression" error constructors
I also renamed "UnexpectedExpression" to just "Expression" because "unexpected"
doesn't apply to "immutable" revset parse/evaluation errors.
2024-03-30 23:53:17 +09:00
Yuya Nishihara
b09732f4f8 revset, templater: split parse error constructor that sets source error object
I'm going to add RevsetParseError constructor for InvalidFunctionArguments,
with/without a source error, and I don't want to duplicate code for all
combinations. The templater change is just for consistency.

I couldn't find a good naming convention for the builder-like API, so it's
called .with_source(mut self, _). Another option was .source_set(source).
Apparently, it's not uncommon to name consuming constructor as
with_<something>().
2024-03-30 23:53:17 +09:00
Yuya Nishihara
db15571eca cli: simplify check for non-empty revisions with/without "all:"
If "all:" is specified, an empty set should be allowed within that expression.
So the additional check we need here is to ensure that the resulting set is not
empty.
2024-03-30 22:40:05 +09:00
Yuya Nishihara
05242c95cd cli: don't silently omit root parent by "jj new --insert-before"
Spotted by Benjamin Tan.
2024-03-30 22:40:05 +09:00
Yuya Nishihara
73b60903ce tree: flatten TreeMergeError into BackendError 2024-03-30 22:40:05 +09:00
Yuya Nishihara
08b5b66ad4 cli: let backend decide whether merge with root can be performed
One less CLI revset helper. It might look odd that "jj rebase" says "Merge
failed" whereas "jj new" doesn't, but that depends on where the BackendError
is detected.
2024-03-30 11:14:25 +09:00
Yuya Nishihara
f20004fffe git_backend: classify "merge with root" as user error
Perhaps, there will be more error types that hold BackendError internally, but
this change is good enough to handle a merge error.
2024-03-30 11:14:25 +09:00
Yuya Nishihara
91ff1fdd1e cli: extract CommandError::with_message() constructor 2024-03-30 11:14:25 +09:00
Yuya Nishihara
1e83faf4f8 tree: remove useless "Backend error" message from TreeMergeError
I don't think it adds any contextual information. TreeMergeError is somewhat
similar to BackendError.
2024-03-30 11:14:25 +09:00
Evan Mesterhazy
dd1def02e4 Move parse_string_pattern in cli to StringPattern::parse in lib
This commit moves the parse_string_pattern helper function into the
str_util module in jj lib and adds tests for it.

I'd like to reuse this code in a function defined by `UserSettings`, which is
part of the jj lib crate and cannot use functions from the cli crate.
2024-03-29 08:48:09 -04:00
Yuya Nishihara
f83d1a840e templater: don't panic on PropertyPlaceholder unset error
The idea is that, if .extract() succeeded in static context, it means the
property can be evaluated as constant. This will potentially eliminate
expect_string_literal_with(), though I'm not too sure if it's a good idea.
If needed, maybe we can extend the idea to suppress type/name resolution errors
by "if(some_static_config_knob, x, y)".
2024-03-29 19:15:02 +09:00
Yuya Nishihara
32b623db67 templater: propagate error from formatted string property 2024-03-29 19:15:02 +09:00
Yuya Nishihara
71c2006c9b templater: introduce Formatter wrapper to switch strict/lax evaluations
This allows us to propagate property evaluation error to a string property. For
instance, "s.contains(x ++ y)" will be an error if "y" failed to evaluate,
whereas bare "x ++ y" shouldn't.

The other implementation ideas:

 a. add Template::into_string_property() to enable strict evaluation
    => it's tedious to implement it for each printable type
 b. pass (formatter, error_handler) arguments separately
    => works, but most implementors don't need error_handler argument
 c. pass strict=bool flag around build_*() functions
    => didn't tried, but it would be more complicated than this patch

Because Template trait is now implementation detail of the templater, it
should be okay to use a non-standard formatter wrapper.
2024-03-29 19:15:02 +09:00
Benjamin Tan
e7edafc924 rebase: do not modify commit IDs if commit is unchanged after rebase 2024-03-29 15:22:50 +08:00
Yuya Nishihara
dcf75788e0 sparse: extract "set --reset" to subcommand
Since --reset conflicts with the other flags, "set --reset" seems odd.
2024-03-29 11:02:31 +09:00
Yuya Nishihara
db94848341 sparse: deduplicate edited patterns
Since "set --add" removes duplicated patterns, it makes sense for "edit" to do
the same thing.
2024-03-29 11:02:31 +09:00
Yuya Nishihara
28e4331787 sparse: extract "set --edit" to subcommand
Even though --edit can be combined with --add/--remove/--clear/--reset, I don't
think it's practically useful.
2024-03-29 11:02:31 +09:00
Yuya Nishihara
0711ac30c3 sparse: extract helper that updates sparse patterns within workspace lock
I assumed locked_wc.sparse_patterns() is cheap operation. If it isn't, a
locked_ws/wc should be passed to the callback instead.
2024-03-29 11:02:31 +09:00
Yuya Nishihara
fff852f136 sparse: parse and print patterns as workspace-relative paths
Per comment in
https://github.com/martinvonz/jj/pull/3379#pullrequestreview-1963841604

Though cwd-relative path might be useful for --remove, I don't think that's
the common use case. The new behavior is consistent with --edit.
2024-03-29 11:02:31 +09:00
Austin Seipp
2d0b6560e8 cli: allow multiple -r options for duplicate/abandon
Commands like `new`, `duplicate`, and `abandon` can take multiple revset
arguments which results in their collective union. They take the revisions
directly as arguments. But for consistency with many other commands, they can
also take the `-r` argument, which is a no-op. However, due to the flag being
specified as a `bool`, the `-r` option can only be specified once, so e.g.
`abandon -r x -r y` often fails. I normally use `-r` for consistency and muscle
memory, so this bites me often.

Instead, use `clap::ArgAction::Count` in order to allow `-r` to be specified
multiple times. It remains unused, of course.

With this change, all the following invocations are equivalent. Before this
change, the second example would fail due to  giving `-r` multiple times.

    jj abandon x y
    jj abandon -r x -r y
    jj abandon -r 'x | y'

Note: `jj new` already supported this exact case actually, but it used an
awkward trick where it used `.overrides_with()` in order to override *itself* so
it could be specified multiple times. I believe this is a bit clearer.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
Change-Id: Ib36cf81d46dae4f698f06d0a32e8fd3120bfb4a4
2024-03-28 15:29:47 -05:00
Yuya Nishihara
916dc30828 revset: use common argument error instead of FsPathParseError
It's not special compared to the other argument errors, and we can now track
the error source separately.
2024-03-28 10:53:06 +09:00
Yuya Nishihara
074e6e12bc revset, templater: include short parse error description in summary line
This makes the summary line more informative. Even though it just duplicates
the message printed later, I think it's easier to follow.

This patch also adjusts some RevsetParseError messages because it seemed
redundant to repeat "revset function", "argument", etc.
2024-03-28 10:53:06 +09:00
Yuya Nishihara
d17166628f revset, templater: simplify parse error impls by using thiserror
This patch moves all "source" errors to the source field to conform to
thiserror API. It will probably help to keep ErrorKind enums comparable.
2024-03-28 10:53:06 +09:00
Yuya Nishihara
2cd70bdf14 revset, templater: render parse error as usual error chain
Because the CLI error handler now prints error sources in multi-line format,
it doesn't make much sense to render Revset/TemplateParseError differently.

This patch also fixes the source() of the SyntaxError kind. It should be
self.pest_error.source() (= None), not self.pest_error.
2024-03-28 10:53:06 +09:00
Yuya Nishihara
844d3d0ff0 revset, templater: allow any kind of error as parse error source
I'm going to make TemplateParseError hold RevsetParseError as Box<dyn _>, but
Box<dyn std::error::Error ..> doesn't implement Eq. I could remove Eq from
ErrorKind enums, but it's handly if these enums remain as value types.

This change will also simplify fmt::Display and error::Error impls.
2024-03-28 10:53:06 +09:00
Yuya Nishihara
790b5846f6 sparse: don't use io::Error to report invalid path stored in repository
I think it's more like data corruption, which is usually reported as an
internal error.
2024-03-28 10:52:51 +09:00
Yuya Nishihara
5c22164a26 sparse: make "sparse set --edit" accept only workspace-relative paths
I don't think it needs to convert absolute file paths to workspace paths.
2024-03-28 10:52:51 +09:00
Yuya Nishihara
a2a9b7decb templater: add coalesce() function that selects first non-empty content
This can be used to flatten nested "if()"s. It's not exactly the same as "case"
or "switch" expression, but works reasonably well in template. It's not uncommon
to show placeholder text in place of an empty content, and a nullish value
(e.g. empty string, list, option) is usually rendered as an empty text.
2024-03-28 10:51:47 +09:00
Yuya Nishihara
423a2a5446 cli: colorize commits summary embedded in single revset resolution hint
I think a colorized commit summary is easier to follow.
2024-03-27 09:06:06 +09:00