Commit graph

1069 commits

Author SHA1 Message Date
Yuya Nishihara
41afdd48c7 templater: reorder declaration of PropertyAndLabels struct 2023-02-01 10:25:28 +09:00
Martin von Zweigbergk
18d4300895 formatter: rename underlined color config to underline
I keep calling it `underline` by mistake, so that probably means that
it's a more natural name for it. We haven't made a release of it yet,
so I didn't mention it in the changelog.

I didn't update all variables to also use `underline`, because I felt
that `underlined` was usually more natural there, plus crossterm calls
it `Attribute::Underlined`.
2023-01-31 08:14:27 -08:00
Yuya Nishihara
f1e6146d6d templater: add newtype to implement property over closure
Many template keywords and methods are one liners, and I think that's actually
good because writing tests for templater would be more involved than for pure
functions.

This patch introduces a wrapper for such one-line functions, and migrates
method parser to that. Some of the commit keyword structs can also be ported
to this wrapper.
2023-01-31 16:27:52 +09:00
Yuya Nishihara
67eac2a455 templater: host shortest_styled_prefix() by CommitOrChangeId
HighlightPrefix::extract() will be inlined by the next commit.
2023-01-31 16:27:52 +09:00
David Barnett
94b53575d8 Add ui.graph.style into config schema 2023-01-31 01:10:31 -06:00
Ilya Grigoriev
adfae11e11 jj log: ui.unique-prefixes="styled" option to show prefixes in color
The tail of the id is shown in grey. For divergent commits, it looks better
to show the tail in red, so the prefix is underlined.

https://user-images.githubusercontent.com/4123047/213904951-caccef87-3636-45b1-b503-86a4271f0cc8.png
2023-01-30 22:48:38 -08:00
Ilya Grigoriev
26cc290157 Templater: Create shortest_styled_prefix function for ids 2023-01-30 22:48:38 -08:00
Ilya Grigoriev
bd37989b63 Templater: Inline highlight_shortest_prefix_brackets 2023-01-30 22:48:38 -08:00
Ilya Grigoriev
3ee87aa5a7 Rename short => shortest 2023-01-30 22:48:38 -08:00
Ilya Grigoriev
85452397c4 Templater: Show entire prefix even if it's long + refactor
This refactors the unique prefix functionality and extracts a function
that will be reused by the styled prefix highlighting.

This also includes a minor change in functionality: if the unique prefix
of an id does not fit into the space provided, it is still printed.

Currently, this would happen if the prefix is more than 12 characters
long, which takes a huge repository. However, I'm hoping that in the
future we'll make this number customizeable.
2023-01-30 22:48:38 -08:00
Martin von Zweigbergk
4e8fbaa210 git: allow conflicts in "HEAD@git"
Git's HEAD ref is similar to other refs and can logically have
conflicts just like the other refs in `git_refs`. As with the other
refs, it can happen if you run concurrent commands importing two
different updates from Git. So let's treat `git_head` the same as
`git_refs` by making it an `Option<RefTarget>`.
2023-01-30 09:05:03 -08:00
Martin von Zweigbergk
6cf7d98465 templater: replace is_git_head keyword by git_head keyword
I'm about to make it possible for `HEAD@git` to be conflicted. For
that, we need to be able to include the trailing `?`. This patch
prepares for that.
2023-01-30 09:05:03 -08:00
Glen Choo
b338c916c0 cli: report no updates to current branch
Fix a bug where `jj git push` would print "No current branch." when
there is a current branch but it is unchanged. We were conflating the
two because we print the message when no updates were performed, instead
of only when no branches were found.
2023-01-29 22:07:28 -08:00
Glen Choo
3418c8ff73 git: add git.auto-local-branch
Add a new git.auto-local-branch config option. When set to false, a
remote-tracking branch imported from Git will not automatically create a
local branch target. This is implemented by a new GitSettings struct
that passes Git-related settings from UserSettings.

