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

865 commits

Author SHA1 Message Date
Yuya Nishihara
b77a110e8a cli: remove less-frequently-used user_error factories 2024-03-24 10:45:52 +09:00
Yuya Nishihara
2523dc188c cli: allow to attach multiple hints to CommandError
Even though the number of the hints is usually 0 or 1, this simplifies the
API and hints handling.
2024-03-24 10:45:52 +09:00
Yuya Nishihara
bb0dcc059c cli: extract helper that prints error message, sources, and hint 2024-03-24 10:45:52 +09:00
Yuya Nishihara
aeb3470b5d cli: reorganize CommandError as (kind, err, hint) tuple
This helps to implement CommandError::add_hint(). The inner errors could be
embedded in the enum as before, but they're mostly of the same type. And I think
it's okay to use downcast_ref() to deal with the clap::Error special case.
2024-03-24 10:45:52 +09:00
Yuya Nishihara
7a2077a434 cli: extract clap::Error handling to function 2024-03-24 10:45:52 +09:00
Yuya Nishihara
c333481496 cli: add more CommandError factory functions, consolidate inner type
I'm going to reorganize CommandError as (kind, err, hints) tuple so that we
can add_hint() to the constructed error object.

Some config error messages are slightly adjusted because the inner error is
now printed in separate line.
2024-03-24 10:45:52 +09:00
Yuya Nishihara
c311131ee2 log: encode elided node as None
Since elided graph entry has no associated commits, it makes some sense to
represent as None?
2024-03-24 10:32:15 +09:00
Yuya Nishihara
2fc7febaef commit_templater: teach elidable (or optional) commit
I think Option<Commit> is the simplest encoding of the log node.

The behavior of an Option type is closer to nullable types rather than the
Option in Rust. I don't think we would want to write opt.map(|x| x.f()) or
opt.unwrap().f(). We can of course add opt?.f() syntax, but it will be a short
for "if(opt, opt.f())"?
2024-03-24 10:32:15 +09:00
Simon Wollwage
63771d6e84 cli: add option to list only conflicted branches
As requested in #1471, I added a new flag for `jj branch list` to only show branches that are conflicted.

Adds a unit test to check for listing only conflicted branches and regenerates the cli output to incorporate the new flag.

Closes #1471

reformat
2024-03-23 22:04:14 +09:00
Benjamin Tan
3034dbba3f git-push: Display messages from remote
The implementation of sideband progress message printing is aligned with
Git's implementation. See
43072b4ca1/sideband.c (L178).

Closes #3236.
2024-03-23 20:17:04 +08:00
Benjamin Tan
2831459a95 ui: Remove &mut requirement for prompt functions 2024-03-23 20:17:04 +08:00
Yuya Nishihara
fad712811c templater: leverage TemplateProperty::map/and_then() helpers 2024-03-23 16:22:17 +09:00
Yuya Nishihara
a3d44485f4 templater: add helper methods to map property like Option/Result
These two are common when implementing methods. Fortunately, the
"return-position impl Trait in traits" feature is stabilized in Rust 1.75.0,
so we don't need another variant of TemplateFunction.
2024-03-23 16:22:17 +09:00
Ilya Grigoriev
02a04d0d37 test_conflicts and test_resolve_command: use indoc! to indent conflict markers in tests
Apart from (IMO) looking nicer, this will also sidestep the potential problem
that if the file contains actual jj conflict markers (`>>>>>>>` in the beginning
of a line, for example), jj would currently have trouble materializing and
subsequently parsing conflicts in the file if it actually became conflicted.

I'll demo this bug in either this or a subsequent PR. It's the kind of bug that
sounds serious in theory but might never cause a problem in practice.

After this PR, only `docs/tutorial.md` has a conflict marker that's not indented.
There's only one there, so hopefully it won't be too much of a pain to deal with.

I also indented other strings in `test_conflicts.rs`. IMO, this looks nice and
more consistent with the `insta::assert_snapshot` output. I didn't spend the
time to do the same for `test_resolve_command`.
2024-03-22 23:27:25 -07:00
Aleksey Kuznetsov
d8c84940d9 cli: avoid bad hint "Prefix the expression with 'all'..."
There is no point of showing the hint for non-existent revision.

Also appends ':' to the 'all' to make the hint more precise.

#2451
2024-03-23 10:05:18 +05:00
Yuya Nishihara
00285be7a7 formatter: use write!() or writeln!() thoroughly, remove .write_str()
One less Formatter API.
2024-03-23 10:43:38 +09:00
Yuya Nishihara
911cf4b8f6 templater: remove Context type from TemplateLanguage/Property
Now a compiled template doesn't have a static Context type internally. A
property is basically of "Fn() -> Result<O, _>" type, and a type-erased "self"
variable will be injected as needed.

