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

1191 commits

Author SHA1 Message Date
Martin von Zweigbergk
331ebf4cef cli: use reverse-alphabet hex for branch name in jj git push --change 2023-02-13 22:49:21 -08:00
Martin von Zweigbergk
9887d2c3d6 templater: use reverse-alphabet hex for change ids 2023-02-13 22:49:21 -08:00
Martin von Zweigbergk
562042312d templater: inline trivial CommitOrChangeId::as_bytes() 2023-02-13 22:49:21 -08:00
Yuya Nishihara
b44148871a templater: save alias chain to report type/name error in original context
Since type/name checking is made after alias substitution, we need to preserve
the original context to generate a readable error message.

We could instead attach a stack of (alias_id, span) to ExpressionNode, but
the extra AliasExpanded node helps to capture downstream error by a single
.map_err() call.
2023-02-14 10:06:28 +09:00
Yuya Nishihara
bfdaaa4257 templater: implement symbol/function alias expansion
Test vectors are mainly copied from revset.rs and adapted to the template
syntax.

Closes #1190
2023-02-14 10:06:28 +09:00
Yuya Nishihara
6ebf05790f templater: add origin field to TemplateParseError to chain alias errors
Copied from 5df25cd834 "revset: add origin field to RevsetParseError to
chain alias errors."
2023-02-14 10:06:28 +09:00
Yuya Nishihara
d0715a0935 cli: load [template-aliases] section and pass around aliases table 2023-02-14 10:06:28 +09:00
Yuya Nishihara
9d356b8094 templater: add table of alias (decl, defn) rules
This is basically a copy of revset::RevsetAliasesMap. We could extract a
common table struct, but that wouldn't be worth the effort since the core
alias substitution logic can't be easily abstracted.
2023-02-14 10:06:28 +09:00
Yuya Nishihara
6c5ff5a2a7 cli: split up write_commit_summary() to avoid passing too many arguments
update_working_copy() borrows self.workspace mutably, which is the reason
why this function needs to borrow things explicitly.
2023-02-14 10:06:28 +09:00
Yuya Nishihara
493cb83fd5 cli: proxy parse_commit_template() through WorkspaceCommandHelper
I'll add an alias table there. Since this function borrows self, it can't
always be used in between mutable operations. For log-like commands, this
should just work fine.
2023-02-14 10:06:28 +09:00
Yuya Nishihara
81c8543621 cli: switch "debug template" command to new AST
This should be more readable than raw pest tree.
2023-02-13 02:11:19 +09:00
Yuya Nishihara
677ac54855 templater: build evaluatable expression from AST nodes 2023-02-13 02:11:19 +09:00
Yuya Nishihara
9dc68af4f9 templater: introduce AST structs
This prepares for template aliases support #1190. Unlike revset, template
expressions can be of various types, whereas alias substitution will process
untyped nodes. That's one reason that ExpressionNode is closer to parsed tree
than evaluatable Property structs. Another reason is that it's uneasy to split
name/type checking into "parsing" and "building property function" stages.

