Commit graph

1127 commits

Author SHA1 Message Date
Yuya Nishihara
7341bff2f4 diff_util: remove WorkspaceCommandHelper dependency from inner show functions
I've added a struct similar to RevsetWorkspaceContext. It can be a closure,
but we'll need to duplicate format_file_path() function anyway if we add
commit.diff() template.
2024-05-14 09:36:13 +09:00
Yuya Nishihara
b6d95c3504 cli: use high-level show_diff() function in cmd_status()
As I'm going to remove &WorkspaceCommandHelper from these functions, it will
be a bit more verbose to call low-level show_*() functions.
2024-05-14 09:36:13 +09:00
Yuya Nishihara
13f10f6957 diff_util: pass repo in to inner show functions by argument
I'm going to remove &WorkspaceCommandHelper dependency. This is the easy part.
2024-05-14 09:36:13 +09:00
Yuya Nishihara
6e7c9f15fd diff_util: pass term_width() in to show_diff_stat() by argument
This patch removes ui dependency from show_diff_stat().
2024-05-14 09:36:13 +09:00
Yuya Nishihara
f614c96383 diff_util: remove CommandError dependency from show functions
Suppose we add commit.diff() template method, some of these show_*() functions
will be called from there. CommandError shouldn't appear in that layer.
2024-05-14 09:36:13 +09:00
Martin von Zweigbergk
ee9d3271c1 cleanup: propagate errors from Commit::predecessors() 2024-05-13 07:39:14 -07:00
Martin von Zweigbergk
0a758e7024 cleanup: propagate errors from Commit::parents()
The function now returns an iterator over `Result`s, matching
`Operation::parents()`.

I updated callers to also propagate the error where it was trivial.
2024-05-13 07:39:14 -07:00
Martin von Zweigbergk
677081ef71 rebase: avoid an unnecessary lookup of parent commits 2024-05-13 07:39:14 -07:00
Yuya Nishihara
728e9e0772 cli: reuse ConfigLevelArgs for "config list --user/--repo"
This is a bit tricky, but we can reconfigure group attributes by using
mut_group().

https://docs.rs/clap/latest/clap/struct.Command.html#method.mut_group
2024-05-12 23:15:58 +09:00
Yuya Nishihara
717b42245c cli: rename ConfigArgs to ConfigLevelArgs 2024-05-12 23:15:58 +09:00
Yuya Nishihara
95593598d5 cli: use command(flatten) instead of deprecated clap(..) 2024-05-12 23:15:58 +09:00
Yuya Nishihara
db75e19751 cli: insert tracing at editor/pager invocation
This should help debug Windows mess.
2024-05-12 23:06:14 +09:00
Yuya Nishihara
e3b3b5586f ui: add per-type FormatterFactory constructors, inline selection
This should be better than passing (bool, bool, bool) arguments.
2024-05-12 09:21:18 +09:00
Yuya Nishihara
46246a7734 ui: inline debug_color() and use_color() 2024-05-12 09:21:18 +09:00
Yuya Nishihara
46226a4c44 ui: forward .color() to FormatterFactory
This helps eliminate use_color() function.
2024-05-12 09:21:18 +09:00
Yuya Nishihara
0423e3e1ee ui: add helper function that sets up FormatterFactory
I'm going to split FormatterFactory::prepare() which takes 3 bool arguments,
and prepare() will be inlined there.
2024-05-12 09:21:18 +09:00
tinger
d0a29a831d cli: add ui.color = "debug"
When using `ui.color = "debug"`, changes in the output style
additionally include delimiters << and >>, as well as all active labels
at this point separated by ::. The output is otherwise unformatted and
the delimiters and labels inherit the style of the content they apply
to.
2024-05-11 10:16:09 +02:00
Yuya Nishihara
d6613304c9 cli: print deleted branch hints at end of "branch list" output
These hints shouldn't be interleaved in the template output. The new output
might look a little bit worse, but I don't think it's unacceptably bad.
2024-05-11 09:43:53 +09:00
Yuya Nishihara
2f3ac4e4d7 tests: snapshot both stdout and stderr in "branch list" tests 2024-05-11 09:43:53 +09:00
Yuya Nishihara
60825c4591 tests: use get_branch_output() at a few more places
Not all "branch list --all-remotes" callers are replaced because I'm going to
make get_branch_output() suppress hints by default, and there should be tests
for the hints.
2024-05-11 09:43:53 +09:00
Alexander Potashev
07559f24ec Refuse to split an empty commit with jj split.
Rationale: The user may be confused by the empty diff in the diff editor
tool if they accidentally run `jj split` on a wrong (empty) commit.
2024-05-10 19:37:28 +02:00
Yuya Nishihara
3307696ba8 cli: parse out redundant "all:" revset modifier in arguments and templates
This also means "all:" is allowed in default revsets (such as "revsets.log"),
but that seems okay. In revset aliases, "all:" isn't allowed because aliases
may be expanded to sub-expression position.

