Commit graph

1581 commits

Author SHA1 Message Date
Yuya Nishihara
589917a53c repo_path: micro-optimize .join() to not reallocate cloned Vec
While playing with perf.data captured with "jj log", I noticed RepoPath::join()
has measurable cost. The first half is small alloc()s for Vec and Strings, and
the latter is realloc() on Vec::push(). Removing realloc() is easy, so let's
do that.
2023-06-15 00:45:07 +09:00
Martin von Zweigbergk
d886d8c203 conflicts: extract methods for converting to/from generic legacy form
We already have the new `Conflict::from_backend_conflict()` for
converting from a `backend::Conflict`, but we model conflicts in a
similar way in at least `RefTarget`. I'd like to be able to use
`conflicts::Conflict` there too. To prepare for that, let's extract
generic methods from `Conflict::from_backend_conflict()` and
`Conflict::to_backend_conflict()`.

I'm not sure I'll get around to making `RefTarget` use `Conflict` but
this commit seems like nice cleanup either way. It makes the tests
simpler if nothing else.
2023-06-13 21:48:35 +02:00
Martin von Zweigbergk
bbbae2c172 conflicts: fix a typo (lossy conflict -> lossy conversion) 2023-06-13 21:48:35 +02:00
Martin von Zweigbergk
02bb3aecf3 tree: don't read file contents on contents/executable "conflict"
If one side changes the contents and one side changes the executable
bit, we get a non-trivial conflict in the `TreeValue`s, but once we've
split them up into `FileId`s and bools, we can trivially resolve them
separately, without having to read file contents.
2023-06-13 08:49:46 +02:00
Martin von Zweigbergk
6e6ca16fd4 tree: make try_resolve_file_conflict() write resolved file to store
The function takes a `&Conflict<Option<TreeValue>>` argument so it
seems it should return an `Option<TreeValue>` for symmetry.
2023-06-13 08:49:46 +02:00
Martin von Zweigbergk
1f1c6867c7 conflicts: add a simplify() method, taken from tree.rs
It seems generally useful to be able to simplify a conflict, and it's
not specific to merging trees, so let's move it to
`conflicts.rs`. Once we're done with the migration to tree-level
conflicts, I think `Conflict::simplify()` will remain but
`tree::simplify_conflict()` will be gone.

The tests I added there are quite similar to those of
`trivial_merge()`. I hope we can make `Conflict::simplify()` call
`trivial_merge()` later. I think it would also make sense to move
`trivial_merge()` onto `Conflict`, or at least have a
`Conflict::resolve_trivial()` calling `trivial_merge()`.
2023-06-13 08:49:46 +02:00
Martin von Zweigbergk
e5a28996b4 tree: specialize and inline tree_value_to_conflict()
It seems that this function didn't serve the purpose I intended it to;
we only passed in `TreeValue::Conflict` variants to it.
2023-06-13 08:49:46 +02:00
Martin von Zweigbergk
ee98d1eee8 tree: remove check for conflict-simplification resulting in deletion
Since we switched to the new `conflicts::Conflict` type, we represent
a missing tree entry by a `None` value in the conflict, not a missing
"add", so the condition removed in this commit will never happen, and
the case will be handled by the case just below it instead.
2023-06-13 08:49:46 +02:00
Martin von Zweigbergk
19fd8a917a conflicts: remove ConflictId from update_conflict_from_content()
For tree-level conflicts (#1624), I plan to remove `ConflictId`
completely. This commit removes `ConflictId` from
`update_conflict_from_content()` by instead making it take a
`Conflict<Option<TreeValue>>` and return a possibly different such
value.

I made the call site in `working_copy` avoid writing the conflict to
the store if it's unchanged, but I didn't make the same optimization
in `merge_tools` becuase it's much more likely to have changed there.
2023-06-13 08:49:46 +02:00
Ilya Grigoriev
096538ba18 revsets: stop jj parsing br as a git_ref refs/heads/br
Use `br@git` instead.

Before, if there is not a local branch `br`, jj tried to resolve
it as a git ref `refs/heads/br`. Unchanged from before, `br` can
still be resolved as a tag `refs/tag/br`.
2023-06-12 14:31:44 -07:00
Ilya Grigoriev
a483252cf2 revset: allow checking out git-tracking (@git) branches 2023-06-12 14:31:44 -07:00
Ilya Grigoriev
8df945b71d cmd: have jj branch list report git-tracking (@git) branches
This doesn't change the way @git branches are stored in `git_refs` as opposed
to inside `BranchTarget` like normal remote-tracking branches. There are
subtle differences in behavior with e.g. `jj branch forget` and I'm not sure
how easy it is to rewrite `jj git import/export` to support a different
way of storage.

I've decided to call these "local-git tracking branches" since they track
branches in the local git repository. "local git-tracking" branches sounds a
bit more natural, but these could be confused with there are no remote
git-tracking branches. If one had the idea these might exist, they would be
confused with remote-tracking branches in the local git repo.

This addresses a portion of #1666
2023-06-12 14:31:44 -07:00
dependabot[bot]
abe5d098c5 cargo: bump rustix from 0.37.19 to 0.37.20
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 0.37.19 to 0.37.20.
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v0.37.19...v0.37.20)

