Commit graph

2677 commits

Author SHA1 Message Date
Yuya Nishihara
9c1d5d155e index: remove HRTB stuff by implementing RevWalkIndex for CompositeIndex 2024-03-11 17:24:10 +09:00
Yuya Nishihara
3d0952b316 index: implement AsCompositeIndex for CompositeIndex, not for &CompositeIndex
Just a minor code cleanup. We still need Index for &CompositeIndex because the
type is unsized, and unsized type cannot be converted to another dyn reference.
2024-03-11 17:24:10 +09:00
Yuya Nishihara
243675b793 index: turn CompositeIndex into transparent reference type
This helps to eliminate higher-ranked trait bounds from RevWalkRevset and
RevWalk combinators to be added. Since &CompositeIndex is now a real reference,
it can be passed to functions as index: &T.
2024-03-11 17:24:10 +09:00
Yuya Nishihara
c8be8c3edd index: add type alias for "dyn IndexSegment" to clarify it's 'static
This helps to migrate CompositeIndex<'_> wrapper to &CompositeIndex. If
the wrapped reference had a lifetimed field, it couldn't be represented as
a trivial reference type.
2024-03-11 17:24:10 +09:00
Yuya Nishihara
64e0be2477 revset: consolidate early-return condition of PositionsAccumulator
Since consume_to() checks the bottom position yielded from the source iterator,
it makes sense to add the same check for the cached positions.
2024-03-11 17:24:01 +09:00
Martin von Zweigbergk
4d42604913 git_backend: write trees involved in conflict in git commit header
We haven't used custom Git commit headers for two main reasons:

1. I don't want commits created by jj to be different from any other
   commits. I don't want Git projects to get annoyed by such commit
   and reject them.

2. I've been concerned that tools don't know how to handle such
   headers, perhaps even resulting in crashes.

The first argument doesn't apply to commits with conflicts because
such commits would never be accepted by a project whether or not they
use custom commit headers. The second argument is less relevant for
conflicted commits because most tools will be confused by such commits
anyway.

Storing conflict information in commit headers means that we can
transfer them via the regular Git wire protocol. We already include
the tree objects nested inside the root-level tree, so they will also
be transferred.

So, let's start by writing the information redundantly to the commit
header and to the existing storage. That way we can roll it back if we
realize there's a problem with using commit headers.
2024-03-10 20:51:05 -07:00
Aleksey Kuznetsov
cd3d75ebf6 revset: introduce more performant way to check if a commit is in a revset
Initially we were thinking to have `Revset` return something like
`CachedRevset`:

```
pub trait CachedRevset {
  fn iter(&self) -> Box<dyn Iterator<Item = Commit>>;
  fn contains(&self, &CommitId) -> bool;
}
```

But we weren't sure what use case for `iter` would be, so we dropped the `iter`
method. `CachedRevset` with single `contains` method needed a better name. We
weren't able to come up with one, so we decided instead to have a method on
`Revset` that returns a closure to check if a commit is in a revset.
2024-03-11 08:27:35 +05:00
Yuya Nishihara
8a406358af index: migrate RevWalkRevset to be based off new RevWalk trait
"for<'index> RevWalk<CompositeIndex<'index>, .." works as of now, but it won't
be composed well. So I'll turn CompositeIndex<'_> into &CompositeIndex in the
next batch, and remove "for<'index>".
2024-03-11 11:25:54 +09:00
Yuya Nishihara
4107cad80e index: migrate RevWalkDescendants to new RevWalk trait
Just for consistency. Descendants are always evaluated eagerly, so this change
isn't strictly needed.
2024-03-11 11:25:54 +09:00
Yuya Nishihara
b6cbd8b90b index: add trait and adaptor types to detach index from RevWalk*
This eliminates lifetimed fields from RevWalk objects, and the RevWalk object
will be embedded directly in RevWalkRevset.

