Commit graph

3306 commits

Author SHA1 Message Date
Yuya Nishihara
e24fe817c9 tests: invoke .walk_revs() through CompositeIndex
Prepares for removal of the index trait method.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
6ba684a395 index: replace use of walk_revs() with revset API
I've added a helper function because the construction of the range expression
is a bit noisy. It could be a Repo method, but I don't want to make it a
default implementation of the trait method.

revset::walk_revs() let the caller handle RevsetEvaluationError since the
evaluation engine may error out even with such a trivial query. For now, most
callers just .unwrap() the error as before.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
0b2f0eca05 revset: add Revset::count() API
The default-engine implementation is pretty much the same as iter().count(),
but custom engine may have an optimal path.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
5b568cabcc revset: add iterator of (CommitId, ChangeId) pairs, use it in id_index
There are a few more places where we need these pairs.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
4d39fdf614 id_prefix: remove redundant CommidId field from disambiguation index 2023-05-24 01:02:37 +09:00
Yuya Nishihara
44927be7c9 id_prefix: add IdIndex method that looks up unambiguous key
resolve_prefix_with() is changed to return both key and values.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
e93ff5815c id_prefix: rename IdIndex::resolve_prefix() to resolve_prefix_to_values()
I'll add a key resolution method.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
e7f83e7681 index: add PrefixResolution::map() helper
I'm going to make IdIndex::resolve_prefix_with() return (key, values) pair,
and add convenient wrappers that .map() the pair to either key or values.
2023-05-24 01:02:37 +09:00
Yuya Nishihara
d6f1ab697a cli: load revset/template aliases in order of config layers
Since we abuse TOML table syntax to define function aliases, an identical
function alias can be found more than once in the merged config. The merged
config doesn't preserve the definition order, so we need to load aliases
table per layer.
2023-05-23 14:20:55 +09:00
Yuya Nishihara
97e2ee2868 cli: pass CommandHelper reference to WorkspaceCommandHelper constructor
I'll need to access LayeredConfigs there, and I don't think external callers
would want to specify each argument separately.
2023-05-23 14:20:55 +09:00
Martin von Zweigbergk
f1e2849c23 cli: add some documentation for jj sparse, including examples 2023-05-22 09:49:38 -07:00
Martin von Zweigbergk
b6691a1d23 cli: make jj sparse --list a subcommand
`jj sparse` is a bit different from other commands in that its `jj
sparse --list` is practically a separate command. Let's make it an
actual subcommand for consistency, and so we can more cleanly add
additional flags for `jj sparse list` in the future. I moved all the
other arguments to `jj sparse set`. I'm not sure if `jj sparse set
--reset` would have been better as `jj sparse reset`, but it is
technically just updating the sparse patterns just like the other
arguments (`--clear`, `--add` , `--remove`).
2023-05-22 09:49:38 -07:00
dependabot[bot]
3575c1f499 cargo: bump digest from 0.10.6 to 0.10.7
Bumps [digest](https://github.com/RustCrypto/traits) from 0.10.6 to 0.10.7.
- [Commits](https://github.com/RustCrypto/traits/compare/digest-v0.10.6...digest-v0.10.7)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-22 16:16:04 +00:00
dependabot[bot]
d8d8fcff2f cargo: bump clap_complete from 4.2.3 to 4.3.0
Bumps [clap_complete](https://github.com/clap-rs/clap) from 4.2.3 to 4.3.0.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.2.3...clap_complete-v4.3.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-22 16:13:55 +00:00
Martin von Zweigbergk
6a9b527987 tests: test lookup of prefixes from the log output just about
It's easier to follow the test if we try to resolve commits from the
`jj log` output just above. That's what we did until I changed it away
from that without thinking in fcda05c69b.
2023-05-22 07:02:32 -07:00
Martin von Zweigbergk
5d2872d76f tests: restore effectiveness of prefix among hidden commits
When I added `revsets.short-prefixes` in 20ef171d7a, I didn't notice
that I made the test of commit prefixes among hidden commits
ineffective because. This restores that by disabling short prefixes in
the test.
2023-05-22 07:02:32 -07:00
Martin von Zweigbergk
a72898000f tests: avoid hardcoding commit/operation ids when possible
Hardcoded ids cannot be updated with `insta`.
2023-05-22 07:02:32 -07:00
Martin von Zweigbergk
0e18757610 tests: include description in test_git_colocated log template
I think this makes the tests a little clearer.
2023-05-22 07:02:32 -07:00
Yuya Nishihara
c23f1e4161 cli: reload both repo and wc commit if working copy was updated
Otherwise, working-copy snapshot would be taken against wrong parent, which
would cause divergence if the history was previously rewritten.

Fixes #1608
2023-05-22 08:36:38 +09:00
Yuya Nishihara
ed60ddcdcc cli: move code that reloads repo to working-copy operation
Reloading repo also means the working-copy commit can change, so the caller
needs to do more things than repo.reload_at().
2023-05-22 08:36:38 +09:00
Yuya Nishihara
1675aec388 git: handle lock error that could occur while adding GC-preventing refs
If I spawned ~20 "jj status &" processes, some of them panicked there.
Spotted when debugging #924.
2023-05-22 08:36:29 +09:00
Yuya Nishihara
b01614bbdd cleanup: leverage scoped thread in tests 2023-05-21 21:02:58 +09:00
Yuya Nishihara
38a7e7fd62 git_backend: on read_commit(), bulk-update extra metadata table of ancestors
Otherwise, "jj init --git-repo ." would create extra table files per commit,
and merge them.

I considered adding an explicit GitBackend method to be called from
git::import_refs(), but the call order matters. The method should be invoked
before calling store.get_commit(..) or mut_repo.add_head(..). Since commits
are likely to be loaded from the head, we can instead make read_commit()
import ancestor metadata at all.

Alternatively, we could make a Git commit hidden until it's inserted into
the extra table. It's rather big change, and I wouldn't like to do that
without thinking more thoroughly.
2023-05-21 08:29:00 +09:00
Yuya Nishihara
fe97dccd02 git_backend: move add_entry() of extra metadata table to caller
I'm going to add a caller which will insert multiple entries at once.
2023-05-21 08:29:00 +09:00
Yuya Nishihara
e6addf7905 git_backend: extract helper that converts git2::Commit to backend::Commit
The root parent id is filled by caller because empty parents list is more
convenient while walking ancestors.
2023-05-21 08:29:00 +09:00
Yuya Nishihara
0149e7b311 git_backend: generate change id from git2::Commit object
I'm going to extract a helper function that converts git2::Commit to
backend::Commit struct, and the commit id can also be obtained from the
git2::Commit object.
2023-05-21 08:29:00 +09:00
Yuya Nishihara
5dba0502cb git_backend: cache head of saved extra metadata table
Just because we know the latest table head.
2023-05-21 08:29:00 +09:00
Yuya Nishihara
a9422460cb git_backend: ensure change id generated from git commit id never reassigned
Fixes #924
2023-05-20 15:53:23 +09:00
Yuya Nishihara
9aa72f6f1d git_backend: add lock to prevent racy change id assignments
My first attempt was to fix up corrupted index when merging, but it turned
out to be not easy because the self side may contain corrupted data. It's
also possible that two concurrent commit operations have exactly the same
view state (because change id isn't hashed into commit id), and only the
table heads diverge.

#924
2023-05-20 15:53:23 +09:00
Yuya Nishihara
e224044dea git_backend: consistently use CommitId type to look up extra metadata table 2023-05-20 15:53:23 +09:00
Yuya Nishihara
78c8dbc8fe git_backend: extract helper to add extra metadata entry and save table 2023-05-20 15:53:23 +09:00
Yuya Nishihara
8a0fcfb032 git_backend: leverage read_extra_metadata_table() in write_commit()
And use the readonly table for lookup, which allows us to extract a helper
method to add/save entry.
2023-05-20 15:53:23 +09:00
Yuya Nishihara
14243a85a0 git_backend: extract helper to read extra metadata table and maintain cache 2023-05-20 15:53:23 +09:00
Yuya Nishihara
83753e59f6 stacked_table: extract method that resolves head without releasing lock
GitBackend will reuse this lock to not assign multiple change ids to a
single commit. We could add a separate lock file that covers the section
from get_head() to save_table(), but I think reusing the table lock is good
enough.
2023-05-20 15:53:23 +09:00
Yuya Nishihara
3655da4f01 tests: add tests for concurrent git commit/change id assignment
Since non-Git metadata isn't hashed, we can't rely on the consistency
provided by content-addressed storage. The problem is also described in
https://github.com/martinvonz/jj/issues/3#issuecomment-947998487

#924
2023-05-20 15:53:23 +09:00
dependabot[bot]
38bac08f25 cargo: bump toml_edit from 0.19.8 to 0.19.9
Bumps [toml_edit](https://github.com/toml-rs/toml) from 0.19.8 to 0.19.9.
- [Commits](https://github.com/toml-rs/toml/compare/v0.19.8...v0.19.9)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-18 09:21:08 -07:00
Yuya Nishihara
b8e0ba9872 stacked_table: do not remove head on empty save_table()
If the head is unchanged, it shouldn't be removed. Otherwise the next reader
wouldn't find the existing table.
2023-05-18 22:55:26 +09:00
Ilya Grigoriev
db8fcf933a export_refs: add or edit some comments (no-op)
This is supposed to make `export_refs` a little more readable.
2023-05-17 17:57:58 -07:00
Ilya Grigoriev
344b3bfa59 import_refs/export_refs: refactor conversion from branch names to refs (no-op)
This is supposed to make `import_refs` and `export_refs` a little less prone to typos
2023-05-17 17:57:58 -07:00
Ilya Grigoriev
714aff63e6 git.rs: properly abandon commits from moved/deleted branches on remote (#864)
This bug concerns the way `import_refs` that gets called by `fetch` computes
the heads that should be visible after the import.

Previously, the list of such heads was computed *before* local branches were
updated based on changes to the remote branches. So, commits that should have
been abandoned based on this update of the local branches weren't properly
abandoned.

Now, `import_refs` tracks the heads that need to be visible because of some ref
in a mapping keyed by the ref. If the ref moves or is deleted, the
corresponding heads are updated.

Fixes #864
2023-05-17 17:57:58 -07:00
Ilya Grigoriev
cf4a603eb4 Tests demonstrating a similar bug with moved rather than deleted branch 2023-05-17 17:57:58 -07:00
Ilya Grigoriev
a0ee2b0dbd lib/tests/test_git.rs: New test to demonstrate #864's root cause 2023-05-17 17:57:58 -07:00
Ilya Grigoriev
bda3d3e50b test_import_refs_reimport: very minor improvement to a test 2023-05-17 17:57:58 -07:00
Ilya Grigoriev
07e7b82a0d import_refs/export_refs: rename some local variables (no-op)
This is supposed to make `import_refs` and `export_refs` a little more
readable.
2023-05-17 17:57:58 -07:00
Martin von Zweigbergk
e3beb82d5f docs: add architecture doc 2023-05-16 11:09:20 -07:00
Ilya Grigoriev
7c24e7bfe7 jj debug operation: Create a debug view alias, arguments that determine what to show 2023-05-14 19:59:50 -07:00
Ilya Grigoriev
d654a9e163 TestEnvironment: make it easier to run integration tests with printf debugging
Before this, it was difficult to run an integration test after adding any
directives from printf-style debugging to jj (e.g. `err!`, `eprintln!`,
`println!`), since `jj_cmd_success` fails if `jj` to output anything to stderr
while `jj_cmd_failure` fails if stdout is not empty.

This adds a `TestEnvironment::debug_allow_stderr` variable that lifts this
restriction for `jj_cmd_success` and makes it output anything `jj` output to
stderr instead. You can set it directly or by running the test with the
`DEBUG_ALLOW_STDERR` environment variable set. You can then add `err!`
anywhere.

You do need to run the test in a somewhat special way, as described in the
docstring.
2023-05-14 19:59:50 -07:00
Martin von Zweigbergk
87a925d736 git_backend: return timestamps for what was actually written
Now that we return the written commit from `write_commit()`, let's
make the timestamps match what was actually written, accounting for
the whole-second precision and the adjustment we do to avoid
collisions.
2023-05-12 15:20:44 -07:00
Martin von Zweigbergk
a95188ddbc backend: take commit to write by value and return new value
The internal backend at Google doesn't let you write any value you
want for in the committer field. The `Store` type still caches the
value it attempted to write, which gets a little weird when the
written value is not what we tried to write. We should use the value
the backend actually wrote. However, we don't know if the backend
changed anything without reading the value back, which is often
wasteful. This commit changes the API to return the written value.

I only changed the signature of `write_commit()` for now. Maybe we
should make a similar change to `write_tree()`.
2023-05-12 15:20:44 -07:00
dependabot[bot]
f412bd5bdd cargo: bump clap_complete from 4.2.2 to 4.2.3
Bumps [clap_complete](https://github.com/clap-rs/clap) from 4.2.2 to 4.2.3.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.2.2...clap_complete-v4.2.3)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-12 16:12:08 +00:00