Commit graph

2046 commits

Author SHA1 Message Date
Martin von Zweigbergk
e3f82cd99a tests: leverage TestRepo::init() in test_merged_tree
I forgot to update these call sites when I introduced (the new version
of) `TestRepo::init()`.
2023-09-20 07:47:30 -07:00
Martin von Zweigbergk
f39b0d24c8 tests: use test backend in working copy tests, fix MergedTree bug
Only tests dealing with Git submodules care about the backend type.

Switching the tests to use the test backend also uncovered another bug
in `MergedTree`, so I fixed that too. The bug only happens with legacy
trees (path-level conflicts) and backends that care about the conflict
path, so it wouldn't happen with Git backends, and it wouldn't happen
at Google either (because we use tree-level conflicts).
2023-09-19 20:49:41 -07:00
Martin von Zweigbergk
0f7054e8c3 tests: wherever we test with only one backend, use the test backend
I don't think there's any reason to use the local backend in tests
instead of using the stricter test backend.

I think we should generally use the test backend in tests and only use
the local backend or git backend when there's a particular reason to
do so (such as in `test_bad_locking` where the on-disk directory
structure matters). But this patch only deals with the simpler cases
where we were only testing with the local backend.
2023-09-19 20:49:41 -07:00
Martin von Zweigbergk
d575aaeca8 backend: move constant functions first
`root_commit_id()`, `root_change_id()`, and `empty_tree_id()` were
strangely ordered between `write_symlink()` and `read_tree().
2023-09-19 05:24:51 -07:00
Martin von Zweigbergk
7ecd64fde1 merged_tree: use child path when merging child
This fixes a bug where we used the parent directory's path when trying
read trees and files for a child entry. Many tests in
`test_merged_tree` fail after switching to the test backend there
without this fix/
2023-09-18 07:53:19 -07:00
Martin von Zweigbergk
63ba2a6346 tests: add a strict backend for use in tests
We ran into a bug in `MergedTree` with our commit backend at
Google. The problem there was that `MergedTree` sometimes uses the
wrong path when reading files and trees. We didn't catch the bug in
our tests (outside of Google) because both our backends let you read
files and trees at any path.

This commit introduces a stricter backend that we can use in tests to
catch this kind of bug. For simplicity, it stores all data in
memory. Since tests are short-lived, I think that should be fine.

For now, this backend is stricter only in that it doesn't mix objects
written to different paths. We can make it strict/lossy in other ways
later (e.g. modifying written commit objects).

I think having a backend designed for tests can also be useful for
later making it possible to control the backend, e.g. to inject
errors.

We may want to replace almost all uses of the local backend in tests
with uses of this new test backend.
2023-09-18 07:53:19 -07:00
Martin von Zweigbergk
cfffbb6cd7 content_hash: make public
I'm going to use `content_hash` in a new commit backend for use in
tests.
2023-09-18 07:53:19 -07:00
Martin von Zweigbergk
9c30d7500b testutils: delete bool-typed init() in favor of enum-typed version
It makes the call sites clearer if we pass the `TestRepoBackend` enum
instead of the boolean `use_git` value. It's also more extensible (I
plan to add another backend for tests).
2023-09-18 07:15:37 -07:00
Martin von Zweigbergk
50596c499e testutils: allow passing TestRepoBackend to TestWorkspace too 2023-09-18 07:15:37 -07:00
Martin von Zweigbergk
c6cf9d54f6 testutils: add an enum for TestRepo backend
I plan to add another backend for use in tests.
2023-09-18 07:15:37 -07:00
Martin von Zweigbergk
79527d707c testutils: use .jj-internal git repos in most tests
I don't think there's much reason to run most tests with a `.git`
directory outside of `.jj`. I think it's just that way for historical
reasons. It's been that way since I added support for `.jj`-internal
repos in a8a9f7dedd.

The reason I want to switch is to make it a little easier to create
test repos for different backends. The problem with `.jj`-external git
repos is that they depend on an additional path.

I had to update `test_bad_locking.rs` to make the code merging
directories able handle missing directories on some side, because
git's loose objects result in directories getting created on one or
both sides.
2023-09-18 07:15:37 -07:00
Martin von Zweigbergk
2bc641c57c test_bad_locking: make merge_directories() expect non-existent target
I ran into some issues here when switching our tests to use
`.jj`-internal git repos. For example, the `std::fs::copy()` calls
started failing, which may be related to #2103. I think one problem is
that we could end up calling `merge_directories()` twice for the same
directory. This patch fixes that by deduping the paths we call with,
and makes the function assume that the output directory doesn't exist.
2023-09-18 06:59:28 -07:00
Yuya Nishihara
fc86d91b15 tests: fix test_merge_views_branches() to set up local "feature" branches
Git refs aren't involved in this test.
2023-09-11 01:07:29 +09:00
Yuya Nishihara
b80d04319d tests: rewrite "@"/"root" revset resolution tests without using bad git refs 2023-09-11 01:07:29 +09:00
Martin von Zweigbergk
86206e83a4 repo_path: avoid repeated copying of PathBuf in to_fs_path()
I've noticed `WorkspaceCommandHelper::format_file_path()` appear in
profiles a few times. A big part of that is spent in
`RepoPath::to_fs_path()`. I think I had been thinking that
`PathBuf::join()` takes `self` by value and mutates it, but it turns
out it creates a new instance. So our `result = result.join(...)` in a
loop was copying the `PathBuf` over and over. This fixes that and also
reserves the expected size. That speeds up `jj files
--ignore-working-copy -r v6.0` in the Linux repo from 546.0 s to 509.3
s (6.7%).
2023-09-09 08:43:29 -07:00
Yuya Nishihara
d05aaf30b4 git: promote imported commits to tree-conflict format if configured 2023-09-08 21:54:43 +09:00
Yuya Nishihara
0c4e667e48 git: import new head commits all at once 2023-09-08 21:54:43 +09:00
Yuya Nishihara
f744e5920b git: create no-gc ref by GitBackend
Since we now have an explicit method to import heads, it makes more sense to
manage no-gc refs by the backend.
2023-09-08 21:54:43 +09:00
Yuya Nishihara
17f502c83a git: do not import unknown commits by read_commit(), use explicit method call
The main goal of this change is to enable tree-level conflict format, but it
also allows us to bulk-import commits on clone/init. I think a separate method
will help if we want to provide progress information, enable check for
.jjconflict entries under certain condition, etc.

Since git::import_refs() now depends on GitBackend type, it might be better to
remove git_repo from the function arguments.
2023-09-08 21:54:43 +09:00
Yuya Nishihara
dde1c1ec9c revset: use ancestors(x, 0) in tree substitution test 2023-09-08 09:28:14 +09:00
Yuya Nishihara
8b825796ff cli: rewrite "x | x-" in default log revset as "ancestors(x, 2)" 2023-09-08 09:28:14 +09:00
James Sully
0946934ca6 revset: Add optional argument n to ancestors() in revset language 2023-09-08 02:50:58 +10:00
James Sully
6ea10906a8 revset: add ancestors_range() method 2023-09-08 02:50:58 +10:00
Yuya Nishihara
c4769e0b7c revset: translate symbol rules in error message
Since we have overloaded operator symbols, we need to deduplicate them
upfront. Legacy and compat operators are also removed from the suggestion.

It's a bit ugly to mutate the error struct before calling Error::renamed_rule(),
but I think it's still better than reimplementing message formatting function.
2023-09-07 15:29:39 +09:00
Yuya Nishihara
a868b2d9a5 revset: do not lookup unimported tags or remote branches by unqualified name
Since e7e49527ef "git: ensure that remote branches never diverge", the last
known "refs/remotes" ref should be synced with the corresponding remote branch.
So we can always trust the branch@remote expression. We don't need "refs/tags"
lookup either since tags should have been imported by git::import_refs().

FWIW, I'm thinking of reorganizing view.git_refs() map as per-remote views.
It would be nice if we can get rid of revsets and template keywords exposing
low-level Git ref primitives.
2023-09-06 13:42:22 +09:00
Yuya Nishihara
4e6323c0a4 revset: add basic test for tag name resolution 2023-09-06 13:42:22 +09:00
Yuya Nishihara
8f4512b109 git: rename local variables in diff_refs_to_export()
old/new_branch sounds like a branch name, but it's a RefTarget. And
jj_known_refs_passing_filter may contain "new" ref names.
2023-09-06 08:17:49 +09:00
Yuya Nishihara
119cc88832 git: extract calculation step from export_some_refs()
export_some_refs() is big, let's split it to functions of reasonable size.
2023-09-06 08:17:49 +09:00
Yuya Nishihara
89f1d83a22 git: do not export new ref if racy process created one with the same name
Since we've checked the ref doesn't exist in this code path, I think it's
better to not overwrite the existing ref.
2023-09-06 08:17:49 +09:00
Yuya Nishihara
a4dd598e3e git: extract helper that exports single updated ref 2023-09-06 08:17:49 +09:00
Yuya Nishihara
d1a08782c9 git: extract helper that exports single deleted ref 2023-09-06 08:17:49 +09:00
Yuya Nishihara
7282b517e8 git: remove stale TODO comment about FailedRefExportReason 2023-09-06 08:17:49 +09:00
Philip Metzger
8dda7e21e0 revsets: Add descendants_at and ancestors_at
They are needed for `next` and `prev`.
They behave symmetrically for parents and children.
2023-09-05 23:13:39 +02:00
Martin von Zweigbergk
f198a1e5f9 git: skip branches on root commit on export
Git doesn't have a root commit, so we should skip branches pointing to
it on export, just like we do with conflicted branches (which Git also
doesn't support).
2023-09-04 20:08:11 -07:00
Martin von Zweigbergk
ef550a9d6d git: include reason for each failed ref export 2023-09-04 20:08:11 -07:00
Martin von Zweigbergk
f6c24fbcef git: return refs that failed to export in sorted order
Before this patch, the order would depend on the reason we failed to
export a ref, because we would add to the `failed_branches` list in
several different places. What's worse, when the export failed because
the branch was conflicted or had an invalid name (from Git's
perspective), it was non-deterministic because we iterated over a
HashSet. This patch fixes that by sorting at the end.

Note that we still want the `branches_to_update` map to be a
`BTreeMap` so we update branches in deterministic order. Otherwise the
error when trying to export both branches `main` and `main/sub` will
become non-deterministic.
2023-09-04 20:08:11 -07:00
Yuya Nishihara
b0c8e9ef62 revset: add 0-ary "::" and ".." operators as short for "all()" and "~root()"
Suppose "x::y" is the operator that defaults to "root()::visible_heads()"
respectively, "::" is identical to "all()". Since we've just changed the
behavior of "..y", ".." is now "root()..visible_heads()" meaning "~root()".
2023-09-05 10:40:04 +09:00
Yuya Nishihara
6b2ad23f8f revset: evaluate "..y" expression to "root()..y"
This seems useful since the root commit is often uninteresting. It's also
consistent with "x::y" in a way that the left operand defaults to "root()".
2023-09-05 10:40:04 +09:00
Yuya Nishihara
f2c1697362 revset: fix comment about "@" expression 2023-09-05 10:40:04 +09:00
Yuya Nishihara
e3c85d6ecc revset: convert root symbol to function
The idea is that we can fully eliminate special symbols that would otherwise
shadow user branches, tags, or change ID prefixes.

Closes #2095
2023-09-04 10:36:30 +09:00
Martin von Zweigbergk
e3825495e3 store: don't include cached objects in Debug format
I was looking into some overly verbose logs and happened to notice
that `Store` uses the default derived, which presumably means it's
going to include all objects in its cached. Just including the
backend's debug string seems enough.
2023-09-01 16:49:23 -07:00
Martin von Zweigbergk
16c897d8b4 conflicts: leverage Merge::map() in materialize_merge_result() 2023-09-01 16:23:39 -07:00
Martin von Zweigbergk
b8f71a4b30 working_copy: in LockedWorkingCopy::drop(), discard unsaved changes
In `LockedWorkingCopy::drop()`, we panic if the caller had not called
`finish()`. IIRC, the idea was both to find bugs where we forgot to
call `finish()` and to prevent continuing with a modified
`WorkingCopy` instance. I don't think the former has been a problem in
practice. It has been a problem in practice to call `discard()` to
avoid the panic, though. To address that, we can make the `Drop`
implementation discard the changes (forcing a reload of the state if
the working copy is accessed again).
2023-09-01 12:25:47 -07:00
Martin von Zweigbergk
5ef0be73c1 merged_tree: allow building trees with variable-arity overrides
When restoring (`jj restore`) a 3-sided conflict from one tree into a
2-sided tree (or a resolved tree), we'll need to extend the size arity
of the target tree to that of the source tree. I had not considered
this case before. This patch relaxes the constraint in
`MergedTreeBuilder` to allow such cases. The additional trees are
based on empty trees with only the larger overrides in them.
2023-09-01 06:09:37 -07:00
Martin von Zweigbergk
d29c831ef9 merge: add a function for padding a Merge to a given size
This will be useful for padding merge objects in `MergedTreeBuilder`
to the size of the widest override.
2023-09-01 06:09:37 -07:00
Martin von Zweigbergk
be08707a3a op_heads_store: propagate errors from OpStore 2023-08-31 12:36:47 -07:00
Martin von Zweigbergk
9d9b2cd057 tests: leverage create_tree() in a few more tests 2023-08-30 19:58:42 -07:00
Martin von Zweigbergk
26581750fe store: add a empty_merged_tree_id() helper
Many (most?) callers of `Store::empty_tree_id()` really want a
`MergedTreeId`, so let's create a helper for that. It returns the
`Legacy` variant, which is what all current callers used. That should
be all we need since the two variants compare equal these days, and
since trees built based on the legacy variant can get promoted to the
new variant on write if the config is enabled.
2023-08-30 19:58:42 -07:00
Martin von Zweigbergk
61501db8ec merged_trees: consider conflict-format-change-only commits empty
When we start writing tree-level conflicts in an existing repo, we
don't want commits that change the format to be non-empty if they
don't change any content. This patch updates `MergeTreeId::eq()` to
consider two resolved trees equal even if only their `MergedTreeId`
variant is different (one is path-level and one is tree-level).

I think I've gone through all places we compare tree ids and checked
that it's safe to compare them this way. One consequence is that
rebasing a commit without changing the parents (typically
auto-rebasing after `jj describe`) will not lead to the tree id
getting upgraded, due to an optimization we have for that case. I
don't think that's serious enough to handle specially; we'll have to
support the old format for existing repos for a while regardless of a
few commits not getting upgraded right away.

The number of failing tests with the config option enabled drop from
108 to 11 with this patch.
2023-08-30 06:17:21 -07:00
Martin von Zweigbergk
8e47d2d66f merged_tree: add config option to write trees using new format
We're finally ready to start writing trees using the new format where
we represent conflicts by having multiple trees in the commit instead
of having a single tree with multiple entries at a path. This patch
adds a config option for that. It's not ready to be used yet, so I
haven't updated the release notes or other documentation.

I added only a simple CLI test for testing what happens when the
config is enabled in an existing repo. 108 tests currently fail if we
flip the default.
2023-08-30 06:17:21 -07:00