Commit graph

4336 commits

Author SHA1 Message Date
Scott Taylor
643318086a diff_util: replace [T; 2] with Diff<T>
I think using `Diff<T>` for these makes the code more readable, since
using 2-element arrays gives a less clear meaning to the arguments.
2025-11-10 14:41:44 +00:00
Scott Taylor
da1921ead5 testutils: dump_tree: print contents of conflicted trees
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
Previously, `assert_tree_eq!` would give a confusing panic message if
one of the trees had a conflict.
2025-11-09 17:48:25 +00:00
Scott Taylor
5aa71d59a9 lib: replace MergedTreeId with MergedTree and Merge<TreeId>
After the previous commit, `MergedTree` and `MergedTreeId` are almost
identical, with the only difference being that `MergedTree` is attached
to a `Store` instance. `MergedTreeId` is also equivalent to
`Merge<TreeId>`, since it is just a wrapper around it.

In the future, `MergedTree` might contain additional metadata like
conflict labels. Therefore, I replaced `MergedTreeId` with `MergedTree`
wherever I think it would be required to pass this additional metadata,
or where the additional methods provided by `MergedTree` would be
useful. In any remaining places, I replaced it with `Merge<TreeId>`.

I also renamed some of the `tree_id()` methods to `tree_ids()` for
consistency, since now they return a merge of individual tree IDs
instead of a single "merged tree ID". Similarly, `MergedTree` no longer
has an `id()` method, since tree IDs won't fully identify a `MergedTree`
once it contains additional metadata.
2025-11-08 14:06:58 +00:00
Scott Taylor
79fc20e856 merged_tree: use Merge<TreeId> instead of Merge<Tree>
Currently, creating a `MergedTree` requires reading all of its root
trees from the store. However, this is often not actually required. For
instance, if the only reason to read the trees is to call
`MergedTree::merge`, and the merge is trivial, then there was no need to
read the trees. Changing `MergedTree` to only require a `Merge<TreeId>`
instead of a `Merge<Tree>` will make it possible to avoid reading trees
unnecessarily in these cases.

One benefit of this approach is that `Commit::tree` no longer requires
reading from the store, so it can be made synchronous and infallible,
which simplifies a lot of code.
2025-11-08 14:06:58 +00:00
Scott Taylor
71b1fd82f7 merged_tree: only accept trees from root directory
Since reading subtrees now returns `Merge<Tree>` instead of
`MergedTree`, we can require that `MergedTree` is only used at the root
directory. This will make the next commit simpler since it won't need to
keep track of directories.

This does complicate `jj debug tree`, since it previously relied on
`MergedTree` to iterate over the entries, but since it's only used for
debugging purposes, I think it's fine to make the code more complicated
if it makes `MergedTree` simpler.
2025-11-08 14:06:58 +00:00
Scott Taylor
6c441ca69f merged_tree: remove names() method
This method is unused, so it doesn't seem to be worth moving to
`Merge<Tree>`.
2025-11-08 14:06:58 +00:00
Scott Taylor
486f1d8129 merged_tree: move tree reading methods to Merge<Tree>
I'm planning to make `MergedTree` contain `Merge<TreeId>` instead of
`Merge<Tree>`, and these methods would all require reading a
`Merge<Tree>`, so I think it makes more sense to have them on
`Merge<Tree>` itself. Also, if `MergedTree` contains conflict labels or
other metadata in the future, it would be better to not have to clone
them each time a subtree is accessed.
2025-11-08 14:06:58 +00:00
Scott Taylor
f08e50a21f conflicts: add "diff-experimental" conflict marker style
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
#7917
2025-11-05 00:00:58 +00:00
Yuya Nishihara
96b746a73e matchers: use RegexSet to test matches of multiple glob patterns
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
The performance wouldn't matter here, but it seems better that we don't have to
deal with multiple regex patterns in match functions.

