Commit graph

6612 commits

Author SHA1 Message Date
Yuya Nishihara
da221eb888 repo: load index eagerly to simplify error handling
If readonly_index() and index() returned Result, it would propagate to many
call sites. That seems bad for API ergonomics. Suppose most "repo" commands
depend on an index, I think it's okay to load index eagerly:

 - "jj config" doesn't load repo (nor index)
 - "jj workspace root" doesn't load repo (nor index)
 - some other mutation commands load index when printing commit summary
 - many other commands load index when resolving revset
2024-07-23 18:26:16 +09:00
Yuya Nishihara
626aa90610 repo: use DetachedCommitBuilder constructors
I think this makes it clear that the builder doesn't add any rewrite records
to the mut_repo.
2024-07-23 18:22:40 +09:00
Yuya Nishihara
337dcef6ee commit_builder: add public interface that writes temporary commit to store
In order to render description template, we'll need a Commit object that
represents the old state (with new tree and parents) before updating the
commit description. The added functions will help generate an intermediate
Commit object.

Alternatively, we can create an in-memory Commit object with some fake
CommitId. It should be lightweight, but might cause weird issue because the
fake id wouldn't be found in the store.

I think it's okay to write a temporary commit and rely on GC as we do for
merge trees. However, I should note that temporary commits are more likely to
be preserved as they are pinned by no-gc refs until "jj util gc".
2024-07-23 18:22:40 +09:00
Yuya Nishihara
b4bf1358a5 commit_builder: extract inner builder which isn't lifetimed by mut_repo
This allows us to construct a builder, format description template with an
intermediate commit, then write() a final commit object to the repo.

I originally considered removing mut_repo from CommitBuilder at all, but
rewriter APIs rely on that CommitBuilder has &mut_repo, and splitting them
would make call sites uglier.

