Commit graph

1265 commits

Author SHA1 Message Date
David Barnett
99cb0ba7c5 Implement "config set" subcommand
Uses toml_edit to support simple config edits like:
  jj config set --repo user.email "somebody@example.com"
2023-02-28 18:18:02 -08:00
Martin von Zweigbergk
bbd6ef0c7b revset: remove filter_by_diff(), have caller intersect expression
To be able to make e.g. `jj log some/path` perform well on cloud-based
repos, a custom revset engine needs to be able to see the paths to
filter by. That way it is able pass those to a server-side index. This
commit helps with that by effectively converting `jj log -r foo
some/path` into `jj log -r 'foo & file(some/path)'`.
2023-02-28 17:45:34 -08:00
Yuya Nishihara
bab13e1982 cli: snapshot stale working copy before updating
Since there's no easy API to snapshot the stale working copy without releasing
the lock, we have to compare the tree ids after reacquiring the lock. We could
instead manually snapshot and rebase the working-copy commit, but that would
require more copy-paste codes.

Closes #1310
2023-02-28 12:59:30 +09:00
Yuya Nishihara
b7eb8ee438 cli: include command args in "snapshot working copy" op log
Since "import git refs" includes the args, there would be no point to exclude
snapshot_working_copy().
2023-02-28 12:59:30 +09:00
Martin von Zweigbergk
346e3c849b repo: propagate error when failing to look up backend type 2023-02-27 09:44:28 -08:00
Martin von Zweigbergk
011d9e3486 workspace: make WorkspaceLoader::load() return WorkspaceLoadError
I plan to make `RepoLoader::init()` return a `Result`, which means
that `WorkspaceLoader::load()` will need to return more kinds of
errors. Making it return `WorkspaceLoadError` is a good start. By also
extracting a function for converting `WorkspaceLoadError` to
`CommandError`, we can reuse a the handling of `PathError` in
`cli_util`.
2023-02-27 09:44:28 -08:00
Martin von Zweigbergk
ea6a238c7c cli: avoid creating new WorkspaceLoader for jj config edit --repo
This is mostly about not having to handle errors twice (or document an
`unwrap()` after `WorkspaceLoader::init()`).
2023-02-27 09:44:28 -08:00
Samuel Tardieu
c5e41a99c3 git remote rename: rename git refs as well 2023-02-26 15:22:18 +01:00
Samuel Tardieu
b515d14f18 git_fetch: when removing a remote branch, remove git ref as well 2023-02-26 15:22:18 +01:00
Yuya Nishihara
bfbb7d1399 cli: on finish_transaction(), print check-out summary by caller
This makes sense because the status is also printed by caller.
2023-02-23 14:15:38 +09:00
Yuya Nishihara
1cb473ab2a cli: on finish_transaction(), look up check-out commit by caller
So the caller can print a commit summary.

It's getting less clear why cli_util::update_working_copy() takes a repo
argument. It might be better to extract a helper struct that operates on
repo + workspace (minus CLI stuff), and move it to the lib crate.
2023-02-23 14:15:38 +09:00
Yuya Nishihara
3dd8b9a5f0 cli: extract update_working_copy() from finish_transaction()
I'll move some bits from the free update_working_copy() function to
deduplicate parse_commit_summary_template() call.
2023-02-23 14:15:38 +09:00
Yuya Nishihara
61d6604d3d cli: add workspace_command.get_wc_commit_id() for short
We can't replace all callers, but I think it's common enough to add a helper
function.
2023-02-23 14:15:38 +09:00
Ilya Grigoriev
49fd177c47 templater: Allow separate styling for change and commit ids 2023-02-21 22:50:27 -08:00
Ilya Grigoriev
00b18bcd18 templater: Upper and lowercase ids and strings 2023-02-21 22:50:27 -08:00
Ilya Grigoriev
643fe9a218 Remove no longer needed clippy bug workaround 2023-02-21 18:33:40 -08:00
Ilya Grigoriev
30d03a66e6 cmd: --branch option for git fetch.
Thanks to @samueltardieu for noticing a subtle bug in the refspecs, providing
the fix, as well as the two `conflicting_branches` tests.
2023-02-21 18:33:40 -08:00
Yuya Nishihara
4ec0bfb8f7 cli: rename op "head" color label to "current_operation"
FWIW, this change means a boolean "current_operation" keyword will be
highlighted even if it's false.
2023-02-21 00:24:58 +09:00
Yuya Nishihara
4f36367aee cli: rename "op-log" color label to "op_log"
Per discussion in #1289.
2023-02-21 00:24:58 +09:00
Yuya Nishihara
c2df989fe9 cli: add "op log -T" option and basic tests for template keywords 2023-02-20 18:20:41 +09:00
Yuya Nishihara
b5f1728ffb templater: migrate op log to template language
The outermost "op-log" label isn't moved to the default template. I think
it belongs to the command's formatter rather than the template.

