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

884 commits

Author SHA1 Message Date
Yuya Nishihara
2e91146d67 cli: highlight "Error: " headings 2024-03-26 00:28:27 +09:00
Yuya Nishihara
1ebe751c42 cli: highlight "Warning: " and "warning: " headings 2024-03-26 00:28:27 +09:00
Yuya Nishihara
78ce9eae65 cli: highlight "Hint: " heading
The existing .hint() method is renamed to .hint_no_heading() to clarify that
it's not the default choice to print a hint. I'll add .hint_default() later,
which will be the shorthand for .hint_with_heading("Hint: ").
2024-03-26 00:28:27 +09:00
Yuya Nishihara
894219dd77 formatter: add wrapper that writes labeled heading once with content
This will be used to label "Error: " heading and content differently. I want
to see an error message in the default (white) color because it's easier to
read, but I still want to highlight the "Error: " heading.

We can achieve that without introducing new wrapper, but the resulting code
would look something like "writeln!(ui.error("Error: ")?, ..)?", and it would
get messier if the caller had to suppress io::Error.
2024-03-26 00:28:27 +09:00
Martin von Zweigbergk
d2043f069e repo: delete record_rewritten_commit()
I don't think we have any callers left that call
`record_rewritten_commit()` multiple times within a transaction and
expect it to result in divergence. I think we should consider it a bug
to do that.
2024-03-25 06:53:14 -07:00
Martin von Zweigbergk
e55168fa3e repo: make record_rewritten_commit() accept only one replacement id
All callers now pass a single new commit and I would like to keep it
that way.
2024-03-25 06:53:14 -07:00
Yuya Nishihara
02d4d14211 next, prev: fix choice from more than two targets 2024-03-25 20:51:54 +09:00
Yuya Nishihara
15ff7dfd48 cli: indent commits summary in single revset resolution hint
This is the same formatting as "jj abandon" output. It should improve the
discoverability of the trailing hint.
2024-03-25 11:15:28 +09:00
Yuya Nishihara
65ef700f94 cli: format single revset resolution hint with reused template instance
I'm going to introduce two changes: 1. indent commit summary, 2. colorize
output. The former can be implemented without using the templater API, but the
latter can't.
2024-03-25 11:15:28 +09:00
Yuya Nishihara
96e0bc0bdd templater: turn logical && and || into short-circuiting operators
Since the context (or self) property is no longer passed by argument, it's easy
to implement short-circuiting behavior.
2024-03-25 11:15:18 +09:00
Yuya Nishihara
df7be43ab6 templater: update comment why Template isn't TemplateProperty<Output = ..>
They are similar in a way that both of them can represent dynamic/static
evaluation, but their behaviors are different in error handling.
2024-03-25 11:15:09 +09:00
Yuya Nishihara
577e030db2 templater: remove unused context parameter from Template<C>
IntoTemplate will be cleaned up later. Perhaps, the lifetime parameter can be
removed at this point, but I'm planning to remove the IntoTemplate trait at all.
2024-03-25 11:15:09 +09:00
Yuya Nishihara
24ab8f7011 templater: turn Root/PlaceholderTemplate into non-Template type
The type parameter 'C' will be removed from the Template trait, making it
represent a printable type or compiled template.

TemplateRenderer now holds Box<dyn _> template because it's unlikely that the
inner template type can be statically determined.
2024-03-25 11:15:09 +09:00
Yuya Nishihara
f312307cbf git-push: process --change branches first to avoid pushing old branch state
This fixes --change/--branch conflicts by making --change precede --branch. I
don't think this is the most obvious behavior, but it's the easiest workaround.
2024-03-24 16:20:26 +09:00
Yuya Nishihara
538bfbc8a4 git-push: filter out duplicated branch names by caller
This is the common pattern among other classify() loops. I also changed the
set to hold &str as it doesn't need owned strings.
2024-03-24 16:20:26 +09:00
Yuya Nishihara
d749ef0195 git-push: extract function that updates push-{change_id} branches 2024-03-24 16:20:26 +09:00
Yuya Nishihara
620f0cd35f git-push: check duplicated --change branch prior to recording branch_updates
It could be moved before set_local_branch_target() to not update the local
branch, but it seemed weird that --change is silently ignored. This
inconsistency will be addressed later.
2024-03-24 16:20:26 +09:00
Yuya Nishihara
f88679bb45 tests: run "git push" with both --change and --branch arguments
It's unclear whether --change should precede or not, but it's wrong to try to
push the same branch twice.
2024-03-24 16:20:26 +09:00
Yuya Nishihara
e50d96e01d cli: split single revset resolution hint to paragraphs
Perhaps, this makes it slightly easier to spot the last "Hint:" line. We can
also render "Error:" and "Hint:" prefixes in different color/style.
2024-03-24 10:45:52 +09:00
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