Commit graph

544 commits

Author SHA1 Message Date
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
Yuya Nishihara
95d83cbfe5 object_id: make ObjectId constructors non-trait methods
I'm going to add try_from_hex(), which requires Self: Sized. Such trait bound
could be added, but I don't think we'll need abstracted ObjectId constructors
at all.
2024-01-05 23:36:57 +09:00
Yuya Nishihara
31b236a70d object_id: move HexPrefix and PrefixResolution from index module 2024-01-05 10:20:57 +09:00
Yuya Nishihara
fa5e40719c object_id: extract ObjectId trait and macros to separate module
I'm going to add a prefix resolution method to OpStore, but OpStore is
unrelated to the index. I think ObjectId, HexPrefix, and PrefixResolution can
be extracted to this module.
2024-01-05 10:20:57 +09:00
Yuya Nishihara
f169c99fb4 cli: add "op abandon root..head" command that "reparents" operations
In order to implement GC (#12), we'll need to somehow prune old operations.
Perhaps the easiest implementation is to just remove unwanted operation files
and put tombstone file instead (like git shallow.) However, the removed
operations might be referenced by another jj process running in parallel. Since
the parallel operation thinks all the historical head commits are reachable, the
removed operations would have to be resurrected (or fix up index data, etc.)
when the op heads get merged.

The idea behind this patch is to split the "op log" GC into two steps:
 1. recreate operations to be retained and make the old history unreachable,
 2. delete unreachable operations if the head was created e.g. 3 days ago.
The latter will be run by "jj util gc". I don't think GC can be implemented
100% safe against lock-less append-only storage, and we'll probably need some
timestamp-based mechanism to not remove objects that might be referenced by
uncommitted operation.

FWIW, another nice thing about this implementation is that the index is
automatically invalidated as the op id changes. The bad thing is that the
"undo" description would contain an old op id. It seems the performance is
pretty okay.
2024-01-04 11:44:36 +09:00
Matt Stark
3f0a49dafe Ensure you never drop the working commit with --skip-empty
See #2766 for discussions
2024-01-04 13:33:24 +11:00
Yuya Nishihara
c53748d732 op_walk: allow walk_ancestors() from more than one head operations 2024-01-02 10:30:08 +09:00
Yuya Nishihara
51691ea22c tests: add lib tests for op id resolution, migrate some from cli
CLI testing is slow and harder to set up crafted environment.
2024-01-02 10:30:08 +09:00
Yuya Nishihara
c9b581589c op_walk: simplify arguments passed to high-level "opset" query functions 2024-01-01 10:22:23 +09:00
Yuya Nishihara
26b5f38f45 op_walk: move "opset" query functions from jj_cli 2024-01-01 10:22:23 +09:00
Yuya Nishihara
e4460d5386 op_walk: add error types for fake "opset" expression
This removes CommandError dependency from these resolution functions. We might
want to refactor the error types again if we introduce a real "opset" evaluator.

The error message for unresolved op heads now includes "@" instead of the whole
expression.
2024-01-01 10:22:23 +09:00
Yuya Nishihara
94fc32ab47 op_walk: extract walk_ancestors() to new module
I'm going to extract fake "opset" resolution functions there, and I think
walk_ancestors() belongs to the same category.
2024-01-01 10:22:23 +09:00
Yuya Nishihara
6dd936f72f op_heads: let caller decide resolve_op_heads() error type
The resolver callback usually returns wider error type, which I don't think
is a variant of OpHeadResolutionError.

To help type inference, resolver's error type is E, not E1 where E: From<E1>.
2024-01-01 10:22:23 +09:00
Martin von Zweigbergk
0d02724341 cli: read files concurrently when diffing
Same reasoning as in the previous patch - this should help
high-latency backends.
2023-12-29 13:37:13 -08:00
Yuya Nishihara
60c5e86fe1 cli: add missing copyright header to cli/src/commands/*.rs 2023-12-29 22:06:50 +09:00
Yuya Nishihara
43e016a7d1 index: add explicit reindexing method that can propagate error 2023-12-29 13:05:58 +09:00
Yuya Nishihara
3abe6be384 index: propagate DefaultIndexStore::init/reinit() errors 2023-12-29 13:05:58 +09:00
Yuya Nishihara
bb73cd491f clenaup: don't use debug format to embed ObjectId in error message
Also fixed typo, s/a/an/.
2023-12-29 13:05:58 +09:00
Waleed Khan
88cc4daad3 merge_tools: upgrade to scm-record v0.2.0
To get the fix at https://github.com/arxanas/git-branchless/pull/1013 "fix(record): don't add new files with no selected contents".
2023-12-26 19:25:02 -08:00
Yuya Nishihara
dde42b9c05 index: rename resolve_prefix() to resolve_commit_id_prefix()
I'll probably add change id lookup methods to CompositeIndex. The Index trait
won't gain resolve_change_id_prefix(), but I also renamed its resolve_prefix()
for consistency.
2023-12-26 01:03:10 +09:00
Ilya Grigoriev
1fb9df252b split.rs: stop using DescendantRebaser::new
This requires creating a new public API as a substitute. I took the opportunity
to also add some comments to the
`MutRepo::record_rewritten_commit`/`record_abandoned_commit` functions.

I imade the simplest possible addition to the API; it is not a very elegant
one. Eventually, the entire `record_rewritten_commit` API should probably be
refactored again.

I also added some comments explaining what these functions do.
2023-12-24 19:25:16 -08:00
Ilya Grigoriev
c7c8960bcc test_split_command: check that new commits inherit author dates
At some point, I tried `new_commit` instead of `rewrite_commit` in the split
command. That seemed to work, but messed up the dates in a subtle way.

This commit should prevents repeats of this mistake and emphasize the
importance of the author dates being preserved.
2023-12-24 19:25:16 -08:00
Ilya Grigoriev
6bfd09009f move.rs: remove use of MutRepo::create_descenant_rebaser.
After this, the internal function is only used in tests.
2023-12-24 19:25:16 -08:00
Yuya Nishihara
6b862c6f23 cli: don't panic on empty alias substitution
This partially reverts 6c627fb30d "cli: default to log when no subcommand is
provided." We could reject an empty alias at all, but we would still need to
ensure that the expanded alias contained a subcommand name.

The help output is a bit odd as the <COMMAND> can be omitted, but I think
that's acceptable. If we do care about that, maybe we can override_usage().
2023-12-24 23:31:28 +09:00
Yuya Nishihara
55b4f69fb6 repo: propagate store error from add_heads() 2023-12-24 00:22:30 +09:00
Yuya Nishihara
1836a105bb cli: warn if -R/--repository could be involved in command alias expansion
#2414
2023-12-24 00:20:38 +09:00
Yuya Nishihara
30b5e88b04 cli: use cwd-relative workspace config to resolve default command and aliases
This is basically the same as Mercurial's workaround. I don't know about Git,
but arguments order is very restricted in git, so -C path can be parsed prior
to alias expansion. In hg and jj, doing that would be messy and unreliable.

Closes #2414
2023-12-24 00:20:38 +09:00
Yuya Nishihara
941e53802f cli: error out early if -R path is invalid
It should be better to handle invalid -R path globally. The error message is
a bit worse, but I think it's still okay.

This helps to load temporary config from the cwd-relative path. If the command
processing continued with an invalid -R path, the temporary config would have
to be explicitly discarded.
2023-12-24 00:20:38 +09:00
Yuya Nishihara
c82b2c78fd cli: inline init_workspace_loader()
In order to load command aliases from .jj/repo/config.toml, WorkspaceLoader
will be changed to be instantiated earlier with the cwd path.
2023-12-24 00:20:38 +09:00
Yuya Nishihara
5bf9e4192a cli: don't look for added/removed conflicts across old/new heads
removed_heads..added_heads won't stop if new head is added on top of non-head
commit for example.

#2729
2023-12-21 23:40:52 +09:00