---
updated-dependencies:
- dependency-name: rustix
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-12 12:29:26 -07:00
Ilya Grigoriev
738f99ddf1 test_revset.rs: disable nightly clippy false-positive warning
I opened a bug for the clippy error:
https://github.com/frondeus/test-case/issues/122
2023-06-11 13:11:01 -07:00
Yuya Nishihara
7a6f832e14 operation: iterate ancestors incrementally with timestamp-based heuristic
Suppose the operation log is mostly linear, this means "jj op log" iterator
won't look ahead more than one entry.

Another idea is to either add a "generation" number to operation data, or
build index of operations. Since we'll eventually add GC command, I don't
think op index would be required. I think readdir() is good enough to resolve
hex prefix against ~10k entries.

For now, walk_ancestors() is a free function. If we add Repo-like abstraction
over OpStore + OpHeadsStore, this function will probably be migrated there.
2023-06-11 11:38:03 +09:00
Yuya Nishihara
5cecdb54ce dag_walk: add lazy topo-order iterator for chronological data
The idea is that the DAG can be split at single fork point while walking
chronologically, and run DFS-based topological sort for each sub graph.
This works well for operation log.

We could also build a topo-sort stack while splitting, but we couldn't detect
cycles in that way. It would also be quite expensive on pessimistic cases.
2023-06-11 11:38:03 +09:00
Yuya Nishihara
fb7fff4409 dag_walk: extract topo-order helper that doesn't reverse the result
I'll add an iterator wrapper that pop()s the sorted result.
2023-06-11 11:38:03 +09:00
Yuya Nishihara
4987c74d4b dag_walk: flatten nested loops in topo_order_reverse() 2023-06-11 11:38:03 +09:00
Yuya Nishihara
d9c417dcb8 dag_walk: add a few more tests for topo_order_reverse(), extract callbacks
I'm going to add an iterator version which can load linear part of the
operation history lazily.
2023-06-11 11:38:03 +09:00
Yuya Nishihara
459e9174ad dag_walk: remove unneeded trait bound on node type 2023-06-11 11:38:03 +09:00
dependabot[bot]
840c283cac cargo: bump tempfile from 3.5.0 to 3.6.0
Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.5.0 to 3.6.0.
- [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Stebalien/tempfile/compare/v3.5.0...v3.6.0)