Template<C> types will be refactored separately.
2024-03-22 11:51:15 +09:00
Yuya Nishihara
0fad9c9795 templater: remove now unused TemplatePropertyFn wrapper 2024-03-22 11:51:15 +09:00
Yuya Nishihara
cecae849aa templater: don't define TemplateLanguage::Context statically
In short, this enables compilation of template of e.g. Vec<Commit> type by
using CommitTemplateLanguage.

A Template<C> was originally compiled for a specific type C, and invoked as
"Fn(&C) -> _". It was simple and intuitive, but we had to define the context
type C statically. Things got even worse by extensions support because we had
to provide object-safe hook point for each context type C.

This patch basically removes the Context type from compiled templates. The
"self" variable is injected through RefCell<Option<C>> placeholder. A compiled
template knows its "self" type, but the type can be decided per instance, not
per TemplateLanguage type. A drawback is that the "self" variable will have to
be cloned one more time.

The Template<C> abstraction no longer makes sense, and will be split to inner
Template<()> implementations (which usually represent printable types) and the
outer Template<C>.
2024-03-22 11:51:15 +09:00
Yuya Nishihara
7b641c0236 templater: add Template<C> adapter that evaluates Template<()> with value of C
The idea is basically the same as list.map(|x| ...) template. It compiles the
inner template with a placeholder variable of type 'C', and evaluate it for
each instance variable by injecting the variable through RefCell.
2024-03-22 11:51:15 +09:00
Yuya Nishihara
017026148b generic_templater: clone &Context to Self_ property like other languages
This prepares for removal of TemplateLanguage::Context type. "C: Clone" trait
bounds looked messy, but they can be removed soon.
2024-03-22 11:51:15 +09:00
Yuya Nishihara
915e75efc0 generic_templater: remove &language argument from keyword functions
Because GenericTemplateLanguage doesn't support any global resources, it no
longer makes sense to pass the language instance around to 0-ary keyword
functions.
2024-03-22 11:51:15 +09:00
Yuya Nishihara
2916bbbec5 templater: allow use of wrap_<type>() functions without borrowing &language
These .wrap_<type>() functions aren't supposed to capture resources from the
language instance. It was convenient that wrap_() could be called without fully
spelling the language type, but doing that would introduce lifetime issue in
later patches.

I added type alias L to several places because the language type is usually
called L in generic code.
2024-03-22 11:51:15 +09:00
Anton Älgmyr
e2eb5bddf9 Make node symbols templatable in the graphs.
Adds config options
* templates.log_graph_node
* templates.log_graph_node_elided
* templates.op_log_graph_node
2024-03-21 17:41:31 +01:00
Martin von Zweigbergk
e51878f4fd cli: show timestamp in local timezone and without millis and offset
As discussed in #2900, the milliseconds are rarely useful, and it can
be confusing with different timezones because it makes harder to
compare timestamps.

I added an environment variable to control the timestamp in a
cross-platform way. I didn't document because it exists only for tests
(like `JJ_RANDOMNESS_SEED`).

Closes #2900
2024-03-20 07:54:08 -07:00
Ilya Grigoriev
4fbe6aecc9 clippy: remove some unused code beta clippy/rustc compain about
There are still some warnings from (seemingly) clippy bugs. Quoting
myself from Discord:

> PSA: the latest beta cargo clippy (from Rust 1.78) has some problems
> that affect jj: https://github.com/rust-lang/rust-clippy/issues/12467
> and https://github.com/rust-lang/rust-clippy/issues/12377.  You could
> disable clippy::assigning_clones and clippy::empty_docs as a workaround.
> VS Code can disable them in rust-analyzer, you can also use
> https://github.com/ericseppanen/cargo-cranky (you can put Cranky.toml in
> the per-user gitignore).
2024-03-19 18:33:29 -07:00
Yuya Nishihara
54bb3b4114 cli: remove last use of resolve_multiple_nonempty_revsets() from cmd_run() 2024-03-18 18:23:03 +09:00
Tom Ward
933150d819 cli: allow colors in form #rrggbb
Changes the formatter to accept not only existing color names (such as "red" or
"green") but also those in the form #rrggbb, where rr, gg, and bb are two-digit
hexadecimal numbers. This allows much finer control over colors used.
2024-03-18 08:03:31 +00:00
Yuya Nishihara
3ffe3d9ed8 git-push: warn unmatched revision set per "-rREVISIONS" argument
If -rREVISIONS is specified, the user would probably expect the set contains
at least one local branch.
2024-03-18 09:32:43 +09:00
Yuya Nishihara
8de3932bda git-push: narrow search space of -rREVISIONS 2024-03-18 09:32:43 +09:00
Yuya Nishihara
bc7a42a00e git-push: do not error out on empty revision set
"-r REVISIONS" here specifies the search space of the branches to push, and
warned if no branches are found in that space. I don't think an empty set
should be an error, but a warning for consistency. The warning message will be
improved by the subsequent patches.
2024-03-18 09:32:43 +09:00
Yuya Nishihara
02c0927734 git-push: extract function that looks up branches by revisions
cmd_git_push() is large. Let's split it up.
2024-03-18 09:32:43 +09:00
Yuya Nishihara
4e9d35d049 cli: make "abandon" not fail with empty revset
This command belongs to the same category as "duplicate".

