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

890 commits

Author SHA1 Message Date
Yuya Nishihara
195e788f92 cli: colorize only "Error: "/"Warning: "/"Hint: " headings
I think long message is easier to read if printed in the default color. Errors
and warnings are printed in bold to make them distinct.
2024-03-26 11:23:13 +09:00
Yuya Nishihara
078acc9eee cli: print "Failed to wait on pager" as warning
Since it doesn't terminate jj, it can be considered a warning.
2024-03-26 11:23:13 +09:00
Yuya Nishihara
31525705db cli: add "Hint: " or "Warning: " heading to almost all messages
It's inconsistent that some warnings have headings and some don't, and it seems
the choice is arbitrary. Let's unify the style. There are two exceptions:
1. continued line following labeled message,
2. "unrecognized response" followed by prompt.
2024-03-26 11:23:13 +09:00
Yuya Nishihara
6a98799176 tests: use jj_cmd_ok() in test_git_fetch_single_remote() 2024-03-26 11:23:13 +09:00
Yuya Nishihara
b363e695e4 commit_templater: make git_head return Option<RefName> instead of Vec<_>
Since we've introduced Option type, it no longer makes sense that git_head
returns a Vec<RefName>.
2024-03-26 00:28:43 +09:00
Yuya Nishihara
bd3d9309ff cli: add convenient methods to print hint or warning with default headings
The lowercase "warning: " is unified to "Warning: " as it is the jj's
convention afaik.

The _default() suffix could be dropped from these methods, but it's probably
better to break the existing codebase for the moment. Otherwise, the caller
might do writeln!(ui.warning(), "Warning: ..").
2024-03-26 00:28:27 +09:00
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