---
updated-dependencies:
- dependency-name: tempfile
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-08 22:53:55 -07:00
Martin von Zweigbergk
de71df2447 conflicts: move conversion to FileId conflict to callers
This simplifies a bit, in particular by removing the error case from
`extract_file_conflict_as_single_hunk()`.
2023-06-07 13:45:16 -07:00
Martin von Zweigbergk
ad667d6bb5 conflicts: convert TreeValue to FileId conflict to avoid panic!
By converting a `Conflict<Option<TreeValue>>` to a
`Conflict<Option<FileId>>`, we don't have to check later that
`TreeValue` really is a `File`.
2023-06-07 13:45:16 -07:00
Waleed Khan
74b846870c feat(diff): add ui.diff-instructions option to suppress JJ-INSTRUCTIONS file 2023-06-06 22:43:14 -07:00
dependabot[bot]
eb1fafa89e cargo: bump once_cell from 1.17.2 to 1.18.0
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.17.2 to 1.18.0.
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](https://github.com/matklad/once_cell/compare/v1.17.2...v1.18.0)

---
updated-dependencies:
- dependency-name: once_cell
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-05 16:22:45 +00:00
dependabot[bot]
4b0b98a3da cargo: bump regex from 1.8.3 to 1.8.4
Bumps [regex](https://github.com/rust-lang/regex) from 1.8.3 to 1.8.4.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.8.3...1.8.4)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-05 16:11:29 +00:00
Waleed Khan
23a4124d20 feat(revset): suggest similar branch names 2023-06-05 11:11:17 -05:00
Waleed Khan
f61cbae022 refactor(revset): move collect_similar from cli_util to revset 2023-06-05 11:11:17 -05:00
Martin von Zweigbergk
ac8313f119 cli: in jj git push, create transaction in a single place
I added a function for updating the description on an existing
transaction. That way we can create the transaction earlier. I'll try
to make `--change` and `--branch` not mutually exclusive next.
2023-06-04 20:50:11 -07:00
Martin von Zweigbergk
29b676f24f store: do conversion to/from backend::Conflict
We now convert to/from `backend::Conflict` right before/after calling
the `Store` methods, so we can simplify by having the `Store` do the
conversion.
2023-06-04 06:48:34 -07:00
Martin von Zweigbergk
43c55fcbc9 tree: replace uses of backend::Conflict 2023-06-04 06:48:34 -07:00
Martin von Zweigbergk
c378503991 conflicts: replace remaining uses of backend::Conflict 2023-06-04 06:48:34 -07:00
Martin von Zweigbergk
9907cccf37 conflicts: use an early return to reduce indentation
Thanks to @ilyagr for the suggestion.
2023-06-04 06:48:34 -07:00
Martin von Zweigbergk
f4499aa65e conflicts: fix bug when modifying modify/delete conflicts
Currently, if the user modifies a modify/delete conflict, we always
consider the result resolved. That happens because we materialize the
missing side of the conflict as an empty string but when we parse the
conflict, we expect only the number of sides in the input
conflict. For example, if the input is a regular modify/delete
conflict with one remove and one add, the materialized markers will
have one remove and two adds (one of them empty), but when we try to
parse it, we expect one remove and only one add. When we fail to parse
it, we consider it resolved.

This commit fixes the bug by using
`conflicts::Conflict<Option<TreeValue>>` and keeping track of which
sides were supposed to be empty. We could have fixed the bug without
switching to `conflicts::Conflict`, but we want to switch anyway, and
the fix happens naturally when switching.
2023-06-04 06:48:34 -07:00
Martin von Zweigbergk
1fdc25fe45 conflicts: replace backend::Conflict in materialize_conflict() 2023-06-04 06:48:34 -07:00
Martin von Zweigbergk
5733e3a442 conflicts: introduce generic type for conflicts
For support for tree-level conflicts (#1624), I'm probably going to
introduce a `MergedTree` type representing a set of trees to
merge. That will be similar to `Tree`, but instead of having values of
type `TreeValue`, it will have values that can represent a single
state or a conflict. The `TreeValue` type itself will eventually lose
its `Conflict` variant.

To prepare for that, this commit introduces a `Conflict<T>` type. That
type is intended to be close to what the future
`MergedTree::path_value()`, `MergedTree::entries()`, etc. The next few
commits will replace most current uses of `backend::Conflict` by this
new `conflicts::Conflict` type. They will use `Option<TreeValue>` as
type parameter. Unlike the current `backend::Conflict` type, the
explicit tracking of `None` values will let us better preserve the
ordering and tying it to the tree-level conflict's order.
2023-06-04 06:48:34 -07:00
Yuya Nishihara
78a64edb22 dag_walk: rename bfs() to dfs() because it's depth-first
No callers appear to rely on traversal order, so let's just fix the function
name. Maybe it was a typo.
2023-06-04 11:47:49 +09:00
Yuya Nishihara
d5d1dbcd3e dag_walk: reorder and adjust signature of neighbors_fn for consistency 2023-06-04 11:47:49 +09:00
Yuya Nishihara
a28e672633 dag_walk: unbox topo_order_reverse() callback 2023-06-04 11:47:49 +09:00
Yuya Nishihara
3ba544414c dag_walk: unbox bfs() callback, use iter::from_fn() to implement iterator
I just wanted to remove syntactic noise from callers. iter::from_fn() helps
to avoid declaring struct with lots of type parameters.
2023-06-04 11:47:49 +09:00
Yuya Nishihara
522308bb9c dag_walk: simply pass callback function by value 2023-06-04 11:47:49 +09:00
Yuya Nishihara
6872051270 tree_builder: populate base trees by recursion
Suppose many override entries share the same parent directories, it should
be cheaper to look up the tree_cache from leaf than root. I also think
recursion is easier to follow than for loop.
2023-06-02 12:23:37 +09:00
Yuya Nishihara
941f41e62e tree_builder: initialize base trees with the root entry
This helps to rewrite populate_trees() as recursive function call.
2023-06-02 12:23:37 +09:00
Yuya Nishihara
7cf96bcae0 tree_builder: ensure override file path never points to root tree 2023-06-02 12:23:37 +09:00
Yuya Nishihara
f475122b7e tree_builder: simply map Tree to backend::Tree in later pass
I'll rewrite populate_trees() as a recursive function, so I want to minimize
the objects to be passed to the function.
2023-06-02 12:23:37 +09:00
Yuya Nishihara
0846d7fc8b tree_builder: remove unneeded "mut" self 2023-06-02 12:23:37 +09:00
dependabot[bot]
59ee431467 cargo: bump criterion from 0.4.0 to 0.5.1
Bumps [criterion](https://github.com/bheisler/criterion.rs) from 0.4.0 to 0.5.1.
- [Changelog](https://github.com/bheisler/criterion.rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bheisler/criterion.rs/compare/0.4.0...0.5.1)

---
updated-dependencies:
- dependency-name: criterion
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-01 09:20:14 -07:00
Yuya Nishihara
3d449c55b7 tree_builder: do not omit file entry which was previously a directory 2023-06-01 09:38:06 +09:00
Yuya Nishihara
68a30c934d tree_builder: when writing trees, rely on lexicographical order of RepoPath 2023-06-01 09:38:06 +09:00
Yuya Nishihara
ae9f7aba52 tests: add test for file-directory-file transition
TreeBuilder fails to handle directory-file transition right now, and leaves
the dirty file as "clean".
2023-06-01 09:38:06 +09:00