We might want a plural version of resolve_revset(), but I'm not sure whether
it should return Vec<Commit> or Revset. Let's revisit it later when we get
more callers.
2024-03-18 09:32:35 +09:00
Yuya Nishihara
f678ba08cf cli: make "duplicate none()" exit successfully
Per discussion in
https://github.com/martinvonz/jj/pull/3311#discussion_r1527171058

We can also rely on the default "Nothing changed." handling, but it seems
better to state the input set is empty.
2024-03-18 09:32:35 +09:00
Yuya Nishihara
f46b738f6e cli: include root() in the heads node of the immutable set expression
It helps to optimize '~immutable()' to '(immutable_heads() | root())..'.
2024-03-17 14:50:48 +09:00
Yuya Nishihara
50363419fb revset: substitute '~(::x)' to 'x..'
Suppose we have an alias 'immutable()' = '::immutable_heads()', user can
express (visible) mutable set as '~immutable()'. 'immutable_heads()..' can
terminate early, but a generic difference 'all() & ~immutable()' can't.
2024-03-17 14:50:48 +09:00
Yuya Nishihara
9207314173 revset: add substitution rule for "::x & ~(::y-)"
Suppose the generation value is usually small, it should be faster to do
bounded range look up first 'y-', then walk ancestors with the unwanted set
'y-..x'.
2024-03-17 14:50:48 +09:00
Yuya Nishihara
b2194d7d2b cli: use present tense "duplicate" in transaction description 2024-03-17 11:44:41 +09:00
Yuya Nishihara
dc7d1beff3 cli: remove .unwrap() from cmd_duplicate() and simplify new commits mapping 2024-03-17 11:44:41 +09:00
Yuya Nishihara
4e3c772428 cli: make "duplicate" evaluate source revisions all at once
There's a subtle behavior change that an empty revset is no longer rejected
individually, but I think that's good for "jj duplicate".

cmd_duplicate() was the last caller of index.topo_order().
2024-03-17 11:44:41 +09:00
Yuya Nishihara
a1b3b3c547 cli: extract helper that concatenates multiple revision args
I'm going to add one more callers.
2024-03-17 11:44:41 +09:00
dploch
d832b4488c operation_templater: support extensions of the template language 2024-03-16 10:32:53 -04:00
Martin von Zweigbergk
c55e08023e workspace: don't lose sparsed-away paths when recovering workspace
When an operation is missing and we recover the workspace, we create a
new working-copy commit on top of the desired working-copy commit (per
the available head operation). We then reset the working copy to an
empty tree because it shouldn't really matter much which commit we
reset to. However, when the workspace is sparse, it does matter, as
the test case from the previous patch shows. This patch fixes it by
replacing the `reset_to_empty()` method by a new `recover(&Commit)`,
which effectively resets to the empty tree and then resets to the
commit. That way, any subsequent snapshotting will result keep the
paths from that tree for paths outside the sparse patterns.
2024-03-16 07:30:36 -07:00
Martin von Zweigbergk
ffb12680a6 tests: demonstrate sparsed-away paths lost on stale-workspace recovery
As shown by the updated test case, when we recover from a working copy
pointing to a lost operation, the new working-copy commit after
snapshotting will have lost any files outside the sparse patterns.
2024-03-16 07:30:36 -07:00
Martin von Zweigbergk
0d197791a0 tests: add unsnapshotted changes in secondary workspace in recovery test
This adds modifed, removed, and added files in the secondary working
copy.
2024-03-16 07:30:36 -07:00
Martin von Zweigbergk
df9434bd4b tests: use short commit ids in workspace tests
It doesn't look like we need the full ids for anything and the full
ids are especially distracting in the test that uses the native
backend.
2024-03-16 07:30:36 -07:00
Alexis (Poliorcetics) Bourget
93c707a469 lib: improve error message for invalid string pattern, suggesting to use one of the known one 2024-03-16 14:22:16 +01:00
Ilya Grigoriev
8600750fce merge tools: split DiffEditWorkingCopies from DiffWorkingCopies
As suggested by @yuja in https://github.com/martinvonz/jj/pull/3296#discussion_r1525829712
2024-03-15 21:35:57 -07:00
Ilya Grigoriev
6a63c705aa merge tools: rename variable to make diff for the next commit simpler 2024-03-15 21:35:57 -07:00
Yuya Nishihara
429cdb38d7 cli: don't bury GitImportError sources
#3301
2024-03-16 12:51:18 +09:00