I also renamed "name" variable because it may consist of multiple path
components.
2025-11-04 13:25:20 +00:00
Yuya Nishihara
5348c753ed matchers: reorganize GlobsMatcher constructor as builder
Since non-trivial matcher objects should be constructed by FilesetExpression, we
won't need a convenient constructor function. It's easier to port Vec<Regex> to
RegexSet if the patterns Vec is owned by the builder.
2025-11-04 13:25:20 +00:00
Yuya Nishihara
f2df32b6fa matchers: extract parse_file_glob() test helper 2025-11-04 13:25:20 +00:00
Yuya Nishihara
e86cdadf0e matchers: rename FileGlobsMatcher to GlobsMatcher
I'm going to add "prefix" globs to enable globs by default #6971, and the
implementation will be quite similar to the current FileGlobsMatcher.
2025-11-04 13:25:20 +00:00
Yuya Nishihara
98f45ff294 matchers: rename test functions to be all in snake_case 2025-11-04 13:25:20 +00:00
Gabriel Goller
df1b452acf config: add hostname-based conditional config scopes
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
This enables configuration to be conditionally applied based on the
hostname set in `operation.hostname`. Users can now use
`--when.hostnames = ["host-a", "host-b"]` in their config files to apply
settings only on specific machines.

Fixes: #6441
2025-11-04 09:03:29 +00:00
Martin von Zweigbergk
b409aa3189 colocation: rename from "colocated repo" to "colocated workspace"
Colocation is about sharing the working copy between jj and git. It's
less important where the repo is stored. I therefore think we should
not call it "colocated repo". I considered renaming it to "colocated
working copy" but that sounded awkward in many places because we often
talk about the whole workspace (repo + working copy), so "In colocated
workspaces with a very large number of branches or other refs" sounds
better than "In colocated working copies with a very large number of
branches or other refs".

Once we support colocate workspaces in non-main Git worktrees, I think
this rename will be even more relevant because then all those
workspaces share the same repo but only some of them may be colocated.
2025-11-03 16:53:26 +00:00
Ilya Grigoriev
e921bfaa05 diff_util: move unified diff utils to jj-lib
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
2025-10-31 18:16:48 +00:00
Yuya Nishihara
53f18f3bb1 git: replace remaining users of is_special_git_remote()
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
We no longer need jj-lib functions.
2025-10-31 00:37:50 +00:00
Yuya Nishihara
d6b5530513 revset: do not ignore "git" remote if user pattern is specified
Since we can now express the default pattern as `remote=~exact:"git"`, we can
unblock queries matching the "git" remote.
2025-10-31 00:37:50 +00:00
Yuya Nishihara
626e5b29a6 revset: parameterize special "git" remote that is ignored by default
The default remote parameter of remote_bookmarks() will be derived from this
parameter. It doesn't make sense to exclude @git bookmarks if the backend isn't
Git. It's also nice that parsing tests don't depend on the feature flag.
2025-10-31 00:37:50 +00:00
Yuya Nishihara
f7256f611c revset: parse string patterns into StringExpression
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
A typical use case is to query bookmarked revisions ignoring auto-generated
bookmarks. `bookmarks() ~ bookmarks(x)` doesn't work because a revision may have
multiple bookmarks. It's also nice that we can document the default of
`remote_bookmarks()` as `remote_bookmarks(remote=~exact:"git")`.

Closes #7665
2025-10-29 23:59:58 +00:00
Yuya Nishihara
9d60816847 str_util: add AST type that represents compound string expressions
This type is akin to Revset/FilesetExpression. Unlike these, StringExpression
doesn't have Difference(x, y) node because Difference isn't any cheaper to
compute than Intersection.

Since string patterns are often parsed as revset symbols in CLI, there's no
native parser for the "string set expression".
2025-10-29 23:59:58 +00:00
Yuya Nishihara
8a65b1996c revset: migrate backend filtering to StringMatcher
For consistency reasons, queries like author(x) will also support compound
string expressions.
2025-10-29 11:19:42 +00:00
Yuya Nishihara
ace8ab6d46 view: migrate pattern.filter_btree_map*() to StringMatcher
I'll add support for filtering bookmarks and tags by compound string
expressions.
2025-10-29 11:19:42 +00:00
Yuya Nishihara
a00cde2172 str_util: add StringMatcher type that supports arbitrary predicates
This will be used in order to filter bookmarks by negative pattern for example.
Since "All" and "Exact" are common, they are specialized. The other patterns are
transformed to dyn Fn.