Old bikeshedding items:
- "current_head", "is_head", or "is_head_op"
  => renamed to "current_operation"
- "templates.op-log" vs "templates.op_log" (the whole template is labeled
  as "op-log")
  => renamed to "op_log"
- "template-aliases.'format_operation_duration(time_range)'"
  => renamed to 'format_time_range(time_range)'
2023-02-20 18:20:41 +09:00
Yuya Nishihara
eafbd977a3 templater: add TimestampRange type, migrate operation time to it 2023-02-20 18:20:41 +09:00
Yuya Nishihara
da3c1d2286 templater: extract helpers to build expression of specific types 2023-02-20 18:20:41 +09:00
Yuya Nishihara
c2e0ebca12 templater: implement .into_template() helper on formattable property
So that I can blindly write property.into_template() to convert any property
type to template.
2023-02-20 18:20:41 +09:00
Yuya Nishihara
854a3e64fa templater: split IntoTemplate trait
The next commit will implement .into_template() on Box<dyn TemplateProperty>,
so I want a trait for this particular method.
2023-02-20 18:20:41 +09:00
Ilya Grigoriev
9c51d74b2c cmd: Allow multiple -b for jj rebase
This also makes `rebase_branch` reuse `rebase_descendants`.

This addresses a portion of #1158
2023-02-20 00:36:32 -08:00
Ilya Grigoriev
f04458a245 cmd: Allow multiple -s for jj rebase
This addresses a portion of #1158

One application (not the prettiest, but useful until we have `jj sync`):

    jj rebase -s oldmain+~:main -d main -L
2023-02-20 00:36:32 -08:00
Ilya Grigoriev
53476a77f7 cmd: Make jj restore work if @ is a merge commit
To be clear, this applies to `jj restore` without any arguments.

Fixes #1228
2023-02-19 22:55:53 -08:00
Martin von Zweigbergk
bc9f66dad3 revset: replace RevsetIterator wrapper by extension
The type doesn't seem to provide any benefit. I don't think I had a
good reason for creating it in the first place; it was probably just
unfamiliarity with Rust.
2023-02-19 21:37:26 -08:00
Martin von Zweigbergk
30160f4d20 revset: pass revset, not iterator, into RevsetGraphIterator
I was thinking of replacing `RevsetIterator` by a regular
`Iterator<Item=IndexEntry>`. However, that would make it easier to
pass in an iterator that produces revisions in a non-topological order
into `RevsetGraphIterator`, which would produce unexpected results (it
would result in nodes that are not connected to their parents, if
their parents had already been emitted). I think it makes sense to
instead pass in a revset into `RevsetGraphIterator`.

