Commit graph

1470 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Benjamin Saunders
ccbb34fddb working_copy: introduce snapshot progress callback 2023-05-06 11:07:46 -07:00
Yuya Nishihara
770ea0c705 tree: rewrite recursive diff iterator to not use machine stack
While mutable borrow in the next() method is a bit tricky, I think it's
easier to follow than invoking iterators recursively.
2023-05-06 14:50:37 +09:00
Yuya Nishihara
a8f77e46a9 tree: extract helper method that sets up subdir iterator
This will be reimplemented as a constructor of subdir item.
2023-05-06 14:50:37 +09:00
Yuya Nishihara
3f7b0929d7 tree: make internal TreeEntryDiffIterator yield all values by reference
This isn't important, but I feel it's a bit inconsistent that name is cloned
by callee, but tree values aren't.
2023-05-06 14:50:37 +09:00
Grégoire Geis
104f8e154c Fix Git/SSH on Windows
There were two issues on my end:
1. `known_hosts` doesn't seem to be recognized
2. SSH Agent is ignored despite running

A workaround for 1. is to set the HOME environment variable on Windows, so I added a hint to suggest this. Ideally we would add a `certificate_check` callback to the remote callbacks, but the git2 crate doesn't expose whether the certificate check already succeeded, which makes it useless for this purpose (as we'd be prompting users to accept a certificate even though that certificate is already known to be valid).

As for 2., I changed the behavior from "check SSH Agent if some env variables exist" to "check SSH Agent and only fail if some env variables exist". On Windows SSH Agent doesn't use these env variables (but trying to communicate with it will still work), so now Windows properly works with SSH Agent.
2023-05-04 23:57:06 +09:00
Martin von Zweigbergk
cd0023e796 tree: if matcher says that tree should be skipped, skip it
When using a sparse working copy (e.g. with no files at all) and
updating the working copy from the root commit to a commit with
millions of files, we shouldn't have to walk the parts of the diff
that doesn't match the sparse patterns. However, we still do the full
walk because our `Tree::diff()` currently doesn't care about what the
matcher tells us to visit, it only filters out unwanted files after
visiting them. This commit fixes that for the special (but common)
case of matching nothing in a directory.

I tried also adding special handling for when the matcher says that we
should only visit a few entries, but it wasn't clearly better in the
cases I tested it on. I'll keep that patch around and might send it if
I find some cases where it helps.
2023-05-03 18:21:51 -07:00
Martin von Zweigbergk
b11d38fdf8 revset: delete obsolete comment about ambiguous change/commit ids
Commit ids and change ids or prefixes of either are never ambiguous
since we started using k-z for change ids.
2023-05-03 16:23:14 -07:00
Martin von Zweigbergk
9cf0440aef revset: elide some lifetimes (reported by IntelliJ) 2023-05-03 16:23:14 -07:00
Martin von Zweigbergk
9c91f8190d tracing: bump a few trace events from DEBUG to INFO
Now that we don't print INFO-level events by default, we can start
using that level.
2023-05-03 11:40:23 -07:00
Martin von Zweigbergk
8395764de8 cargo: downgrade tracing from yanked 0.1.38 to 0.1.37 2023-04-29 22:59:52 -07:00
Yuya Nishihara
e9d2403696 index: use SmallVec to avoid lots of small allocations for adjacent lookup
I simply enabled all smallvec features that are covered by our MSRV.
https://docs.rs/smallvec/latest/smallvec/index.html#optional-features
2023-04-28 08:36:58 +09:00
Yuya Nishihara
d948acd5bf revset: do not scan ancestors more than once to evaluate nested children set 2023-04-28 08:36:58 +09:00
Yuya Nishihara
524db833f7 index: implement RevWalk that filters descendants with generation from roots
We could add `walk.descendants(root_positions)` method, and apply
`.filter_by_generation(range)`, but queue-based `.descendants()` would be
slower than the one using reachable set. So I didn't add such method.

I also considered reimplementing non-lazy version of this function without
using the current RevWalkGenerationRange, but it appears the current iterator
version performs well even if we have to do .collect_vec() and .reverse().
2023-04-28 08:36:58 +09:00
Yuya Nishihara
be5d380f2e index: add newtype to hide RevWalkIndex abstraction
I want to keep RevWalkIndex private, so I need to remove 'I: RevWalkIndex'
trait bound from the public types.
2023-04-28 08:36:58 +09:00
Yuya Nishihara
51683457c7 index: abstract CompositeIndex away from RevWalkQueue 2023-04-28 08:36:58 +09:00
Yuya Nishihara
8176f7d7b4 index: encapsulate ordering details in RevWalkQueue
This helps to extract a trait that abstracts CompositeIndex and descendants
map. Since the entry type E is a newtype wrapper, there wouldn't be runtime
cost.
2023-04-28 08:36:58 +09:00
Yuya Nishihara
e6740d9c3b index: migrate walk_ancestors_until_roots() from revset engine
I'm going to add a RevWalk method to walk descendants with generation filter,
which will use this helper method. RevWalk::take_until_roots() uses .min()
instead of .last() since RevWalk shouldn't know the order of the input set.
2023-04-28 08:36:58 +09:00
dependabot[bot]
d741e5b352 cargo: bump pest_derive from 2.5.7 to 2.6.0
Bumps [pest_derive](https://github.com/pest-parser/pest) from 2.5.7 to 2.6.0.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.7...v2.6.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-27 10:03:58 -07:00
Yuya Nishihara
38e7eff09f index: merge overlapped generation ranges to be enqueued
Before, the number of the generations to track would increase at each merge
point. This was really bad for queries like ':@--' in merge-heavy history,
but I didn't notice the problem because ancestors query is lazy and
the default log template is slow. Since I'm going to reuse RevWalk for
'roots++:' queries, which can't be lazy, I need to fix this problem first.

As we don't have a revset expression to specify exact generation range,
gen.end is initialized to either 1 or close to u32::MAX. So, this change
means long-lived generation ranges will eventually be merged into one.
2023-04-27 08:18:47 +09:00
Yuya Nishihara
9a6a7c50db index: translate generation-filter range to item ranges
This allows us to merge overlapped ranges per entry.
2023-04-27 08:18:47 +09:00
Yuya Nishihara
c61d4e8404 index: extract constructor and helper methods of generation range walker 2023-04-27 08:18:47 +09:00
dependabot[bot]
a21b3d8c02 cargo: bump pest from 2.5.7 to 2.6.0
Bumps [pest](https://github.com/pest-parser/pest) from 2.5.7 to 2.6.0.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.7...v2.6.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-26 12:55:04 -07:00
dependabot[bot]
3391b217a8 cargo: bump tracing from 0.1.37 to 0.1.38
Bumps [tracing](https://github.com/tokio-rs/tracing) from 0.1.37 to 0.1.38.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-0.1.37...tracing-0.1.38)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-26 12:54:28 -07:00
Martin von Zweigbergk
a19a91bfbc cargo: upgrade regex 1.7.3 to 1.8.1 2023-04-24 11:28:12 -07:00