The inner builder methods are based on &mut Self instead of Self, because it's
easier to wrap, and users of the inner builder will bind it to a named variable
anyway.
2024-07-23 18:22:40 +09:00
Yuya Nishihara
6516a40c19 commit_builder: extract free function that sets up signing and write commit
I'll add another write() method that doesn't consume self, which will have to
clone self.commit.
2024-07-23 18:22:40 +09:00
Yuya Nishihara
fab310f53f commit_builder: keep Store internally
I'm going to extract an inner builder that is free from &mut MutableRepo
lifetime.
2024-07-23 18:22:40 +09:00
Yuya Nishihara
49d92a0480 commit_builder: remove redundant boxing from signing fn closure 2024-07-23 18:22:40 +09:00
Yuya Nishihara
209e076bfc commit_builder: use .clone_from() to silence nightly clippy warning
It's not wrong that String::clone_from() could potentially be cheaper.
2024-07-23 18:22:40 +09:00
Julien Vincent
feceb622f1 Add hunk.nvim to list of community tools 2024-07-22 15:29:54 -06:00
dependabot[bot]
005c04e7bb cargo: bump syn from 2.0.71 to 2.0.72 in the cargo-dependencies group
Bumps the cargo-dependencies group with 1 update: [syn](https://github.com/dtolnay/syn).


Updates `syn` from 2.0.71 to 2.0.72
- [Release notes](https://github.com/dtolnay/syn/releases)
- [Commits](https://github.com/dtolnay/syn/compare/2.0.71...2.0.72)

---
updated-dependencies:
- dependency-name: syn
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-22 19:01:55 +02:00
Benjamin Tan
dade156859 cli: add jj operation show command 2024-07-22 19:16:42 +08:00
Benjamin Tan
a6d82cc344 cli: add jj operation diff command 2024-07-22 19:16:42 +08:00
Benjamin Tan
58a813cb18 repo: add RepoLoader::merge_operations 2024-07-22 19:16:42 +08:00
Benjamin Tan
87ea9102f0 repo: add MutableRepo::merge_index 2024-07-22 19:16:42 +08:00
Yuya Nishihara
ddc601fbf9 str_util: add regex pattern
This patch adds minimal support for the regex pattern. We might have to add
"regex-i:" for completeness, but it can be achieved by "regex:'(?i)..'".
2024-07-22 12:00:52 +09:00
Yuya Nishihara
845793a7ad str_util: remove Eq + PartialEq from StringPattern
I'm going to add regex support, and compiled Regex object isn't comparable.
2024-07-22 12:00:52 +09:00
Yuya Nishihara
5783631271 tests: use assert_matches!() to compare StringPattern 2024-07-22 12:00:52 +09:00
Scott Taylor
14d3bb85bc workspace: use cwd for printing relative path
The user probably would expect the path to be relative to their current
directory rather than the workspace root. For instance, if the user is
in a child directory and runs `jj workspace add ../../name`, then they
might be surprised if we printed "../name" instead of "../../name".
2024-07-21 14:26:18 -05:00
Yuya Nishihara
8df7857706 cli_util: add tx.commit_summary_template() and related helper functions
These functions mirror the ones in WorkspaceCommandHelper. I'm not sure if all
of them will have to be public, but parse_commit_template() might be useful in
order to implement description template.
2024-07-20 09:08:59 +09:00
Yuya Nishihara
b762dd55cd cli_util: cache IdPrefixContext by transaction wrapper
This addresses lifetime issue in the next patch, in which the context has to
be borrowed from a known location.
2024-07-20 09:08:59 +09:00
Yuya Nishihara
9d5eda107d commit_builder: inline mut_repo.write_commit()
As the doc comment says, it's called only from CommitBuilder. Let's clarify
that. I'm also planning to extract a builder that only writes to the store
(without mutably borrowing a mut_repo.) It will help implement description
template.
2024-07-20 09:06:46 +09:00
Vincent Ging Ho Yim
2e3b4b5fe3 docs: add copy tracking design doc to MkDocs
Missed in #3574.
2024-07-19 22:00:09 +02:00
dependabot[bot]
491ec3d3eb github: bump github/codeql-action in the github-dependencies group
Bumps the github-dependencies group with 1 update: [github/codeql-action](https://github.com/github/codeql-action).


Updates `github/codeql-action` from 3.25.12 to 3.25.13
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](4fa2a79536...2d790406f5)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: github-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-19 19:45:21 +02:00
Ilya Grigoriev
e2f12d91cc conflicts: switch to multi-line regex, fix minor bug
The multi-line regex will be used for other purposes soon.
2024-07-18 18:42:40 -07:00
Ilya Grigoriev
d095570718 conflicts: demo minor bug 2024-07-18 18:42:40 -07:00
Ilya Grigoriev
f3de66e603 conflicts: demo failure to materialize if conflicts don't end in a newline
#3968
2024-07-18 18:42:40 -07:00
Scott Taylor
d5c526f496 branch: ignore git tracking branches for rename warning
Prevents a warning from being printed when renaming branches in a
colocated repo, since git tracking branches were being considered as
remote tracking branches.
2024-07-18 17:27:19 -05:00
dependabot[bot]
94f5a20cb7 cargo: bump thiserror in the cargo-dependencies group
Bumps the cargo-dependencies group with 1 update: [thiserror](https://github.com/dtolnay/thiserror).


Updates `thiserror` from 1.0.62 to 1.0.63
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/1.0.62...1.0.63)

---
updated-dependencies:
- dependency-name: thiserror
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-18 18:25:28 +02:00
dependabot[bot]
0572bde762 cargo: bump gix-path from 0.10.8 to 0.10.9
Bumps [gix-path](https://github.com/Byron/gitoxide) from 0.10.8 to 0.10.9.
- [Release notes](https://github.com/Byron/gitoxide/releases)
- [Changelog](https://github.com/Byron/gitoxide/blob/main/CHANGELOG.md)
- [Commits](https://github.com/Byron/gitoxide/compare/gix-path-v0.10.8...gix-path-v0.10.9)

---
updated-dependencies:
- dependency-name: gix-path
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-18 18:25:09 +02:00
Matt Kulukundis
6ffe05290d copy-tracking: move unit tests into backend specific file 2024-07-18 05:44:56 -04:00
Yuya Nishihara
5649ee4f45 fileset: parse glob characters as identifier
It's inconvenient that we have to quote glob patterns as 'glob:"*.rs"'. Suppose
filesets are usually specified in shell, it's better to allow unquoted strings
if possible. This change also means we'll probably abandon #2101 "make the
parsing of string arguments stricter."

Note that we can no longer introduce ? operator or [] subscript syntax in
filesets.

Closes #4053
2024-07-18 13:49:10 +09:00
Ilya Grigoriev
ff0188d63a cli branch create/set: add --to aliases for -r
Now that `jj move` does not accept `-r` (since it has `--from` and `--to`), `jj set --to` seems more useful
than `jj set -r`. `create --to` is also added for ease of switching
between `branch create` and `branch move`.
2024-07-17 21:21:40 -07:00
Yuya Nishihara
1a387489d9 files: relax requirement of merge() inputs
Most callers have Merge<ContentHunk> or Merge<Vec<u8>>.
2024-07-18 11:34:43 +09:00
Yuya Nishihara
e5b49c7d52 files: extract pre-processing part from merge()
I'll make the first half generic over T: AsRef<[u8]>.
2024-07-18 11:34:43 +09:00
dependabot[bot]
5a58030b69 cargo: bump tokio from 1.38.0 to 1.38.1 in the cargo-dependencies group
Bumps the cargo-dependencies group with 1 update: [tokio](https://github.com/tokio-rs/tokio).


Updates `tokio` from 1.38.0 to 1.38.1
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.38.0...tokio-1.38.1)

---
updated-dependencies:
- dependency-name: tokio
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-18 01:01:50 +09:00
Yuya Nishihara
895eead4b8 revset: add diff_contains(text[, files]) to search diffs
The text pattern is applied prior to comparison as we do in Mercurial. This
might affect hunk selection, but is much faster than computing diff of full
file contents. For example, the following hunk wouldn't be caught by
diff_contains("a") because the line "b\n" is filtered out:

    - a
      b
    + a

Closes #2933
2024-07-18 01:01:16 +09:00
Yuya Nishihara
eabff4c0b4 revset: propagate BackendError from inner file() predicate function
We should probably add error propagation path to Revset iterator, and predicate
functions will return Result<bool, RevsetEvaluationError>.
2024-07-18 01:01:16 +09:00
Yuya Nishihara
a6a67fa8fd revset: pass Commit object to inner file() predicate function
Commit object extraction is common across predicate functions.
2024-07-18 01:01:16 +09:00
Yuya Nishihara
a9af8d21f8 diff: move materialized_diff_stream() to jj_lib::conflicts module
New diff_contains() revset function will use this helper.
2024-07-18 01:01:16 +09:00
Vladimír Čunát
0c8f881fcd docs/git-comparison.md: update the Signed_commits bullet 2024-07-17 17:12:34 +02:00
Austin Seipp
6c54b66fac cargo: build with crt-static on windows
Avoids a runtime dependency on vcruntime140.dll

Signed-off-by: Austin Seipp <aseipp@pobox.com>
2024-07-17 07:40:30 -05:00
Martin von Zweigbergk
f2bfb90c8c cli: remove unused dependency on gix-filter
This dependency was added in 067d37aa but it seems it ended up being
used only from the jj-lib crate.
2024-07-17 11:53:51 +02:00
Yuya Nishihara
d1912bf016 templater: add commit.diff().<format>() methods
This patch adds TreeDiff template type to host formatting options. The main
reason of this API design is that diff formats have various incompatible
parameters, so a single .diff(files, format[, options..]) method would become
messy pretty quickly. Another reason is that we can probably add custom
summary templating support as diff.files().map(|file| file.path()..).

RepoPathUiConverter is passed to templater explicitly because the one stored
in RevsetParseContext is behind Option<_>.
2024-07-17 18:52:49 +09:00
Yuya Nishihara
4a63a1f660 diff: pass repo.store() to inner show_*_diff() functions, reorder arguments
This will help remove lifetimed &dyn Repo from diff object in templater.

Function arguments are reordered in a way that all show_*() functions have
common parameters in the same order.
2024-07-17 18:52:49 +09:00
Yuya Nishihara
18d60ad0d3 cli: use lossy string conversion to accept non-UTF-8 template outputs
I'm going to add diff() method which provides no guarantee about content
encoding.
2024-07-17 18:52:49 +09:00
Vincent Ging Ho Yim
79b326d56b cli_util: add missing word in conflict resolution instructions 2024-07-17 08:10:25 +02:00
Matt Kulukundis
3043b83a8f copy-tracking: add get_copy_records to Store 2024-07-16 13:18:49 -04:00
Anton Älgmyr
c7eac90200 Enable the new graph nodes by default.
It's been tested in various places now, so this is probably mature
enough to be the default.
2024-07-16 12:54:24 +02:00
Yuya Nishihara
a757fddcf1 revset: parse file() argument as fileset expression
Since fileset and revset languages are syntactically close, we can reparse
revset expression as a fileset. This might sound a bit scary, but helps
eliminate nested quoting like file("~glob:'*.rs'"). One oddity exists in alias
substitution, though. Another possible problem is that we'll need to add fake
operator parsing rules if we introduce incompatibility in fileset, or want to
embed revset expressions in a fileset.

Since "file(x, y)" is equivalent to "file(x|y)", the former will be deprecated.
I'll probably add a mechanism to collect warnings during parsing.
2024-07-16 10:18:57 +09:00
Yuya Nishihara
c74cf2d80d revset: use .ok_or_else() to handle missing workspace context
FWIW, this might be changed to non-error so that "file()" revset can be used
at server side.
2024-07-16 10:18:57 +09:00