.filter_btree_map*() functions are duplicated from StringPattern. The old
functions will be removed soon.
2025-10-29 11:19:42 +00:00
Yuya Nishihara
843b45b7cb str_util: rename StringPattern::everything() to all()
I'm going to add AST type for compound string match expressions, and this type
will be similar to Revset/FilesetExpression which implement all().
2025-10-29 11:19:42 +00:00
Yuya Nishihara
1b22b9dc89 rewrite: avoid inserting comments between if/else keywords
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
Apparently, rustfmt gave up formatting the original code leaving excessive
indentation.
2025-10-28 15:02:57 +00:00
Brian Schroeder
8fcb46e56a index: make Index::common_ancestors fallible
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which may produce I/O errors during operation. See #7825 for more
information.

This introduces another instance of the existing anti-pattern, `TODO:
indexing error shouldn't be a "BackendError"`. We're tracking this known
issue in #7849.

Closes #7825.
2025-10-28 13:47:44 +00:00
Brian Schroeder
7810926c35 index: make Index::is_ancestor fallible
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which may produce I/O errors during operation. See #7825 for more
information.

- Introduced a few more instances of the existing anti-pattern, `TODO:
  indexing error shouldn't be a "BackendError"`. We're tracking this
  known issue in #7849.
- Converted `MutableRepo::merge_view` to return a `RepoLoaderError`
  instead of a `BackendError`. The only caller, `MutableRepo::merge`,
  already returns a `RepoLoaderError`.
- Added three "`fallible_`" iterator helpers to reduce the amount of
  noise at `is_ancestor` call sites due to the method now being
  fallible. Using these helpers seem to produce code that's a little
  more readable than using `process_results` from itertools. One
  consideration in this trade-off is that these helpers do not
  themselves return iterators: if we find that we need more support for
  fallible combinators mid-"chain" of iterator combinators, we might
  either want to use `process_results` only in those cases, or switch to
  use of `process_results` across the board (in lieu of these new
  helpers).
2025-10-28 13:47:44 +00:00
Scott Taylor
a16c89f16e conflicts: render exactly one snapshot in "diff" marker style
Although rare, it would be very confusing to a user if they encountered
a conflict with a `-------` marker while using the "diff" style. This
addresses a TODO in the test.
2025-10-28 12:43:08 +00:00
Ilya Grigoriev
5fc339abf5 debugging: comment on why impl Debug for jj_lib::Commit is not informative 2025-10-28 03:10:52 +00:00
Martin von Zweigbergk
9d81ad4ae3 cleanup: remove some unnecessary anonymous lifetime annotations
This change was motived by the next Gitoxide version adding an
additional lifetime to `gix::reference::iter::Iter`, which currently
breaks the automated Dependabot upgrade.

I left annonymous lifetime annotations on ref-like types like
`RemoteRefSymbol`.
2025-10-28 03:05:32 +00:00
Martin von Zweigbergk
7724f52d71 git_backend: reduce duplication of basename handling 2025-10-27 18:36:57 +00:00
Martin von Zweigbergk
a11c5eb4e4 predecessors: add option to not include them in commits
We want to eventually stop writing predecessors in the commit object
since we now have them in the operation object. That will expose some
problems with creating cycles between commits. This patch adds a
config option for not recording predecessors in commits so we can
start testing and fixing those issues.
2025-10-27 16:35:47 +00:00
Yuya Nishihara
ffdd6025ad dag_walk: avoid using unwrap() to strip off infallible error
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
We're now allowed to omit Err(_) if it can never be constructed.
2025-10-27 15:17:34 +00:00
Martin von Zweigbergk
b62438e398 repo: propagate error when there's a cycle in parent_mapping
We were sometimes seeing crashes at Google when a commit was rewritten
very quickly without any changes. This should prevent the crashes and
return an error to the user instead.
2025-10-27 14:16:34 +00:00
Martin von Zweigbergk
d8acbec3fc dag_walk: propagate error when cycle is detected
A sibling team of my team sometimes runs into panics caused by cycles
in the commit graph. This patch removes the panics from `dag_walk` by
having all the callers pass in a `cycle_fn`. For now, the callers
panic instead.
2025-10-27 14:16:34 +00:00
Brian Schroeder
b8fa9ecf9c index: make Index::has_id fallible
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which may produce I/O errors during operation. See #7825 for more
information.
2025-10-25 18:05:13 +00:00
Yuya Nishihara
5f40f62494 cleanup: remove redundant + use<'_> after migrating to 2024 edition
AliasFunctionOverloads::arities() doesn't need to capture &self, but it's not
important to describe the lifetime precisely here.
2025-10-25 02:09:31 +00:00
Brian Schroeder
159fb829d5 index: make Index::resolve_commit_id_prefix fallible
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which may produce I/O errors during operation. See #7825 for more
information.
2025-10-24 10:51:56 +00:00
Brian Schroeder
385fb064b9 index: make Index::shortest_unique_commit_id_prefix_len fallible
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which may produce I/O errors during operation. See #7825 for more
information.
2025-10-24 10:51:56 +00:00
Lander Brandt
61691755fe lib: optimize file handle usage when calling into same_file during
checkout