This behavior is particularly useful in a co-located jj and Git repo,
because a Git remote might have branches that are not of everyday
interest to the user, so it does not make sense to export them as local
branches in Git. E.g. https://github.com/gitster/git, the maintainer's
fork of Git, has 379 branches, most of which are topic branches kept
around for historical reasons, and Git developers wouldn't be expected
to have local branches for each remote-tracking branch.
2023-01-29 20:17:49 -08:00
Yuya Nishihara
3d965f22ab templater: disallow empty template in function arguments and parens
Before, "f()" was parsed as a function call with one empty argument. In
practice, this change means "if(divergent,,false_template)" is no longer
valid.
2023-01-30 12:50:40 +09:00
Yuya Nishihara
a5bb48d47e templater: introduce top-level rule that wraps template terms
An epsilon rule will be moved here to disambiguate f() with f("").
2023-01-30 12:50:40 +09:00
Yuya Nishihara
c44dda55e3 templater: extract function arguments to inner node
This should help to represent an empty argument properly.
2023-01-30 12:50:40 +09:00
Yuya Nishihara
62def97f58 templater: remove redundant boxing of single template term
It was a copy-paste error.
2023-01-30 12:50:40 +09:00
Samuel Tardieu
890327ea68 style: return early from exceptional situation 2023-01-29 19:23:56 +01:00
Samuel Tardieu
fc59db5d52 split: allow creation of empty parent or child
jj split .           => create an empty child
jj split nonexistent => create an empty parent
2023-01-29 19:23:56 +01:00
Yuya Nishihara
a3d3947499 templater: move epsilon rule out of term rule
Suppose "template" is a sequence of "term"s, it makes more sense to handle
an empty sequence there. It might be even better to disallow empty template
other than the top-level one.
2023-01-29 08:54:14 +09:00
Yuya Nishihara
d1281ef48e templater: ensure "template" node is passed to parse_commit_template_rule()
Assertion will be added by the next commit.
2023-01-29 08:54:14 +09:00
Yuya Nishihara
bf66beab36 templater: fix parsing of parenthesized expression
A "list" is a sequence of more than one "term" nodes, so it shouldn't contain
a single parenthesized node.

Also, a parenthesized "term" rule wasn't handled.
2023-01-29 08:54:14 +09:00
Yuya Nishihara
f7993f0fe9 templater: eliminate whitespace nodes from parse tree 2023-01-29 08:54:14 +09:00
Yuya Nishihara
a85488b11d cli: pretty-print "debug template" output
Since a parsed tree is deeply nested, it's difficult to read as a one-line
string.
2023-01-29 08:54:14 +09:00
Yuya Nishihara
29eb7a16b8 templater: process method chaining from left to right
A method call is typically left associative, and LTR processing is simpler.
2023-01-28 10:53:03 +09:00
Yuya Nishihara
2ae892efab templater: reuse function rule to represent a method chain
A method call is typically parsed as (obj.meth)(), not as obj.(meth()),
but the latter is good enough for our needs. It's unlikely we'll add a
first-class function support.

.into_inner().next().unwrap() mess will be cleaned up by the next commit.
2023-01-28 10:53:03 +09:00
Martin von Zweigbergk
d8942d5f96 cli: rename ui.graph.format to ui.graph.style
I think of it more as style than a format, so using `style` in the
config key makes sense to me.

I didn't bother making upgrades easy by supporting the old name since
this was just released and only a few developers probably have it set.
2023-01-27 10:36:26 -08:00
Martin von Zweigbergk
8248d6e8f6 graphlog: remove use of PhantomData 2023-01-27 10:36:26 -08:00
Martin von Zweigbergk
0b99e5b16e graphlog: enable Sapling's graph styles by default
I would also rename the feature, but I hope we can instead soon make
it a non-optional dependency and delete the feature.
2023-01-27 09:46:57 -08:00
Martin von Zweigbergk
5ec5f4bb5f config: rename [alias] to [aliases], still supporting old name
The name of the [alias] section is inconsistent with other
table-valued sections ([revset-aliases], [colors], [merge-tools]), so
let's rename it. For comparison, `Cargo.toml` also uses plural names
(e.g. `[dependencies]`).
2023-01-26 18:15:23 -08:00
Martin von Zweigbergk
8af38f0d75 cli: consistently use clap::Command, and avoid unnecessary qualification 2023-01-26 18:15:23 -08:00
Martin von Zweigbergk
4a4aebd3bc cli: don't use clap::Error since it's too generic
It's not obvious when you see `Error`, even in the CLI crate, that
it's a `clap::Error`
2023-01-26 18:15:23 -08:00
Yuya Nishihara
bfb56614d4 templater: rename TemplateFunction::new() parameter for consistency 2023-01-26 23:42:13 +09:00
Yuya Nishihara
2c4856c47b templater: remove Box<dyn> from generic wrappers, parameterize type
This basically removes 'a lifetime from these wrappers, and add trait bounds
instead. I have no idea which version would look less scary, but let's see.