Closes #3654
2024-05-10 15:28:18 +09:00
Yuya Nishihara
ba73accac6 cli: use command helper to check if path argument is parsable as revset
There should be no reason to use low-level API.
2024-05-10 15:28:18 +09:00
Yuya Nishihara
12b873e1ef cli: port "branch list" to template
Perhaps, this can be used to generate parsable branches list.

The hint for deleted branches isn't migrated to the template. I'm thinking of
moving it out of the loop and printed once at the end. If we want to generate
a hint in template, we'll probably need local_ref.tracking_remote_refs(), etc.
that return a list of RefNames.
2024-05-10 08:36:38 +09:00
Yuya Nishihara
af9f9ba1e4 cli: filter out synced remote branches early
Perhaps, this make it a bit clearer when "deleted" local branches should be
displayed. In practice, this change is noop since remote_ref.target should
never be absent.
2024-05-10 08:36:38 +09:00
Yuya Nishihara
8e4f75552d templater: add tracking methods to remote RefName
More tests will be added later as "branch list" templates.

In "log" template, we might want to see the number of "local" commits ahead
of any tracked remotes. It can be implemented later in a similar way (or as a
nested remote_refs list.)
2024-05-10 08:36:38 +09:00
Yuya Nishihara
ccabb11890 templater: wrap RefName with Rc to copy OnceCell around
Because template is declarative language, and is evaluated as a tree, there
will be multiple copies of the same RefName object. This patch allows us to
cache ahead/behind counts which will be lazily calculated.
2024-05-10 08:36:38 +09:00
Yuya Nishihara
cb0964b1d0 templater: extract remote-only RefName constructor as well
I'm going to make these constructors return Rc<RefName>, and it seems better
to consolidate Rc wrapping functions.
2024-05-10 08:36:38 +09:00
Yuya Nishihara
e27421d2bd templater: extract trackable RefName constructors
They'll be called from cmd_branch_list().
2024-05-10 08:36:38 +09:00
Yuya Nishihara
9a5b001d58 templater: add SizeHint type to represent revset.count_estimate() value
We'll probably add binary comparison operators at some point, but this patch
also adds size_hint.zero() method. Otherwise, we'll have to write
"if(x.upper() && x.upper() == 0, ..)" to deal with None.

The resulting "branch list" template will look like:
```
separate(", ",
  if(!ref.tracking_ahead_count().zero(),
    if(ref.tracking_ahead_count().exact(),
      "ahead by " ++ ref.tracking_ahead_count().exact() ++ " commits",
      "ahead by at least " ++ ref.tracking_ahead_count().lower() ++ " commits")),
  if(!ref.tracking_behind_count().zero(),
    if(ref.tracking_behind_count().exact(),
      "behind by " ++ ref.tracking_behind_count().exact() ++ " commits",
      "behind by at least " ++ ref.tracking_behind_count().lower() ++ " commits")),
)
```
2024-05-09 08:51:34 +09:00
Yuya Nishihara
62decb76bc templater: add optional integer type
In order to port "branch list" to template, we need to somehow represent
revset.count_estimate() result as a template property. I'm going to add
SizeHint template type for that, and its .upper() and .exact() methods will
have to return optional integers.

Fortunately, the Integer type has no implicit conversion to bool, so
"if(optional_integer, ..)" is not ambiguous.
2024-05-09 08:51:34 +09:00
Yuya Nishihara
c2c160f635 templater: add helper method that unwraps Option<T> property
I'll add a few more optional property types, and I don't want to duplicate the
error message. Type names are capitalized for consistency.
2024-05-09 08:51:34 +09:00
Yuya Nishihara
04063a0efd templater: remove IntoTemplate abstraction, use extension method instead
This is a remainder of the previous refactoring series. into_template() could be
implemented as a non-extension method, which allows us to get rid of .clone()
from Literal property extraction. However, there wasn't measurable difference.
Let's not try to overly optimize things. It's probably simpler to switch to
Rc<str> if .clone() really matters.
2024-05-09 08:51:34 +09:00
Ilya Grigoriev
2760b23f8d cli jj util completion --help: Make the terminal output a bit prettier
Cc: https://github.com/martinvonz/jj/pull/2949#issuecomment-2098710774
2024-05-08 11:40:54 -07:00
Ilya Grigoriev
9be159342c config.md: advertise diffedit3 as an alternative to meld-3 diff editor
This is instead of https://github.com/martinvonz/jj/pull/3292, which would make
`diffedit3` built into `jj`. I still have some hope of eventually making
`diffedit3` into the default diff editor that is available without any
configuration, which probably requires building it into `jj`, but this may not
happen, and it wouldn't hurt to test `diffedit3` first. Some examples of
concerns (see also the discussion in that PR):

- It is only a guess on my part that this would make a good default. The editor
might not be polished enough, and most users are not used to 3-pane diff
editing. I think most users would like it if they tried it, but this might be
plain wrong.