This patch adds two separate iterator adapters. They are identical at this
point, but I'm going to add detach/reattach methods only to the borrowed
version. I'm also planning to change CompositeIndex<'_> to &CompositeIndex
to get around higher-ranked trait bound restrictions.
2024-03-11 11:25:54 +09:00
Yuya Nishihara
d780910bec index: make RevWalk yield IndexPosition instead of IndexEntry
This simplifies the RevWalkIndex API. It would probably add fractional msecs of
overhead per next() call, but I don't see significant difference in revset
benches.
2024-03-11 11:25:54 +09:00
Anton Älgmyr
099f06bf71 Add configuration options for node symbols in the graphs. 2024-03-09 21:16:58 +01:00
Yuya Nishihara
f51c5d7e57 index: consistently use IntoIterator in RevWalk builder API
Since the return type is no longer "impl Iterator<..>", there isn't lifetime
issue anymore.
2024-03-10 01:45:30 +09:00
Yuya Nishihara
2615fed5be index: handle cut-off position of RevWalk by queue
I'm going to make CompositeIndex<'_> detachable from the RevWalk, and
"F: Fn(CompositeIndex) -> Box<dyn Iterator<..>>" of RevWalkRevset<F> will
be replaced with "W: RevWalk<CompositeIndex>". This will simplify the code
structure, but also means that we can no longer apply .take_while() here and
convert it back to RevWalk. Fortunately, ancestors_until_roots() is the only
function I need to reimplement.
2024-03-10 01:45:30 +09:00
Yuya Nishihara
34fbaaaad6 index: construct RevWalk queue after item type is settled
It doesn't make sense to build BinaryHeap with intermediate type, and I'm
going to reimplement take_until_roots() in a way that the queue drops
uninteresting items.
2024-03-10 01:45:30 +09:00
Yuya Nishihara
8480ee9e05 index: migrate RevWalk constructors to builder API
The current RevWalk constructors insert intermediate items to BinaryHeap
and convert them as needed. This is redundant, and I'm going to add another
parameter that should be applied to the queue first. That's why I decided
to factor out a builder type. I considered adding a few set of factory
functions that receive all parameters, but they looked messy because most of
the parameters are of [IndexPosition] type.

This patch also adds must_use to the builder and its return types, which are
all iterator-like.
2024-03-10 01:45:30 +09:00
Yuya Nishihara
008adecf23 index: rename ancestors iterators from RevWalk* to RevWalkAncestors*
I'm planning to add RevWalk trait, and this patch frees up the name. It seems
also good for consistency as we have RevWalkDescendants*.
2024-03-10 01:45:30 +09:00
Yuya Nishihara
fa60026f25 repo_path: don't panic on invalid UTF-8 path component
Although watchman client appears to fail at decoding non-UTF-8 path (somewhere
in serde), jj shouldn't panic if watchman could deal with that.

The outer error message "path not in the repo" would sounds odd, but I think
that's okay because 1. it's unlikely that a user input is not UTF-8, and 2.
it's technically correct that a non-UTF-8 path is not contained in the repo.
2024-03-09 11:01:43 +09:00
Yuya Nishihara
a224d0f172 repo_path: show more detailed error if filesystem path failed to parse
This should address both use cases:
 1. If from_relative_path() is directly called, the error says ".." shouldn't
    be included in the (normalized) relative path.
 2. If parse_fs_path() is used, the error message contains paths relative to
    cwd. #3216
2024-03-09 11:01:43 +09:00
Yuya Nishihara
a76f716cd1 index: remove RevWalk newtypes that were necessary to hide impl types/traits
Some of the RevWalk methods could be generalized, but I decided to not try that
for now. I'll probably need to do more cleanup to (hopefully) remove 'index
lifetime from these types.
2024-03-08 10:07:40 +09:00
Yuya Nishihara
8451453f3a index: hide walk_revs() and related types
They are now implementation details of the default index backend.
2024-03-08 10:07:40 +09:00
Yuya Nishihara
f5eb172769 tests: remove last use of walk_revs() from integration tests 2024-03-08 10:07:40 +09:00
Martin von Zweigbergk
5ce5022ee9 cargo: mark the jj-lib-proc-macros crate for publish
I don't think we can publish a new version of the other crates without
publishing `jj-lib-proc-macros`.
2024-03-06 20:35:38 -08:00
Thomas Castiglione
d661f59f9d working_copy: implement symlinks on windows with a helper function
enables symlink tests on windows, ignoring failures due to disabled developer mode,
and updates windows.md
2024-03-05 15:16:38 +08:00
Austin Seipp
bd551099f0 cargo: update whoami dependency to 1.5.0
This requires a code tweak to avoid clippy failures, as `whoami` 1.5.0 has
deprecated the default `hostname()` function.

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-03-04 18:35:21 -06:00
Yuya Nishihara
c8023dbd8b signing: insert tracing events to command invocation paths
This might help debug command failure.
2024-03-05 09:23:15 +09:00
Yuya Nishihara
fa7864edeb signing: ensure child processes are wait()ed on I/O error
This will also provide a better error indication. If write() failed, the child
process would presumably have exited with non-zero status and error message to
stderr.
2024-03-05 09:23:15 +09:00
Evan Mesterhazy
a09ee4b9a3 Make URLs in docs hyperlinks
`cargo doc` complains that two URLs aren't actually links:

```
warning: this URL is not a hyperlink
  --> lib/src/fsmonitor.rs:66:6
   |
66 | /// (https://facebook.github.io/watchman/). Requires `watchman` to already be
   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://facebook.github.io/watchman/>`
   |
   = note: bare URLs are not automatically turned into clickable links
   = note: `#[warn(rustdoc::bare_urls)]` on by default

warning: `jj-lib` (lib doc) generated 1 warning (run `cargo fix --lib -p jj-lib` to apply 1 suggestion)
 Documenting jj-cli v0.14.0 (/Users/emesterhazy/oss/github.com/martinvonz/jj/cli)
 Documenting testutils v0.14.0 (/Users/emesterhazy/oss/github.com/martinvonz/jj/lib/testutils)
warning: this URL is not a hyperlink
    --> cli/src/cli_util.rs:2077:41
     |
2077 | /// To get started, see the tutorial at https://github.com/martinvonz/jj/blob/main/docs/tutorial.md.
     |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://github.com/martinvonz/jj/blob/main/docs/tutorial.md.>`
     |
     = note: bare URLs are not automatically turned into clickable links
     = note: `#[warn(rustdoc::bare_urls)]` on by default

warning: `jj-cli` (lib doc) generated 1 warning (run `cargo fix --lib -p jj-cli` to apply 1 suggestion)
```

This commit fixes the warnings by making the watchman URL a hyperlink and by
disabling the lint for the jj-cli error. Disabling the link is the right thing
to do because the comment is captured by clap and printed when `jj --help`
runs and any markdown formatting like `<>` is passed through.
2024-03-04 16:05:42 -05:00
Yuya Nishihara
24868e5192 gpg_signing: handle early termination of gpg command in verify path
Also fixes missing wait() on I/O error. We have the same problem in several
places. I'll fix them in another batch.
2024-03-03 18:35:10 +09:00
Yuya Nishihara
a0c31134ba gpg_signing: split run_command() into sign/verify variants 2024-03-03 18:35:10 +09:00
Yuya Nishihara
093f61607e gpg_signing: leverage Command builder API to eliminate type casting noises 2024-03-03 18:35:10 +09:00
Yuya Nishihara
dbe99c8fe0 gpg_signing: extract bottom half of run() to helper function
I'll split it further to fix EPIPE handling.
2024-03-03 18:35:10 +09:00
Evan Mesterhazy
ff4a5aa491 Store OpHeadsStore in UnpublishedOperation instead of RepoLoader
The only thing we need from the `RepoLoader` is the `OpHeadsStore`, so we can
extract it in UnpublishedOperation::new instead of keeping the entire
`RepoLoader` around.
2024-03-02 23:08:57 -05:00
Evan Mesterhazy
1439c902be Replace NewRepoData with ReadonlyRepo in the UnpublishedOperation struct
`NewRepoData` is just a container that holds data used to construct a
`ReadonlyRepo`. The `ReaonlyRepo` is always constructed before the
`UnpublishedOperation` is dropped, so we can simply construct the
`ReadonlyRepo` upfront and delete the `NewRepoData` type.
2024-03-02 23:08:57 -05:00
Evan Mesterhazy
c4cbf25545 Remove the std::Option around UnpublishedOperation::data
The Option is unnecessary now since `UnpublishedOperation` doesn't implement
the Drop trait (the `MustClose` member implements it instead).
2024-03-02 23:08:57 -05:00
Evan Mesterhazy
962b188b76 Replace custom Drop impl for UnpublishedOperation with #[must_use]
The custom Drop impl prevents us from moving members of UnpublishedOperation,
and is the reason why `NewRepoData` is wrapped in an `Option`. We don't use
custom Drop functions like this for debugging elsewhere in the codebase, and in
some ways #[must_use] provides better protection since it will typically cause
a compiler error if the UnpublishedOperation isn't used.
2024-03-02 23:08:57 -05:00
Evan Mesterhazy
6ee19589e9 Adjust visibility of codependent MutableRepo and CommitBuilder functions
MutableRepo and CommitBuilder both define public (now crate-public) functions
which should only be called by each other. This commit adds documentation and
restricts visibility of these functions to the jj_lib crate. It might be even
better to move CommitBuilder to the same module as MutableRepo so that these
codependent functions can be private to the module to avoid misuse.
2024-03-02 22:41:47 -05:00
Ilya Grigoriev
96bf190234 Nightly clippy fixes
There are a few additional warnings because of
https://github.com/rust-lang/rust-clippy/issues/12377, which is a
nightly-only bug that will hopefully be fixed.
2024-03-02 18:19:14 -08:00
Evan Mesterhazy
2f7b15b7b1 Add documentation comments for operation, transaction, and view types 2024-03-02 15:35:41 -05:00
Evan Mesterhazy
a335321c45 Add documentation comments for several types
These comments are intended to make it easier for new developers to get up to
speed with the project. This is just a starting point... there are other types
and functions that could benefit from documentation.
2024-03-02 15:01:55 -05:00
Evan Mesterhazy
b8aa9a1a2b Make a minor simplification to CommitBuilder::write
There's no need to have a block of code at the beginning of the function to
cache the rewrite source id. We can simply check the necessary condition before
calling record_rewritten_commit.

This tweak makes the function a little easier to read since we don't check the
condition until we're ready to do the work.
2024-03-02 13:40:18 -05:00
Evan Mesterhazy
276276ea01 Reorder functions in impl Repo for MutableRepo to match trait
This is just a clean-up to silence a lint that complains that the functions are
defined in a different order than they are in the trait.
2024-03-02 13:40:04 -05:00
Yuya Nishihara
5df7a42915 merge_tools: move "ui.diff-instructions" to CLI and config/misc.toml
There are no users of this option in jj-lib. Let's simplify it.
2024-03-02 23:33:45 +09:00
Evan Mesterhazy
5c252bd8e4 Add test cases where HexPrefix::new fails due to invalid inputs 2024-03-01 10:00:22 -05:00
Yuya Nishihara
4c16c05be1 cli: move --git-repo path normalization back from workspace
This reverts dc074363d1 "no-op: Move external git repo canonicalization into
Workspace::init_git_external." As I said in the PR comment, appending ".git"
is normalization of the user input, which is IMHO more appropriate to be done
in the CLI layer.
2024-02-28 09:03:16 +09:00
Evan Mesterhazy
a28beb5b8f Allow id_type! to capture doc comments
This allows us to define documentation comments for types implemented using the
id_type! macro. Comments defined above the type inside the macro will be
captured and visible in generated docs.

Example:

```
id_type!(
    /// Stable identifier for a [`Commit`]. Unlike the `CommitId`, the `ChangeId`
    /// follows the commit and is not updated when the commit is rewritten.
    pub ChangeId
);
```

This commit also adds documentation for the `CommitId` and `ChangeId` types
defined using the `id_type!` macro.
2024-02-27 10:37:05 -05:00
Yuya Nishihara
ef9d22887c tests: disable gpg unknown_key() test on Windows as well
Follows up 7552f939c6 "tests: disable most gpg integration tests on Windows."
I couldn't find this test failing in a few samples before, but it does now.
2024-02-27 00:55:06 +09:00
Martin von Zweigbergk
1cbf2b4acf rewrite: allow working-copy to be abandoned
This removes the special handling of the working-copy commit. By
recording when an empty/emptied commit was abanoned, we rebase
descendants correctly and create a new empty working-copy commit on
top.
2024-02-25 16:39:05 -08:00
Martin von Zweigbergk
3bc3a63411 rewrite: move decision about abandoned commit into update_references() 2024-02-25 16:39:05 -08:00
Yuya Nishihara
7552f939c6 tests: disable most gpg integration tests on Windows
These tests often stuck on Windows CI for unknown reasons. Let's mark them
ignored for the moment. The unknown_key test is allowed because it somehow
appears to pass.

https://github.com/martinvonz/jj/actions/runs/8009950119/job/21879789008?pr=3123#step:7:1487

#3140
2024-02-25 17:07:05 +09:00