See https://github.com/jj-vcs/jj/pull/7695 for motivation/background

One of the hottest paths in `jj` during checkout is `can_create_file`
and `create_parent_dirs`. Both of these functions check to ensure that
there aren't attempts to write to special directories
(`reject_reserved_existing`) which is a fairly expensive check.

This change reduces file open/close syscalls by reusing file handles
when possible.
2025-10-24 00:42:00 +00:00
Brian Schroeder
37da011be8 index: make MutableRepo::merge_in fallible
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which may produce I/O errors during operation. See #7825 for more
information.
2025-10-23 20:52:16 +00:00
Brian Schroeder
c70f9b5b3f index: make ChangeIdIndex::shortest_unique_prefix_len fallible
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which can produce I/O errors during operation. See #7825 for more
information.
2025-10-23 15:28:33 +00:00
Brian Schroeder
5468bb49d3 index: make ChangeIdIndex::resolve_prefix fallible
This is part of a series of changes to make most methods on index traits
(i.e. `ChangeIdIndex`, `MutableIndex`, `ReadonlyIndex`, `Index`)
fallible. This will enable networked implementations of these traits,
which can produce I/O errors during operation. See #7825 for more
information.
2025-10-23 15:28:33 +00:00
Brian Schroeder
2d1acbec3b index: add IndexStoreResult type alias over IndexStoreError results
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
By introducing `IndexStoreResult`, we follow the pattern used by other
storage traits: `BackendResult`, `OpStoreResult`, and `IndexResult`.
2025-10-23 02:07:08 +00:00
Brian Schroeder
fc1639b1e1 index: add IndexResult type alias over IndexError results
By using a type alias, we match how `Backend` and `OpStore` traits
organize their errors. This will be useful as we progressively convert
more methods on `Index`, `MutableIndex`, `ReadonlyIndex`, and
`ChangeIdIndex` traits to return `Result<T, IndexError>` in order to
support networked implementations which can produce I/O failures.
2025-10-23 02:07:08 +00:00
Brian Schroeder
378e80cfff index: unify IndexStore errors into IndexStoreError enum
This way we match how the errors are organized for other storage traits.
2025-10-23 02:07:08 +00:00
Brian Schroeder
551e600405 index: unify Index errors into IndexError enum
This way we match how errors are organized for the other storage traits,
and we allow for networked implementations of `Index::all_heads_for_gc`
to return I/O errors.
2025-10-23 02:07:08 +00:00
Ilya Grigoriev
ca2b478a76 clippy: nightly clippy fixes (more Self)
Some checks are pending
binaries / Build binary artifacts (push) Waiting to run
website / prerelease-docs-build-deploy (ubuntu-24.04) (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
2025-10-21 02:00:14 +00:00
Martin von Zweigbergk
d39962416d revset: try to clarify error from exactly()
The error is currently something like "The revset was expected to have
1 elements, but more were provided". It wasn't at first clear what
"provided" was referring to. Of course it can only really refer to the
revset, but I think we say it more clearly as "The revset has more
than the expected 1 revisions". Note that I also changed "elements" to
"revisions" to clarify that the elements are revisions.
2025-10-20 22:56:32 +00:00