- There are concerns about adding a heavyweight dependency on `jj`. While I
tried to make it as lightweight as possible, it still unavoidably includes a web
server.

- There may be ways to bundle `diffedit3` with `jj` without combining them in a
single binary.
2024-05-08 11:38:41 -07:00
Martin von Zweigbergk
dbba2edc57 commit: add a helper for returning parent tree of Commit
The pattern of getting the parent tree of a commit gets repeated a
bit. Let's add a helper on `Commit`.
2024-05-07 19:35:03 -07:00
Martin von Zweigbergk
428e209304 cleanup: consistently use BackendResult
We have the type alias so we should use it consistently.
2024-05-07 19:35:03 -07:00
Martin von Zweigbergk
61e4e3627c
branching: merge v0.17.1 into main 2024-05-07 08:54:35 -07:00
Yuya Nishihara
0a5c98d9fe cli: status: exclude working-copy commit from conflicts revset by ancestry
This should be cheaper than using a generic difference expression.
2024-05-07 22:10:50 +09:00
Yuya Nishihara
c1d934a08a cli: status: evaluate conflicts revset as a user expression
Otherwise, it would panic if immutable_heads() contained unresolved symbols.
2024-05-07 22:10:50 +09:00
Yuya Nishihara
76b6d031d7 cleanup: rustfmt cli/src/commands/status.rs 2024-05-07 22:10:50 +09:00
Eric Roshan-Eisner
b67e198cde cli: status: only scan through mutable changes to find conflicts
Fixes #3628
2024-05-06 17:32:50 -07:00
dploch
20af8c79ef revset: support custom filter extensions 2024-05-06 10:42:01 -04:00
dploch
387ae9bce1 revset: support defining custom revset functions 2024-05-06 10:42:01 -04:00
dploch
4e0abf0631 revset: make RevsetParseContext opaque 2024-05-06 10:42:01 -04:00
Ilya Grigoriev
70b517ca64 conflicts.rs: label conflict number and sides next to conflict markers
For example, 

```
<<<<<<< Conflict 1 of 3
+++++++ Contents of side #1
left 3.1
left 3.2
left 3.3
%%%%%%% Changes from base to side #2
-line 3
+right 3.1
>>>>>>>
```

or

```
<<<<<<< Conflict 1 of 1
%%%%%%% Changes from base to side #1
-line 3
+right 3.1
+++++++ Contents of side #2
left 3.1
left 3.2
left 3.3
>>>>>>>
```

Currently, there is no way to disable these, this is TODO for a future
PR. Other TODOs for future PRs: make these labels configurable. After
that, we could support a `diff3/git`-like conflict format as well, in
principle.

Counting conflicts helps with knowing whether you fixed all the
conflicts while you are in the editor.

While labeling "side #1", etc, does not tell you the commit id or
description as requested in #1176, I still think it's an improvement.
Most importantly, I hope this will make `jj`'s conflict format less
scary-looking for new users.

I've used this for a bit, and I like it. Without the labels, I would see
that the two conflicts have a different order of conflict markers, but I
wouldn't be able to remember what that means. For longer diffs, it can
be tricky for me to quickly tell that it's a diff as opposed to one of
the sides. This also creates some hope of being able to navigate a
conflict with more than 2 sides.

Another not-so-secret goal for this is explained in
https://github.com/martinvonz/jj/pull/3109#issuecomment-2014140627. The
idea is a little weird, but I *think* it could be helpful, and I'd like
to experiment with it.
2024-05-05 18:42:14 -07:00
Ilya Grigoriev
2f48f76e85 test_resolve_command: use diff --git for readability 2024-05-05 18:42:14 -07:00
Ilya Grigoriev
04158c3744 External merge tools: better error message for unsupported usage
I've heard of one instance of a person being confused by the error.

Previously, the error was:

```
Error: Failed to load tool configuration
Caused by: To use `diffedit3` as a merge tool, the config `merge-tools.diffedit3.merge-args` must be defined (see docs for details)

```

Now, it is:

```
Error: The tool `diffedit3` cannot be used as a merge tool with `jj resolve`.
Hint: To use `diffedit3` as a merge tool, the config `merge-tools.diffedit3.merge-args` must be defined (see docs for details)
```

TODO for future PR: allow setting `merge-tools.TOOL.edit-args = false` so that
attempting to use TOOL as a diff editor fails. This would be helpful, for
example, for the `vscode` tool.
2024-05-05 18:33:53 -07:00
Martin von Zweigbergk
3dab92d2e9 cli: move revsets.log default to config file 2024-05-05 09:08:14 -07:00
Yuya Nishihara
f1fd1d8071 cli: show hint for inner fileset/revset/template errors
Note that find_source_parse_error_hint() has recursion, but it should terminate
because err.source() shouldn't have a cycle.
2024-05-05 11:16:17 +09:00