I also added trait bounds to constructor functions. They aren't strictly
required, but help type inference of closure (and will probably improve
an error message.)
2023-01-26 23:42:13 +09:00
Aleksandr Mikhailov
e7077909c1 cli: fix jj squash on empty commit
Fixes #787
If `jj squash` is run on an empty commit, it fails with "Error: No changes selected"

With this change such squash command will behave like `jj abandon`.
2023-01-26 11:37:20 +01:00
Yuya Nishihara
b9fc6d4203 templater: rewrite divergent property by leveraging IdIndex 2023-01-26 14:10:26 +09:00
Martin von Zweigbergk
10725c095f cleanup: update more "checkout" to "working-copy commit" and similar
I've preferred "working-copy commit" over "checkout" for a while
because I think it's clearer, but there were lots of places still
using "checkout". I've left "checkout" in places where it refers to
the action of updating the working copy or the working-copy commit.
2023-01-25 11:02:59 -08:00
Yuya Nishihara
e874570947 cli: proxy format_commit_summary() through transaction wrapper
At this point, tx.base_repo() is identical to tx.repo(), so the caller doesn't
need to explicitly select the "base" one.
2023-01-25 13:52:43 +09:00
Yuya Nishihara
18e9679613 cli: move run_mergetool/edit_diff/select_diff to transaction wrapper
These functions should use MutableRepo if base_repo.store() != repo.store().
See also #50.
2023-01-25 13:52:43 +09:00
Yuya Nishihara
330adf380f cli: start transaction before starting edit/select_diff()
Other callers do that, so let's make the transaction cover tree merging
and diff editing.
2023-01-25 13:52:43 +09:00
Yuya Nishihara
1b8ecef968 cli: have WorkspaceCommandHelper return &WorkspaceId, clone it by caller
I didn't make this change before because there are many immutable/mutable
borrow conflicts. Now most of the problems are consolidated to the transaction
wrapper, we can simply make it return a reference.
2023-01-25 13:31:41 +09:00
Yuya Nishihara
3d5eb970da cli: wrap transaction started by WorkspaceCommandHelper, borrow helper mutably
This ensures that helper methods that depend on repo aren't used by mistake
while transaction is in progress. Still it provides an escape hatch to invoke
e.g. select_diff() with the base repo, but such invocations are more explicit.

Some MutableRepo methods are proxied through the wrapper to get around
borrowing errors.
2023-01-25 13:31:41 +09:00
Yuya Nishihara
44e7c0632e cli: evaluate rebase set before starting transaction
This should eliminate lifetime issue I would have to deal with in the
next commit. evaluate_revset() only borrows RepoRef, but such precise
dependency can't be expressed as of now.
2023-01-25 13:31:41 +09:00
Yuya Nishihara
c018ef229b repo: proxy shortest unique prefix function through RepoRef
Since this function depends on both index and view, it can't be moved to
one of the storage objects. If we go forward with this approach, some
revset::resolve_*() functions will also be migrated to RepoRef.

This patch slightly changes the function name since a "prefix" might have
various meanings.
2023-01-25 10:47:39 +09:00
Martin von Zweigbergk
b079897a56 cli: propagate failure to record new working-copy id
This code cannot currently fail because we we never pass in the root
commit, but it's more future-proof to propagate the error.
2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
63aa484046 repo: add a specific error type for MutableRepo::check_out() 2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
dd3472924b repo: add a specific error type for MutableRepo::edit()
The new type is just an enum version of `RewriteRootCommit`.  I'll add
another variant soon.
2023-01-24 12:20:28 -08:00
Martin von Zweigbergk
ff592e522f edit: explicitly check that target commit is rewritable
I think the CLI should check if the target of `jj edit` is rewritable
before calling the library to update the repo. The other commands
already do that. Then, if calling `MutableRepo::edit()` fails, it's
always an internal error, which makes error handling simpler in coming
commits.
2023-01-24 12:20:28 -08:00
Samuel Tardieu
e4f6dadfad workspace: add a root subcommand to print the workspace root path 2023-01-24 16:53:54 +01:00