Commit Graph

2020 Commits

Author SHA1 Message Date
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
Martin von Zweigbergk
bb755ae754 working_copy: use MergedTreeBuilder in test 2023-08-30 06:17:21 -07:00
Martin von Zweigbergk
6b3fa3ee79 working_copy: avoid a nested TreeBuilder in a test
It's just slightly simpler to not create a `TreeBuilder` to create a
`TreeValue`; we can instead write to the outer builder.
2023-08-30 06:17:21 -07:00
Martin von Zweigbergk
7e6930b56f backend: remove last few instances of MergedTreeId::as_legacy_tree_id() 2023-08-30 06:17:21 -07:00
Martin von Zweigbergk
962da1947e tests: make dump_tree() work with merged trees
My goal is to minimize impact on tests when we start using the new
format.
2023-08-30 06:17:21 -07:00
Waleed Khan
56c61fd047 merge_tools: create builtin diff editor 2023-08-30 05:38:10 -04:00
Martin von Zweigbergk
145b0b24d8 commit: drop merged_ prefix from tree() and tree_id()
The old `tree()` and `tree_id()` functions are now gone, so we can use
those names for the new functions.
2023-08-29 08:32:04 -07:00
Martin von Zweigbergk
f54b456e64 working_copy: leverage Store::get_root_tree() in current_tree()
I guess I forgot this when I added `Store::get_root_tree()`.
2023-08-29 08:32:04 -07:00
Martin von Zweigbergk
2d50d8a077 merged_tree: propagate errors from from_legacy_tree() 2023-08-29 08:32:04 -07:00
Martin von Zweigbergk
67832a3940 merged_tree: take store argument to write_tree() instead of new()
The store isn't needed until we write the trees, so I think it makes
more sense to pass it there.
2023-08-29 08:32:04 -07:00
Martin von Zweigbergk
64b47bae56 tree: inline legacy_id() into its sole caller 2023-08-29 07:01:52 -07:00
Martin von Zweigbergk
d9ce70c176 tests: make create_tree() return MergedTree
I think most tests want a `MergedTree`, so this makes `create_tree()`
return that. I kept the old function as `create_single_tree()`. That's
now only used in `test_merge_trees` and `test_merged_tree`.

I also consistently imported the functions now, something I've
considered doing for a long time.
2023-08-29 07:01:52 -07:00
Martin von Zweigbergk
e4c6595620 tests: make create_random_tree() return a MergedTreeId 2023-08-29 07:01:52 -07:00
Martin von Zweigbergk
9c77e6aa8c commit_builder: remove last traces of pre-MergedTree API 2023-08-29 07:01:52 -07:00
Martin von Zweigbergk
6e3590f5cd tests: remove last uses of Commit:tree() and delete it 2023-08-29 07:01:52 -07:00
Yuya Nishihara
55c6e90555 git: remove handling of real remote named "git", always override
#1690
2023-08-29 22:50:46 +09:00
Yuya Nishihara
ce3d28e234 git: do not import refs from remote named "git"
I made it simply fail on explicit fetch/import, and ignored on implicit import.
Since the error mode is predictable and less likely to occur. I don't think it
makes sense to implement warning propagation just for this.

Closes #1690.
2023-08-29 22:50:46 +09:00
Yuya Nishihara
04e2f5ed20 git: fix typo in GitFetchError message 2023-08-29 22:50:46 +09:00
Yuya Nishihara
35a596ff66 git: prohibit creation of remote named "git"
#1690
2023-08-29 22:50:46 +09:00
Yuya Nishihara
0e26ef7733 git: add constant for pseudo remote name "git" 2023-08-29 22:50:46 +09:00
Martin von Zweigbergk
f47da04a43 tree: delete recursive diff iterator, which is no longer used 2023-08-28 16:21:44 -07:00
Martin von Zweigbergk
1b24b522f6 tree: move diff_summary() to MergedTree 2023-08-28 16:21:44 -07:00
Martin von Zweigbergk
a7a2150328 tree: delete unused DiffSummary::is_empty() 2023-08-28 16:21:44 -07:00
Martin von Zweigbergk
dc06bbc7d1 commit: migrate remaining uses of Commit::tree_id() and delete it 2023-08-28 15:58:34 -07:00
Martin von Zweigbergk
7bfd439bd1 rewrite: return MergedTree from merge_commit_trees_without_repo() 2023-08-28 15:58:34 -07:00
Martin von Zweigbergk
90e78a1424 rewrite: return MergedTree from merge_commit_trees() 2023-08-28 15:58:34 -07:00
Martin von Zweigbergk
bd6098e09e cli: merge trees via MergedTree in jj move 2023-08-28 15:58:34 -07:00