Commit graph

3275 commits

Author SHA1 Message Date
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
Martin von Zweigbergk
e7419e76a1 backend: replace git_repo() by as_any()
This has several advantages:

 * Makes it possible to downcast to non-Git custom backends (might be
   useful at Google, but we haven't needed it yet)

 * Lets us access more specific functionality on the `GitBackend`,
   making it possible to access the `git2::Repository` without
   creating a copy of it.

 * Removes the dependency on Git from the backend
2023-05-12 08:05:09 -07:00
Yuya Nishihara
8d56b199bc revset: initialize with default prefix resolver
Since repo is passed as argument, we can define the default resolver as
a plain function.
2023-05-12 21:31:29 +09:00
Yuya Nishihara
f58beca760 revset: move resolve_symbol() to tests
It's no longer used in library code.
2023-05-12 21:31:29 +09:00
Martin von Zweigbergk
916b00c33e id_prefix: remove repo field from IdPrefixContext
By passing the repo as argument to the methods instead, we can remove
the `repo` field and the associated lifetime. Thanks to Yuya for the
suggestion.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
eab5218fe5 cli: allow resolving shorter ids within a configured revset
This adds a config called `revsets.short-prefixes`, which lets the
user specify a revset in which to disambiguate otherwise ambiguous
change/commit ids. It defaults to the value of `revsets.log`.


I made it so you can disable the feature by setting
`revsets.short-prefixes = ""`. I don't like that the default value
(using `revsets.log`) cannot be configured explicitly by the
user. That will be addressed if we decide to merge the `[revsets]` and
`[revset-aliases]` sections some day.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
6a4502cb5d prefixes: allow resolving shorter ids within a revset
In large repos, the unique prefixes can get somewhat long (~6 hex
digits seems typical in the Linux repo), which makes them less useful
for manually entering on the CLI. The user typically cares most about
a small set of commits, so it would be nice to give shorter unique ids
to those. That's what Mercurial enables with its
`experimental.revisions.disambiguatewithin` config. This commit
provides an implementation of that feature in `IdPrefixContext`.

In very large repos, it can also be slow to calculate the unique
prefixes, especially if it involves a request to a server. This
feature becomes much more important in such repos.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
2e12aad1f7 id_prefix: add IdIndex::has_key()
For the support for shorter prefixes within a revset, we'll want to be
able to check if an id is in the index.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
481b8c5d0e id_prefix: add IdIndex::resolve_prefix()
I'll use this in `IdPrefixContext` soon.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
f657bcb6ae prefixes: move IdIndex to id_prefix module
I'll reuse it there next.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
5612a3106c revset: use IdPrefixContext for resolving commit/change ids
This is another step towards resolving abbreviated commit ids within a
configured revset.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
f66efcf6f9 revset: inline resolution of change/commit ids
This prepares for adding callbacks to resolve these ids.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
c8648cb300 templater: move id prefix shortening onto a new type
I would like to copy Mercurial's way of abbreviating ids within a
user-configurable revset. We would do it for both commit ids and
change ids. For that feature, we need a place to keep the set of
commits the revset evaluates to. This commit adds a new
`IdPrefixContext` type which will eventually be that place. The new
type has functions for going back and forth between full and
abbreviated ids. I've updated the templater to use it.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
db0d14569b cli: wrap repo in a struct to prepare for adding cached data
I want to store some lazily calculated data associated with a
repo. The data will depend on the user's config, which means it
shouldn't live in the `ReadonlyRepo` itself. We could store it
directly in `WorkspaceCommandHelper` - and I did that at first - but
it's annoying and risky to remember to reset the cached data when we
update the repo instance (which we do when a transaction
finishes). This commit therefore introduces a wrapper type where we
can store it. Having a wrapper also means that we can use `OnceCell`
instead of more manually initializing it with a `RefCell`.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
efd743339c revset: don't allow symbols in RevsetExpression::resolve()
When creating `RevsetExpression` programmatically, I think we should
use commit ids instead of symbols in the expression. This commit adds
a check for that by using a `SymbolResolver` that always errors
out.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
99e9cd70d1 cli: make WorkspaceCommandHelper create SymbolResolver
I would eventually want the `SymbolResolver` to be customizable (in
custom `jj` binaries), so we want to make sure we always use the
customized version of it.

I left `RevsetExpression::resolve()` unchanged. I consider that to be
for programmatically created expressions.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
5e7c57c527 revset: introduce a trait for resolving symbols
I'd like to make the symbol resolution more flexible, both so we can
support customizing it (in custom `jj` binaries) and so we can use it
for resolving short prefixes within a small revset.
2023-05-11 23:41:24 -07:00
Martin von Zweigbergk
ac31c83e13 cli: rename ui.default-revset to revsets.log
I plan to add `revsets.short-prefixes` and `revsets.immutable` soon,
and I think `[revsets]` seems like reasonable place to put them. It
seems consistent with our `[templates]` section. However, it also
suffers from the same problem as that section, which is that the
difference between `[templates]` and `[template-aliases]` is not
clear. We can decide about about templates and revsets later.
2023-05-11 23:41:24 -07:00
Ilya Grigoriev
0a51c5fc2e test_git_colocated_fetch_deleted_branch: Fix the test
Before, HEAD@git was at change `e1f4` mentioned in the test. So, as long as we
consider the behavior added in 20eb9ec to be correct, that change should NOT
have been abandoned after the fetch, in spite of what the comment in the test
says. In other words, the test did NOT demonstrate a bug before this commit.

Now, the test properly demonstrates the bug.

Cc #864
2023-05-11 16:35:11 -07:00
Ilya Grigoriev
46422c6502 test_git_colocated: show git head in colocated tests 2023-05-11 16:35:11 -07:00
dependabot[bot]
8eda1b68b5 cargo: bump clap_complete from 4.2.1 to 4.2.2
Bumps [clap_complete](https://github.com/clap-rs/clap) from 4.2.1 to 4.2.2.
- [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.1...clap_complete-v4.2.2)

---
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-11 10:29:49 -07:00
dependabot[bot]
ecb6352d39 github: bump codespell-project/actions-codespell from 1.0 to 2.0
Bumps [codespell-project/actions-codespell](https://github.com/codespell-project/actions-codespell) from 1.0 to 2.0.
- [Release notes](https://github.com/codespell-project/actions-codespell/releases)
- [Commits](22ff5a2e4b...94259cd8be)

---
updated-dependencies:
- dependency-name: codespell-project/actions-codespell
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-11 17:26:25 +00:00
dependabot[bot]
a5395bc8af cargo: bump serde from 1.0.162 to 1.0.163
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.162 to 1.0.163.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.162...v1.0.163)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-11 10:12:40 -07:00
Tal Pressman
cc21edea6e move .idea ignore to editor-specific section 2023-05-11 13:52:26 +09:00
Tal Pressman
d038926714 trim snapshot progress output 2023-05-11 13:26:42 +09:00
Tal Pressman
f7764bc665 ignore .idea 2023-05-11 12:55:24 +09:00
Yuya Nishihara
92cfffd843 git: on external HEAD move, do not abandon old branch
The current behavior was introduced by 20eb9ecec1 "git: don't abandon
HEAD commit when it loses a branch." While the change made HEAD mutation
behavior more consistent with a plain ref operation, HEAD can also move on
checkout, and checkout shouldn't be considered a history rewriting operation.

I'm not saying the new behavior is always correct, but I think it's safer
than losing old HEAD branch. I also think this change will help if we want
to extract HEAD management function from git::import_refs().

Fixes #1042.
2023-05-11 10:15:31 +09:00
Yuya Nishihara
66d405fa5f git: add tests that simulate external checkout/amend in colocated repo
I'm going to change the behavior of _without_ref() case to mitigate #1042.
2023-05-11 10:15:31 +09:00
dependabot[bot]
aa54fbaa99 cargo: bump libc from 0.2.142 to 0.2.144
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.142 to 0.2.144.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.142...0.2.144)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-08 15:20:09 +00:00
Martin von Zweigbergk
01755176c6 docs: use git switch/restore in command-equivalence table
IIUC, the consensus in the Git project is that the overloaded nature
of `git checkout` for many use cases was a mistake, and `git
switch/restore` are meant to replace it.
2023-05-07 21:48:40 -07:00
Martin von Zweigbergk
6a1bb1c0a9 docs: co-located mode is not new anymore, but it does have surprises 2023-05-07 16:13:33 -07:00
Benjamin Saunders
d747b2f362 lib: use advisory locks on Unix targets
Allows automatic recovery when encountering stale lockfiles, and more
efficient blocking rather than polling for fresh ones. The previous
implementation is preserved for other platforms.
2023-05-07 09:52:09 -07:00