Commit graph

28 commits

Author SHA1 Message Date
Martin von Zweigbergk
d1dc22d957 backend: let backend decide length of change id
As mentioned in the previous commit, our internal backend at Google
uses a 32-byte long change id. This commit will make us able to use
that.
2023-02-07 22:31:34 -08:00
Martin von Zweigbergk
e6693d0f68 backend: let backend choose root change id
Our internal backend at Google uses a 32-byte change id, so I'd like
to make the backend able to decide the length. To start with, let's
make the backend able to decide what the root change id should
be. That's consistent with how we already let the backend decide what
the root commit id should be.
2023-02-07 22:31:34 -08:00
Martin von Zweigbergk
98259346df backend: make hash_length() specifically about commit IDs
The function is currently only about the length of commit IDs, so
let's clarify that. I'm going to add another function for the length
of change IDs next. I don't know if we're going to care about lengths
of other hashes in the future. We might even be able to remove the
current restriction that all commit IDs and all change IDs have the
same length.
2023-02-07 22:31:34 -08: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
Samuel Tardieu
8a289ddef0 refactor: return ExitCode from CliRunner::run()
`CliRunner::run()` has been renamed from `CliRunner::run_and_exit()`
and returns an `ExitCode` which can be returned from `main()`.
2023-01-20 06:42:08 +01:00
Martin von Zweigbergk
5b40eda47a cli: add a way to add custom global flags
Our internal build at Google needs a custom global flag, which lets
the user pass flags into C++ code we use for our custom backends. This
provides a way of achieving that.
2023-01-18 17:24:05 -08:00
Yuya Nishihara
d4ab33951a cli: replace short_commit_description() with commit summary template
resolve_single_rev() would have to parse the template for each revision,
but it's just 5 times at most. Let's start with a simple API. If the template
doesn't capture RepoRef, maybe we can cache it.
2023-01-16 11:53:35 +09:00
Yuya Nishihara
42a044b7c7 cli: move ui.settings() to CommandHelper, disown UserSettings from Ui
Still UserSettings is cloned to WorkspaceCommandHelper, but I think this is
slightly better since CommandHelper and WorkspaceCommandHelper are scoped
based on call stack. Perhaps, UserSettings can be shared by Arc or immutable
reference.
2023-01-05 14:33:10 +09:00
Yuya Nishihara
d7911ff279 cli: move ui.cwd() to CommandHelper
I'm going to remove owned UserSettings from Ui so that UserSettings can be
instantiated after both user and repo configs are loaded. ui.cwd() belongs
to the same category (random environment stuff), and Ui doesn't depend on it,
so let's remove it first from Ui.

I'm not pretty sure if CommandHelper and WorkspaceCommandHelper should be
a permanent home for cwd and settings, but it works for now as CommandHelper
is immutable.
2023-01-05 14:33:10 +09:00
Yuya Nishihara
6d8d495075 cli: port custom command dispatch to CliRunner
Box<dyn> isn't technically needed, but it simplifies the type signature. Type
alias is added to silence clippy warning.
2023-01-04 15:48:38 +09:00
Yuya Nishihara
e0690f9d66 cli: pass CommandHelper to dispatch function by reference
This allows us to chain custom dispatch functions. If CommandHelper were
moved or passed by mutable reference, weird thing could happen depending
on the call order.
2023-01-04 15:48:38 +09:00
Yuya Nishihara
0110814885 cli: integrate custom StoreFactories registration with CliRunner
.set_store_factories() could be invoked for any CliRunner<F> type, but
I don't care much about that since the type parameter F will be removed
soon.
2023-01-04 15:48:38 +09:00
Yuya Nishihara
f34f764b9f cli: migrate custom command augmentation and parse_args() to CliRunner
CommandHelper is passed by move because custom-backend/main.rs mutates it.
This will be addressed by the next commit.
2023-01-04 15:48:38 +09:00
Yuya Nishihara
9296ae6eb4 cli: add builder type that handles CLI initialization and teardown
parse_args() will probably become more involved to deal with --config-toml,
-R, and repository configs. This builder will hopefully allow us to move
things around without changing the high-level interface.
2023-01-04 15:48:38 +09:00
Yuya Nishihara
9763a4d689 cli: move --verbose handling to parse_args(), enable it in custom examples 2023-01-04 11:56:53 +09:00
Yuya Nishihara
6586a756c1 cli: inline create_ui(), use ? to handle config error 2023-01-02 14:14:50 +09:00
Martin von Zweigbergk
d86ba708a3 repo: add MutableRepo::rewrite_commit() returning CommitBuilder
Same reasoning as the previous commit.
2022-12-26 23:30:52 -08:00
Martin von Zweigbergk
f3208f59c4 store: propagate error from Backend::write_commit() 2022-12-26 23:30:52 -08:00
Martin von Zweigbergk
49b2f3b6ca commit_builder: keep MutableRepo reference
When you're done with the `CommitBuilder`, you're going to have to
call `write_to_repo()`, passing it a mutable `MutableRepo`
reference. It's a bit simpler to pass that reference when we create
the `CommitBuilder` instead, so that's what this patch does.

