Commit graph

573 commits

Author SHA1 Message Date
Yuya Nishihara
9faa4670d5 cli: on init, import git refs prior to importing HEAD
The "::HEAD" set is usually smaller than "::git_refs". If these sets were
imported in that order, "HEAD..git_refs" commits would be indexed on top of
the "::HEAD" commits. It's not a problem, but undesirable.
2024-01-27 00:01:59 +09:00
Yuya Nishihara
23a1ddb6ad cli: split WorkspaceCommandHelper::import_git_refs_and_head()
Also added status message to import_git_head() as I think it's an unusual
event.
2024-01-27 00:01:59 +09:00
Yuya Nishihara
fc114ef217 git: extract Git HEAD handling bits from import_some_refs()
I'm going to make WorkspaceCommandHelper::maybe_snapshot() snapshot the working
copy before importing refs. git::import_some_refs() can rebase the working copy
branch and therefore @ can be moved. git::import_head() doesn't, and it should
be invoked before snapshotting.

git::import_head() is inserted to some of the git:import_refs() callers where
HEAD seems to matter. I feel it's a bit odd that the HEAD ref is imported to
non-colocated repo, but "jj init --git-repo" relies on that, and I think the
existence of HEAD@git is harmless. It's merely a ref to the revision checked
out somewhere else.
2024-01-27 00:01:59 +09:00
Valentin Gatien-Baron
3b7678d9c5 cli: move jj workspace root to `jj root, for discoverability
This is a convenient command, for scripting things like `cd $(jj root)
&& do something`, and it seems better to allow people to find it
before they learn about workspaces.
2024-01-25 16:31:44 -05:00
Ilya Grigoriev
95b752dfe8 cli branch: add alias t for track
This goes with `c`, `s`, `f`. I feel like it's a relatively
common command now that `auto-local-branch` defaults to
`false`.

I didn't add `u` for `untrack` because it seems a little
ambiguous (un-what?); there may be other `branch` commands that undo
something in the future.
2024-01-25 12:59:18 -08:00
Daniel Ploch
20cbe77bf5 workspace: support creating shares of custom workspaces 2024-01-25 11:46:07 -08:00
Daniel Ploch
cb889f0b45 workspace: combine working copy functions into a trait 2024-01-25 11:46:07 -08:00
Jonathan Tan
6fa5d456f8 util gc: allow specifying prune time
This only affects pruning of the operation log for now, and only
supports the string "now" for now.
2024-01-24 09:29:40 -08:00
Daniel Ploch
4024fb4880 cli_util: improve API for editing text in a tempfile
Consolidates bulky tempfile code in sparse.rs and description_util.rs into cli_util.rs
2024-01-23 23:49:35 -08:00
Stephen Jennings
57d5abab0c cli: display which file's conflicts are being resolved 2024-01-23 08:59:43 -08:00
Yuya Nishihara
566713bf6b cli: colorize choices of prev/next commits 2024-01-23 15:01:25 +09:00
Yuya Nishihara
2839922e57 ui: remove redundant .to_lowercase() from prompt_yes_no() 2024-01-23 08:48:58 +09:00
Jonathan Tan
0bc1341fd0 revset: add count_estimate() to Revset trait
The count() function in this trait is used by "jj branch" to determine
(and then report) how many commits a certain branch is ahead/behind
another branch. This is currently implemented by walking all commits
in the revset, counting how many were encountered. But this could be
improved: if the number is large, it is probably sufficient to report
"at least N" (instead of walking all the way), and this does not scale
well to jj backends that may not have all commits present locally (which
may prefer to return an estimate, rather than access the network).

Therefore, add a function that is explicitly documented to be O(1)
and that can return a range of values if the backend so chooses.

Also remove count(), as it is not immediately obvious that it is an
expensive call, and callers that are willing to pay the cost can obtain
the exact same functionality through iter().count() anyway. (In this
commit, all users of count() are migrated to iter().count() to preserve
all existing functionality; they will be migrated to count_estimate() in
a subsequent commit.)

"branch" needed to be updated due to this change. Although jj
is currently only available in English, I have attempted to keep
user-visible text from being assembled piece by piece, so that if we
later decide to translate jj into other languages, things will be easier
for translators.
2024-01-22 15:07:00 -08:00
Jonathan Tan
08da40bc82 branch: refactor ahead/behind message
A subsequent commit will teach more variants of ahead/behind messages,
so refactor the existing code to avoid code duplication and a future
combinatorial explosion.
2024-01-22 15:07:00 -08:00
Daniel Ploch
32b982e507 next: support prompting for ambiguous commit targets
Resolves part of issue #2126
2024-01-22 13:58:45 -08:00
Daniel Ploch
deaea0732a testing: allow testing of commands that expect stdin 2024-01-22 13:58:45 -08:00
Daniel Ploch
b4b1a21e70 next: fix branching tests to actually test ambiguous targets 2024-01-22 13:58:45 -08:00
Daniel Ploch
f3edc75c81 ui: add helpers for prompting from a set of values
Prompts are barely used in the CLI currently but they are very useful in extensions with more complex workflows.
2024-01-22 13:58:45 -08:00
Daniel Ploch
5448a473ca ui: handle EOF on prompts 2024-01-22 13:58:45 -08:00
Daehyeok Mun
ad05a8750a Renaming \'BranchSubCommand\' and \'ConfigSubCommand\' 2024-01-22 10:12:00 -08:00
Daehyeok Mun
02f94653e6 Implement tag command. 2024-01-22 09:23:18 -08:00
Austin Seipp
0af1a15162 cli: move RepoBranchName(Pattern) to crate::cli_utils
Needed in another upcoming diff, as Gerrit needs to parse remote names for
pushing refs.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-01-20 17:55:45 -06:00
Austin Seipp
bd110307ff cli: move some git utilities to new crate::git_utils
Gerrit also needs to be able to push low-level refs into upstream remotes, just
like `jj git push` does. Doing so requires providing callbacks e.g. for various
password entry mechanisms, which was private to the `git` command module.

Pull these out to a new module `git_utils` so we can reuse it across the two
call sites.

This also moves a few other strictly Git-related functions into `git_utils`
as well, just for the sake of consistency.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-01-20 15:58:37 -06:00
Daehyeok Mun
5b6ef63666 Support --user and --repo argument for config list command 2024-01-17 11:19:23 -08:00
Daehyeok Mun
4b224c45e0 Allow printing overridden config values via --include-overridden. 2024-01-16 13:36:50 -08:00
Yuya Nishihara
c6b1ace9dd cli: use root operation id as the default lhs operand of range expression 2024-01-16 21:46:54 +09:00
Essien Ita Essien
dc074363d1 no-op: Move external git repo canonicalization into Workspace::init_git_external
* Move canonicalization of the external git repo path into the Workspace::init_git_external().
  This keeps necessary code together.
* Add a new variant of WorkspaceInitError for reporting path not found errors. The user error
  string is written to pass existing tests.
2024-01-16 10:46:02 +00:00
Martin von Zweigbergk
b5343fb968 cli_util: remove handling of unrelated op logs
Any two operations should now have the root operation as common
ancestor. Otherwise there's a bug in the op store.
2024-01-14 10:15:14 -08:00
Martin von Zweigbergk
41db64e63c cli: give root operation special treatment in template (like root commit) 2024-01-14 10:15:14 -08:00
Martin von Zweigbergk
6e302bb3a2 op_store: add a virtual root operation, similar to root commit
It seems obvious in hindsight to have a virtual root operation just
like we have a virtual root commit. It removes the same kind of
problems by making sure there's always a common ancestor (or multiple)
between any two commits.

I think the reason I didn't add a root operation from the beginning
was that there used to be a mandatory working-copy commit in the view
(this was before support for multiple workspaces).

Perhaps we should remove the "initialize repo" operation now. The only
difference between their view objects is that the "initialize repo"
operation adds the root commit as a head. We could add that to the
root operation, but then the root operation's value depends on the
commit backend.
2024-01-14 10:15:14 -08:00
Martin von Zweigbergk
c9af8bf43a view: drop tracking of public heads
We've had the public_heads for as long as we've had the View object,
IIRC (I didn't check), but we still don't use it for anything. I don't
have any concrete plans for using it either. Maybe our config for
immutable commits is good enough, or maybe we'll want something more
generic (like Mercurial's phases). For now, I think we should simplify
by removing it the storage for public heads.
2024-01-13 22:23:57 -08:00
Yuya Nishihara
7e62d5ef36 cli: rename snapshot() to maybe_snapshot(), make inner function private
This function respects --ignore-working-copy and --at-op arguments, but the
name snapshot() sounds like it could forcibly trigger the snapshotting. Let's
clarify the actual behavior.

import_git_refs_and_head() and snapshot_working_copy() are unchecked functions,
and there are no external callers.
2024-01-13 11:47:42 +09:00
Yuya Nishihara
650c1f6521 cli: inline CommandHelper::workspace_helper_internal()
The control flow is pretty simple. We don't need a inner function that
implements the both.
2024-01-13 11:47:42 +09:00
Yuya Nishihara
543036c753 cli: run "op log" without loading repo or merging concurrent ops
When debugging behavior of badly-GCed repos, I find it's annoying that "op log"
fails because the index can't be loaded. Since "op log" doesn't need a repo, I
think it's better to display the exact op-heads state without merging.
2024-01-13 10:38:10 +09:00
Yuya Nishihara
e8900123d2 cli: add method to load template aliases without using WorkspaceCommandHelper 2024-01-13 10:38:10 +09:00
Yuya Nishihara
45fdcfd6a8 cli: construct op template without using repo, make current op optional
I'm going to make "op log" not load a repo nor resolve concurrent operations,
so there will be the case where no unique "current" operation exists. Since the
"current" operation represents the repo to be loaded, I think it's better to
not consider multi-head operations as the "current" ones. That's why the
templater field isn't Vec<_> but Option<_>.
2024-01-13 10:38:10 +09:00
Yuya Nishihara
faa9b8d77f cli: run "op abandon" without loading repo, reject --at-op
If indexing failed due to missing commit objects, the repo won't be loadable
without --ignore-working-copy (at least in colocated environment.) In that
case, we can use "op abandon" to recover, but we had to work around the failed
index loading by --ignore-working-copy. Since "op abandon" isn't a repo-level
command, it's better to bypass working-copy snapshot and import of git refs at
all.

--at-op is rejected because it's useless and we'll need extra care for "@"
expression resolution and working-copy updates.
2024-01-12 08:01:13 +09:00
Yuya Nishihara
f70107dad9 tests: ensure that operation id is updated by "op abandon" command
Before, the test passed even if "op abandon" didn't remap the working-copy
operation id.
2024-01-12 08:01:13 +09:00
Yuya Nishihara
4fed19361a cli: include branches and tags in default "show" template
The formatting is closer to hg than git just because it's easier to
conditionalize the whole line per keyword. Our template language doesn't
have infix logical operators.

Unlike the other default templates, all remote branches are displayed because
it's "detailed" output.

Closes #2509
2024-01-11 15:47:09 +09:00
Yuya Nishihara
bde9cda915 cli: colorize local/remote_branches keywords
This is a follow up for 0e14a1f04d "templater: add local/remote_branches
keywords."
2024-01-11 15:47:09 +09:00
Yuya Nishihara
3357882496 cli: group diff formatting options in help
Since DiffFormatArgs is flattened into log args, it's a bit hard to reason about
what --color-words means for example.
2024-01-11 15:46:58 +09:00
Yuya Nishihara
9b5439256f cli: leverage next_help_heading attribute to deduplicate "Global Options"
It's scoped to the GlobalArgs and the flattened EarlyArgs.
https://docs.rs/clap/latest/clap/_derive/index.html#command-attributes
2024-01-11 15:46:58 +09:00
Yuya Nishihara
5047e114ea cli: run "debug index" without loading repo
This is the command to dump the current state. I don't think we'll want to
merge the concurrent operations.
2024-01-11 09:15:19 +09:00
Yuya Nishihara
180ea49fda cli: run "debug reindex" without loading repo
If the existing index was corrupt, it would have to be rebuilt while loading a
repo (at least in colocated environment.) Then, the index will be rebuilt again.
2024-01-11 09:15:19 +09:00
Valentin Gatien-Baron
6caeacf29e cli: fix missing word in help of --ignore-working-copy 2024-01-10 12:30:23 -08:00
Yuya Nishihara
dc68f1eeb2 revset: remove unused lifetime parameter from Revset<'index> 2024-01-09 10:37:43 +09:00
Yuya Nishihara
e9d31177cb op_store: implement GC of unreachble operations and views
Since new operations and views may be added concurrently by another process,
there's a risk of data corruption. The keep_newer parameter is a mitigation
for this problem. It's set to preserve files modified within the last 2 weeks,
which is the default of "git gc". Still, a concurrent process may replace an
existing view which is about to be deleted by the gc process, and the view
file would be lost.

#12
2024-01-09 10:37:03 +09:00
Yuya Nishihara
7cfd32bac1 cli: disallow gc run from non-head operation
It doesn't make sense to do gc from a non-head operation because that means
either the head operation would be corrupted or the --at-op argument is
ignored.
2024-01-09 10:37:03 +09:00
Essien Ita Essien
08d1809dc1 Issue warning if renaming branch with a remote tracking branch. 2024-01-07 18:04:38 +00:00
Martin von Zweigbergk
0046af8d4c cli: allow non-static version strings from custom binaries
We would like to use a non-static version string at Google. We have a
workaround using Lazy, but it seems unfortunate to have to do
that. Using dynamic strings requires Clap's `string` feature, which
increases the binary size by 140 kiB (0.6%).
2024-01-06 16:24:55 -08:00