We could do alias expansion at once while building Property functions, but
that would make testing harder because Property isn't Debug + PartialEq.
2023-02-13 02:11:19 +09:00
Yuya Nishihara
7c6ddf9773 templater: duplicate parsing functions for reference
I'm going to split 'parse() -> Expression' functions into 'parse() -> AST'
and 'build(AST) -> Expression'. The duplicated functions will be baseline of
new 'parse() -> AST' functions.
2023-02-13 02:11:19 +09:00
Yuya Nishihara
8749a325e9 templater: move whitespace rule out of template node
For the same reason as b2825c22d7 "revset: move whitespace rule out of
expression."
2023-02-13 02:11:19 +09:00
Martin von Zweigbergk
aefd0fe69e cli: set LESSCHARSET=utf-8 for our default less -FRX pager
Without a pager configured (in `ui.pager` or `$PAGER`), running
`LC_CTYPE=foo jj log` would replace the Unicode characters in our
(Sapling's) "curved" graph style by escapes, like this:

```
@  1d4ae2372dd2 martinvonz@google.com 2023-02-11 14:56:00.000 -08:00 a8eac1f9efe8
<E2><94><82>  (no description set)
```

This fixes that by including the `LESSCHARSET=utf-8` environment
variable in our default `ui.pager` value.
2023-02-12 07:23:29 -08:00
Martin von Zweigbergk
170de4749f allow passing environment variables to external tools
We would like our default pager of `less -FRX` to also get passed
`LESSCHARSET=utf-8`. I don't like having defaults that the user can't
specify themselves, so this commits provides users with a way to pass
environment variables to their configured pager (or editor, or merge
tool, ...).

I didn't document this feature and I didn't add it to the config
schema because it seems it's going to be so rarely useful to users.
2023-02-12 07:23:29 -08:00
Vamsi Avula
98261e81e2 Fix typos and slightly simplify code from #1235 2023-02-12 03:17:40 +05:30
Vamsi Avula
daf7b656e3 config: add and parse ui.log_author_format for use in the default template
Supported values are,

- `none` for no author information,
- `full` for both the name and email,
- `name` for just the name,
- `username` for username part of the email,
- (default) `email` (or any other gibberish for that matter) for the full email.
2023-02-11 20:54:23 +05:30
Yuya Nishihara
c2b92f43c6 cli: do not report "broken pipe" if pager exits successfully
This partially reverts the change in d7f64c07e0 "cli: handle last-minute
ui.write() error." In this commit, I tried to handle the case when the pager
process goes through env/sh, and exits immediately with "command not found".
However, I missed EPIPE could also occur when the pager was closed by user.

Apparently, hg is killed by SIGPIPE in that case (exits with 141), and chg
exits with 255. With this change, jj will silently exits with 3.
2023-02-12 00:06:01 +09:00
Vamsi Avula
aacdcf629b author/committer templates: add a username method
I haven't used a proper email address parser as I'm not really sure if it's
worth the extra dependency and effort -- thoughts?
2023-02-11 15:38:27 +05:30
Martin von Zweigbergk
ee336a2e45 cli: delete builtin update/up aliases
These don't seem used much, and maybe we (or a customized build) will
want to use the name in the future.
2023-02-10 08:33:05 -08:00
Yuya Nishihara
d7f64c07e0 cli: handle last-minute ui.write() error
This works if the pager exits instantly and jj is slow enough to notice
EPIPE. If the pager exits late, no error would be reported.

Since the pager process is asynchronous, EPIPE could occur in
handle_command_result(). That's why I made it not panic.
2023-02-10 23:30:35 +09:00
Yuya Nishihara
686c1fb522 templater: allow trailing comma
While rewriting the default log template, I find it's annoying that I have
to remove "," from the last line.
2023-02-07 23:19:36 +09:00
Yuya Nishihara
ba1c4f5fe5 cli: replace all $variable matches found in edit/merge-args 2023-02-07 18:32:57 +09:00
Yuya Nishihara
a1bfe33a08 cli: expand $left/$right parameters in merge-tools.<name>.edit-args
And set edit_args = ["$left", "$right"] by default.
2023-02-07 18:32:57 +09:00
Yuya Nishihara
449e84d7ea cli: rename interpolate_mergetool_filename_patterns(), inline caller
I'll add string interpolation support to edit-args.
2023-02-07 18:32:57 +09:00
Yuya Nishihara
baa67fe1db cli: make interpolate_mergetool_filename_patterns() simply work with strings
The assumption here is temp_dir wouldn't contain invalid utf-8 bytes. If it
can contain invalid bytes, maybe we can remove temp_dir from arguments, and
chdir(temp_dir) instead.

This unblocks the use of Regex. We could use regex::bytes, but it's way
more complex as we would have to go back and forth between str/OsStr and
bytes.
2023-02-07 18:32:57 +09:00
Yuya Nishihara
d5f05b7897 cli: implement Default for MergeTool, do not override it with empty args
The default edit_args will be changed to ["$left", "$right"] to support
variable substitution without breaking the existing configuration too much.

The default merge_args could also be set if we could come up with something
meaningful.
2023-02-07 18:32:57 +09:00
Yuya Nishihara
2d17385d2e config: add merge-tools.<name>.edit-args to schema 2023-02-07 18:32:57 +09:00
Samuel Tardieu
605a39b84f jj new --insert-after 2023-02-07 09:16:48 +01:00
Samuel Tardieu
4119aa44a9 jj new --insert-before 2023-02-07 09:16:48 +01:00
Yuya Nishihara
cd164be762 templater: inline extract_entire_prefix_and_trimmed_tail() and simplify 2023-02-07 11:42:39 +09:00
Yuya Nishihara
ebf9887d65 templater: migrate shortest_prefix_and_brackets() over shortest() 2023-02-07 11:42:39 +09:00
Yuya Nishihara
3ccac9cda5 templater: rename shortest_styled_prefix() to shortest()
Now it is the true "shortest prefix" function with the default parameter,
so let's simply call it "shortest()".
2023-02-07 11:42:39 +09:00
Samuel Tardieu
6377b4f502 style: move unix-specific imports into unix section 2023-02-06 13:16:30 +01:00
Martin von Zweigbergk
74bff5c916 doc: include diff format in config schema 2023-02-05 23:36:30 -08:00
Martin von Zweigbergk
8d3d89facc cli: rename diff.format to ui.diff.format
I felt that the config is too narrow to have it's own top-level [diff]
section, and I couldn't think of another good place to have it. I'm
happy to hear other suggestions.
2023-02-05 23:36:30 -08:00
Ilya Grigoriev
de163216c0 Templater: make shortest id functions default to 0 length
This makes them print the shortest unique prefix only.
2023-02-05 22:15:27 -08:00
Ilya Grigoriev
f076fae9b5 Document the fact that jj rebase accepts multiple -d
It was already mentioned towards the end of the introductory text, but that's
easy to miss.

This also clarifies the doc for `--allow-large-revsets`.
2023-02-05 22:07:28 -08:00
Yuya Nishihara
7bb7d2bd35 cli: rename FullCommandArgs to CommandNameAndArgs
Per discussion in #1198.
2023-02-06 15:03:08 +09:00
Yuya Nishihara
eb95b31b78 cli: split command name and args by FullCommandArgs
If FullCommandArgs is renamed to CommandNameAndArgs, the meaning of .args()
will get fuzzy. This also clarifies that the name part exists even if the
source command string is empty.
2023-02-06 15:03:08 +09:00
Ilya Grigoriev
9cc536e9e0 Mention --allow-large-revsets in hint when one revset resolves to multiple revisions 2023-02-05 21:22:18 -08:00
Ilya Grigoriev
db148af019 Move resolve_destination_revs into mod.rs
It's not very general.
2023-02-05 21:22:18 -08:00
Ilya Grigoriev
4183c69238 Refactor & rename resolve_base_revs to extract the more general function
This extracts the more general `resolve_mutliple_nonempty_revsets_flag_guarded`
out of `resolve_base_revs`. This function should be useful for `rebase -s`,
etc.

`resolve_base_revs` is renamed to `resolve_destination_revs`; that's simply a
better name for it. It is also quite specific to the `new` and `rebase -d`
commands.  It will be moved out of general utilities in the next commit
2023-02-05 21:22:18 -08:00
Ilya Grigoriev
1c6c6dbccc jj rebase -d and jj new: Allow several commits per argument with --allow-large-revsets
Eventually, we should be able to rely on `jj op restore` and the `--allow-large-revsets`.
argument should likely be removed. This is a temporary measure until we figure
out https://github.com/martinvonz/jj/issues/922 and the like.

Fixes https://github.com/martinvonz/jj/issues/571
2023-02-05 21:22:18 -08:00
Ilya Grigoriev
d153ced8ba cli_util: Make resolve_base_revs use IndexSet
This will make deduplication easier in the next commit.
The error message becomes slightly less informative, unfortunately.
2023-02-05 21:22:18 -08:00
Ilya Grigoriev
4268c80c84 Refactor and rename rewrite_multiple_rewriteable_revsets to be more general
We'll soon need that functionality without the checking for rewriteable
part.
2023-02-05 21:22:18 -08:00
Ilya Grigoriev
159c474e2c Move resolve_multiple_rewriteable_revsets to cli_utils.rs 2023-02-05 21:22:18 -08:00
Ilya Grigoriev
8c1a5539ad cli: Include revset in hint for resolve_single_rev
The revset is already printed in the error message, but it's easy to miss since
the error message is in different color.
2023-02-05 21:22:18 -08:00