A drawback of passing in the mutable reference when we create the
builder is that we can't have multiple unfinished `CommitBuilder`
instance live at the same time. We don't have any such use cases yet,
and it's not hard to work around them, so I think this change is worth
it.
2022-12-26 23:30:52 -08:00
Yuya Nishihara
986649623d commit_builder: relax type of description parameter
The next commit will introduce a newtype for -m/--message argument which
can be converted Into<String>.

Since CommitBuilder is a thin wrapper, code bloat caused by generic parameters
wouldn't matter. I have another set of commits that makes all builder methods
accept Into/IntoIterator, which will remove some of .clone() calls from tests.
2022-12-22 14:59:03 +09:00
Daniel Ploch
7cbea42a24 repo: rename BackendFactories to StoreFactories 2022-12-14 14:10:30 -08:00
Glen Choo
7c2400f3e5 ui: add pager
Teach Ui's writing functions to write to a pager without touching the
process's file descriptors. This is done by introducing UiOutput::Paged,
which spawns a pager that Ui's functions can write to.

The pager program can be chosen via `ui.pager`. (defaults to Defaults to
$PAGER, and 'less' if that is unset (falling back to 'less' also makes
the tests pass).

Currently, commands are paginated if:

- they have "long" output (as defined by jj developers)
- jj is invoked in a terminal

The next commit will allow pagination to be turned off via a CLI option.
More complex pagination toggling (e.g. showing a pager even if the
output doesn't look like a terminal, using a pager for shorter ouput) is
left for a future PR.
2022-11-30 06:14:39 +08:00
Martin von Zweigbergk
d8feed9be4 copyright: change from "Google LLC" to "The Jujutsu Authors"
Let's acknowledge everyone's contributions by replacing "Google LLC"
in the copyright header by "The Jujutsu Authors". If I understand
correctly, it won't have any legal effect, but maybe it still helps
reduce concerns from contributors (though I haven't heard any
concerns).

Google employees can read about Google's policy at
go/releasing/contributions#copyright.
2022-11-28 06:05:45 -10:00
Benjamin Saunders
472b6926e5 cli: define drop+signal guard helper 2022-11-06 18:15:22 -08:00
Martin von Zweigbergk
89680b8df9 cli: update off of deprecated clap API 2022-09-29 17:53:36 -07:00
Martin von Zweigbergk
4f0ccedd31 cli: don't call process::exit() in create_ui()
This patch move the call to `process::exit()` out of `create_ui()` by
letting that function return a `(Ui, Result<(), CommandError>)`.
2022-09-25 19:43:47 -07:00
Martin von Zweigbergk
0484573a6d examples: show how to add a custom backend 2022-09-25 09:40:42 -07:00
Martin von Zweigbergk
18cf020f2f examples: show how to add custom CLI command
It's now pretty easy to add a custom command. Let's have an example to
show how to do it, and to protect against regressions.

It would be nice to also have some tests of the custom command, to
check that the command works, that other commands can be run, and that
`jj debug completion` includes the custom command. I'm not sure how to
do that, however.
2022-09-24 07:28:10 -07:00