Incidentally, it will also be useful to have the full revset available
in `RevsetGraphIterator` if we rewrite the algorithm to be more
similar to Mercurial's and Sapling's algorithm, which involves asking
the revset if it contains parent revisions.
2023-02-19 21:37:26 -08:00
Yuya Nishihara
a3efb74cfc commit_templater: make commit/change_id typed again
This basically undoes d6c6cdb45c "templater: store type-erased version of
commit/change id." Since they are looked up differently, they should preserve
the original types.
2023-02-20 13:41:44 +09:00
Samuel Tardieu
863a6e6d09 git push: add --deleted option 2023-02-19 18:18:53 +01:00
Yuya Nishihara
4f9e75c7d1 templater: use macro to implement property kind wrappers 2023-02-19 16:18:39 +09:00
Yuya Nishihara
aaae90a599 commit_templater: turn property structs into functions 2023-02-19 16:18:39 +09:00
Yuya Nishihara
cf1b609de2 commit_templater: rename 'repo lifetime for clarity
FWIW, I'm thinking of making the repo parameter generic over Arc<ReadonlyRepo>
and &MutableRepo. It will allow us cache a parsed commit_summary template.
2023-02-19 16:18:39 +09:00
Yuya Nishihara
c5ddd14c13 commit_templater: extract runtime objects from templater.rs
This should reduce future merge conflicts around use statements.
2023-02-19 16:18:39 +09:00
Yuya Nishihara
c396b4cecf commit_templater: extract parsing functions from template_parser.rs
parse_commit_template() is renamed to commit_templater::parse().
2023-02-19 16:18:39 +09:00
Yuya Nishihara
73b7954060 templater: make common parser types and utility functions public
So the commit templater can be extracted to new module.
2023-02-19 16:18:39 +09:00
Yuya Nishihara
a28396fc86 templater: extract "commit" property variants to separate enum
Now it's ready to split template_parser/templater into base template functions
and "commit" templater. I think Signature and Timestamp are basic types, so
they aren't moved to CommitTemplatePropertyKind. Perhaps, a duration type from
OpTemplate will also be added to CoreTemplatePropertyKind.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
7ee2ff862f templater: rename Property enum to CoreTemplatePropertyKind
I'll add CommitTemplatePropertyKind.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
5474268d22 templater: parameterize property type 2023-02-19 11:31:22 +09:00
Yuya Nishihara
907bddaf1e templater: add conversion trait for common template types
Maybe we can split traits per type (such as IntoTemplate), but a single
trait should be good enough to abstract "Property" enums.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
2be34ab552 templater: proxy Property::<variant>() wrapping through language trait
The idea is that a derived language will do wrap_<core_type>() as
DerivedProperty::Core(CoreProperty::<Type>(property)). This could be dealt
with some From<CoreProperty> trait impls, but the resulting code looked
a mess, and compile errors would be cryptic. I think this is somewhat similar
to serde::Serializer API.

I also rejected the idea of abstracting property types over Box<dyn>. Maybe
it's okay for method dispatching and extraction of some basic types, but it
wouldn't work if we want to implement comparison operators for any compatible
types.

wrap_commit_or_change_id() and wrap_shortest_id_prefix() will be moved to
the CommitTemplateLanguage. I'll add impl_wrap_fns() macro after splitting
the modules.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
52df6f2e81 templater: proxy build_core_method() through language trait
The "core" template parser wouldn't know how to dispatch property of types
added by a derived language. For example, CommitOrChangeId/ShortestIdPrefix
will be moved to the "commit" templater.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
3361130df4 templater: introduce trait that abstracts property kind and keywords
This trait will provide ways to dispatch keyword/method nodes, and wrap
TemplateProperty object with a dedicated "Property" enum.

build_keyword() and context parameter "I"/"C" have been migrated to it.
2023-02-19 11:31:22 +09:00
Yuya Nishihara
4b00fb70d0 templater: extract function that dispatches method call by property type
A derived template language (e.g. commit template) will forward method calls
of the core types to this function.
2023-02-18 01:16:43 +09:00
Yuya Nishihara
7784768dc6 templater: inline PropertyAndLabels into Expression::Property()
It's no longer used at type position.
2023-02-18 01:16:43 +09:00
Yuya Nishihara
84ad048f24 templater: move initial labeling out of keyword function
I'm going to extract functions specific to commit templates, and auto labeling
feature should be a part of the core template language.
2023-02-18 01:16:43 +09:00
Ilya Grigoriev
e4aa2cb2e5 Rename ui.relative-timestamps to ui.oplog-relative-timestamps 2023-02-15 21:26:14 -08:00
Ilya Grigoriev
859b0f680c Make ui.relative-timestamps default to true
This seems like a better default for `jj op log`, which is now the only thing
this option affects.
2023-02-15 21:26:14 -08:00