Commit graph

1614 commits

Author SHA1 Message Date
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
Yuya Nishihara
837e8aa81a revset: add substitution rule for nested descendants/children
The substitution rule and tests are copied from ancestors/parents. The backend
logic will be reimplemented later. For now, it naively repeats children().
2023-04-24 20:45:13 +09:00
Yuya Nishihara
32253fed5e revset: replace children node with descendants of generation 1..2 2023-04-24 20:45:13 +09:00
Yuya Nishihara
a99b82c634 revset: add generation parameter to descendants node
This is a minimal change to replace Children with Descendants. A generation
parameter could be added to RevsetExpression::DagRange, but it's not needed
as of now.
2023-04-24 20:45:13 +09:00
Yuya Nishihara
f6570486e0 revset: add descendants node to expression, resolve it later
I'll add a substitution rule that folds (x+)+, and 'Descendants { roots }'
is easier to process than 'DagRange { roots, heads }'.
2023-04-24 20:45:13 +09:00
Yuya Nishihara
eadf8faded revset: extract children() evaluation to function
I'm going to add generation parameter to Children/DagRange nodes, and
'Children { .. }' will be substituted to 'DagRange { .., gen: 1 }'. This
commit helps future code move.

Lifetime bounds of the arguments are unnecessarily restricted. It appears
walk_ancestors_until_roots() captures arguments lifetime on rustc 1.64.0.
I think the problem will go away if walk_*() functions are extracted to
RevWalk methods where input arguments will become less generic.
2023-04-24 20:45:13 +09:00
Yuya Nishihara
d9d2b405e1 revset: remove redundant boxing from evaluated children node
Just spotted while moving codes around. This wouldn't matter in practice.
2023-04-24 20:45:13 +09:00
Yuya Nishihara
36e7afe0db revset: exclude unreachable roots from collect_dag_range() result
It doesn't matter, but can simplify the function interface. I'll probably
extract this function to RevWalk so the descendants with/without generation
filter can be tested without using revset API.
2023-04-24 20:45:13 +09:00
Martin von Zweigbergk
c60f14899a index: remove entry_by_id() from trait
It no longer needs to be on the `Index` trait, thereby removing the
last direct use of `IndexEntry` in the trait (it's still used
indirectly in `walk_revs()`).
2023-04-18 18:32:23 -07:00
dependabot[bot]
c7b66606a1 cargo: bump git2 from 0.17.0 to 0.17.1
Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.17.0 to 0.17.1.
- [Release notes](https://github.com/rust-lang/git2-rs/releases)
- [Changelog](https://github.com/rust-lang/git2-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/git2-rs/compare/git2-curl-0.17.0...0.17.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-17 09:19:58 -07:00
Ilya Grigoriev
c298339f98 proto_op_store: Add two minor comments 2023-04-16 22:04:27 -07:00
dependabot[bot]
cf402af9c1 cargo: bump prost-build from 0.11.8 to 0.11.9
Bumps [prost-build](https://github.com/tokio-rs/prost) from 0.11.8 to 0.11.9.
- [Release notes](https://github.com/tokio-rs/prost/releases)
- [Commits](https://github.com/tokio-rs/prost/compare/v0.11.8...v0.11.9)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-14 16:11:09 +00:00
Yuya Nishihara
6a55ae6fea settings: add helper to turn ConfigError::NotFound into Option
Now we have 4 callers, I concluded this is common enough to add an
extension method. Still I think it's preferred to define config items in
src/config/*.toml if possible. It will catch typo of config keys.
2023-04-14 20:30:42 +09:00
dependabot[bot]
72985a6286 cargo: bump prost from 0.11.8 to 0.11.9
Bumps [prost](https://github.com/tokio-rs/prost) from 0.11.8 to 0.11.9.
- [Release notes](https://github.com/tokio-rs/prost/releases)
- [Commits](https://github.com/tokio-rs/prost/compare/v0.11.8...v0.11.9)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-13 16:26:06 +00:00
dependabot[bot]
86bbea2b3c cargo: bump serde_json from 1.0.95 to 1.0.96
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.95 to 1.0.96.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.95...v1.0.96)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-13 16:21:06 +00:00
Martin von Zweigbergk
e492548772 revset: bump generation numbers in API to 64 bits
A chain of 4 billion commits is a lot, but it's not out of the
question, so let's support it. The current default index will not be
able to handle that many commits, so I let that still use 32-bit
integers.
2023-04-12 21:18:49 -07:00
Yuya Nishihara
5351371d51 revset: resolve visible heads prior to evaluation 2023-04-10 00:39:58 +09:00
Yuya Nishihara
7e1e9efa38 revset: resolve "all()" prior to evaluation 2023-04-10 00:39:58 +09:00
Yuya Nishihara
f43f0d24b8 revset: resolve candidates of children set prior to evaluation 2023-04-10 00:39:58 +09:00
Yuya Nishihara
7974269bab revset: remove None variant from resolved enum, use Commits([]) instead
We'll remove All, so it makes sense to not have None either.
2023-04-10 00:39:58 +09:00
Yuya Nishihara
0fcc13a6f4 revset: make resolve() return different type describing evaluation plan
New ResolvedExpression enum ensures that the evaluation engine doesn't have
to know the symbol resolution details. In this commit, I've moved Filter
and NotIn resolution to resolve_visibility(). Implicit All/VisibleHeads
resolution will be migrated later.

It's tempting to combine resolve_symbols() and resolve_visibility() to get
rid of panic!()s, but the resolution might have to be two passes to first
resolve&collect explicit commit ids, and then substitute "all()" with
"(:visible_heads())|commit_id|..". It's also possible to apply some tree
transformation after symbol resolution.
2023-04-10 00:39:58 +09:00
Yuya Nishihara
6c2525cb93 revset: add "resolve" method to RevsetExpression, always call it
I'll make the resolution stage mandatory, and have it return a "resolved"
type. RevsetExpression::evaluate() will be moved to the "resolved" type.
2023-04-10 00:39:58 +09:00
Yuya Nishihara
6d9b836d10 revset: extract unresolved commit references to separate enum
This makes it clear what should be resolved at resolve_symbols(). Symbol
is a bit special while parsing function arguments, but it's no different
than the other unresolved references at expression level.
2023-04-10 00:39:58 +09:00
Yuya Nishihara
fc65b00020 revset: extract CommitId resolution to function
I'm going to merge unresolved variants as RevsetExpression::CommitRef(_).
This prepares for the change.
2023-04-10 00:39:58 +09:00
Yuya Nishihara
adfd52445b revset: reimplement children to not scan visible ancestors twice
It's slightly faster, and removes the use of RevsetExpression::descendants()
API.
2023-04-08 12:13:30 +09:00
Yuya Nishihara
5dd99db250 revset: make evaluation helper not create trait object eagerly
We wouldn't care for the cost of virtual dispatch at this level, but I
think a concrete struct type is easier to deal with than trait object.
2023-04-08 12:13:30 +09:00
Yuya Nishihara
85fb1f74c3 revset: for roots:heads, terminate ancestor lookup at min(roots) 2023-04-08 12:13:30 +09:00
Yuya Nishihara
ddff089286 revset: do not evaluate roots() candidates three times 2023-04-08 12:13:30 +09:00
Yuya Nishihara
eef6a77aa4 revset: reuse reachable dag-range set to calculate roots
This also removes the use of RevsetExpression::connected() API from the
evaluation engine.
2023-04-08 12:13:30 +09:00
Yuya Nishihara
20aa31336e revset: extract dag-range calculation to function
The returned reachable set can be reused to calculate roots() expression.
2023-04-08 12:13:30 +09:00
Yuya Nishihara
7dc35b82b0 revset: evaluate ancestors without using RevsetExpression builder API
I'm thinking of transforming RevsetExpression to a enum dedicated for
the evaluation stage. To help the migration, I want to remove the use of
the RevsetExpression builder API from the evaluation engine.

Fewer virtual dispatch is also better.
2023-04-08 12:13:30 +09:00
Martin von Zweigbergk
24a512683b revset: add a revset function for finding commits with conflicts
This adds `conflict()` revset that selects commits with conflicts. We
may want to extend it later to consider only conflicts at certain
paths.
2023-04-06 16:46:21 -07:00
Yuya Nishihara
308a5b9eae revset: make empty()/file(".") not load root tree for liner history
TreeDiffIterator wouldn't load identical subtrees, but it's up to caller to
optimize out the root tree loading.
2023-04-05 21:53:24 +09:00
Martin von Zweigbergk
e1c57338a1 revset: split out no-args head() to visible_heads()
The `heads()` revset function with one argument is the counterpart to
`roots()`. Without arguments, it returns the visible heads in the
repo, i.e. `heads(all())`. The two use cases are quite different, and
I think it would be good to clarify that the no-arg form returns the
visible heads, so let's split that out to a new `visible_heads()`
function.
2023-04-03 23:46:34 -07:00
Yuya Nishihara
982062bd75 revset: do not always evaluate filter node to InternalRevset
This basically removes hidden 'all() &' from union/negation of filters. To
achieve that, I have two options: 1. add separate evaluation path (like the
one this commit introduced), or 2. wrap "all()" revset to override predicate
as Box::new(|_| true) function. I took the former since it's less ad-hoc.

We can add an explicit RevsetExpression node to branch between evaluate()
and evaluate_predicate(), but I don't think it would simplify the
implementation at this point. We might need such node if we want to resolve
"all()" at resolve_symbols(). It might be even better to extract a subset of
RevsetExpression enum, which only contains evaluatable nodes.

The cost of 'all() &' isn't significant for most filters. '~merges()' is
the exception. For jj repo,

    revsets/:v0.3.0 & (author(martinvonz) | committer(martinvonz))
    --------------------------------------------------------------
    base     1.06      11.2±0.04m
    new      1.00      10.5±0.05m

    revsets/~merges()
    -----------------
    base     1.69     750.0±8.47µ
    new      1.00     444.1±3.50µ
2023-04-04 15:21:21 +09:00
Yuya Nishihara
69794f2585 revset: add method to upcast InternalRevset to ToPredicateFn 2023-04-04 15:21:21 +09:00
Yuya Nishihara
426f3e4e0a revset: simplify evaluation of "all()"
I think this is more readable, and apparently it produces slightly better code
maybe because the compiler can determine that there are no unwanted markers.
2023-04-04 15:21:21 +09:00
Yuya Nishihara
0bfdbcaa1e revset: don't rewrite '~set & filter' as difference
Since filter is slow in general, its input set should be minimized. This has
measurable impact on artificial query like '~(v0.4.0..) & author(_)'. If it
were evaluated as a difference of sets, all commits would have to be loaded.
2023-04-04 15:21:21 +09:00
dependabot[bot]
663f0ef697 cargo: bump pest_derive from 2.5.6 to 2.5.7
Bumps [pest_derive](https://github.com/pest-parser/pest) from 2.5.6 to 2.5.7.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.6...v2.5.7)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-03 09:29:53 -07:00
dependabot[bot]
658423dc78 cargo: bump test-case from 3.0.0 to 3.1.0
Bumps [test-case](https://github.com/frondeus/test-case) from 3.0.0 to 3.1.0.
- [Release notes](https://github.com/frondeus/test-case/releases)
- [Changelog](https://github.com/frondeus/test-case/blob/master/CHANGELOG.md)
- [Commits](https://github.com/frondeus/test-case/compare/v3.0.0...v3.1.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-03 09:29:29 -07:00
dependabot[bot]
fb27885c5d cargo: bump git2 from 0.16.1 to 0.17.0
Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.16.1 to 0.17.0.
- [Release notes](https://github.com/rust-lang/git2-rs/releases)
- [Changelog](https://github.com/rust-lang/git2-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/git2-rs/compare/0.16.1...git2-curl-0.17.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-03 09:24:05 -07:00
Yuya Nishihara
3927c01d08 revset: make error type opaque to try_transform_expression()
It no longer handles RevsetResolutionError.
2023-04-03 10:55:03 +09:00
Yuya Nishihara
f1e2d19d57 revset: fully consume Present(_) node by resolve_symbols()
Since resolve_symbols() now removes Present(_) node, it make sense to
handle symbol resolution error there. That's why I added a "pre" callback
to try_transform_expression().

Perhaps, "operation" scope (#1283) can be implemented in a similar way,
(but somehow need to resolve operation id and call repo.reload_at(op).)
2023-04-03 10:55:03 +09:00
Yuya Nishihara
aeb93c7591 revset: insert pre-order callback that can terminate transformation early
This will be a hook for resolve_symbols() to transform Present(_) subtree.
2023-04-03 10:55:03 +09:00
Yuya Nishihara
feaad6b5fa revset: add type alias for Option<Rc<RevsetExpression>>
I'm going to parameterize error type of TransformResult, and the result type
will be replaced with Result<TransformedExpression, E>.
2023-04-03 10:55:03 +09:00
Yuya Nishihara
c28d2d7784 revset: split RevsetError into RevsetResolution/EvaluationError
This makes it clear that RevsetExpression::Present node is noop at the
evaluation stage.

RevsetEvaluationError::StoreError is unused right now, but I'm not sure if
it should be removed. It makes some sense that evaluate() can propagate
StoreError as it has access to the store.
2023-04-03 10:55:03 +09:00
Yuya Nishihara
429562ca2f revset: implement Debug for RevsetImpl and add trait bound accordingly 2023-04-02 22:54:46 +09:00
Yuya Nishihara
2aab6c7825 revset: implement Debug for InternalRevset objects
Even though predicate function and RevWalk internals can't be debug printed,
it's useful to see an overview of InternalRevset tree.
2023-04-02 22:54:46 +09:00
Yuya Nishihara
b297b7c965 revset: turn PurePredicateFn into newtype struct
This will avoid extra boxing when converting PurePredicateFn to dyn
ToPredicateFn object.
2023-04-02 22:54:46 +09:00
Yuya Nishihara
fbb292f7c9 revset: relax lifetime bound of ToPredicateFn
We don't have to require that the input IndexEntry<'_> has 'index lifetime.
2023-04-02 22:54:46 +09:00
Yuya Nishihara
2404dc8cd3 revset: remove redundant type bound from RevWalkRevset
The "'index: 'a" bound can be removed by bypassing the Box<dyn> indirection
of self.iter().
2023-04-02 22:54:46 +09:00
Ilya Grigoriev
a58af4f19d Work around a couple of false positives for recent nightly clippy
This is likely https://github.com/rust-lang/rust-clippy/issues/10577
2023-04-01 18:35:38 -07:00
dependabot[bot]
0f108e278d cargo: bump pest from 2.5.6 to 2.5.7
Bumps [pest](https://github.com/pest-parser/pest) from 2.5.6 to 2.5.7.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.6...v2.5.7)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-31 09:27:29 -07:00
Martin von Zweigbergk
3546cc1bf6 revset: pass in store, index, and heads instead of whole Repo
The `Repo` is a higher-level type that the index shouldn't have to
know about. With this change, a custom revset implementation should be
able evaluate the revset on a server without knowing which repo it
refers to.
2023-03-30 20:15:45 -07:00
Martin von Zweigbergk
9f9e356f3d revset: use the default index impl more in default revset engine
We already pass a `CompositeIndex` to
`default_revset_engine::evaluate()` so let's use that wherever we
currently use `repo.index()`. That will help us remove the `repo`
argument, and it will also let us internal types (like `IndexEntry`)
in the index methods we call.
2023-03-30 20:15:45 -07:00
Martin von Zweigbergk
002ec1ac68 revset: move internal_evaluate() onto new context type
I'm about to replace the `&dyn Repo` argument by several smaller
types, and it's easier to collect those in a single context type than
to pass them separately as arguments.

I also moved `revset_for_commit_ids()` and `take_latest_revset()` onto
the new type because it was easy. `build_predicate_fn()` and
`has_diff_from_parent()` ran into some lifetime issue when I tried.
2023-03-30 20:15:45 -07:00
Martin von Zweigbergk
3ff1ab520b revset: remove public_heads()
The `public_heads()` revset only contains the root commit in
practice. I'm not sure what we want to do about phases, but since we
don't have any real support for them yet, let's just remove this
revset. I didn't update the changelog because we don't seem to have
documented the revset function (and it seems unlikely that users who
found out about it found it useful enough to use it when they could
just use `root`).
2023-03-30 20:15:45 -07:00
Martin von Zweigbergk
2a3d402d0c revset: also resolve branches(), tags(), etc. when resolving symbols
This is another step towards removing the `Repo` argument from
`Index::evaluate_revset()`.
2023-03-30 20:15:45 -07:00
Martin von Zweigbergk
6643fb2bff op_store: inline ProtoOpStore into SimpleOpStore
The `ProtoOpStore` was separated out to simplify the migration from
Thrift. Now that the `ThriftOpStore` is gone, we can inline
`ProtoOpStore` as the TODO says.
2023-03-30 20:00:33 -07:00
Martin von Zweigbergk
68fb46b2af op_store: drop support for upgrading from Thrift implementation 2023-03-30 20:00:33 -07:00
dependabot[bot]
0d581809fc cargo: bump tempfile from 3.4.0 to 3.5.0
Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.4.0 to 3.5.0.
- [Release notes](https://github.com/Stebalien/tempfile/releases)
- [Changelog](https://github.com/Stebalien/tempfile/blob/master/NEWS)
- [Commits](https://github.com/Stebalien/tempfile/commits)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-30 16:38:19 +00:00
B Wilson
01a9ce0c71 diff: Treat multi-byte UTF-8 runes as word characters
Inline diffs on multi-byte UTF-8 characters would match individual
bytes, causing garbled diffs in some cases. For example, replacing
`⊢` with `⊣`, which differ in the final byte only, caused the
diff to display a diff of the bytes instead the character.

This commit uses a workaround present in Mercurial by treating all
bytes 0x80 and above as word characters, causing any multi-byte
character to be treated as a word and not segmented.

https://www.mercurial-scm.org/repo/hg/file/6.3.3/mercurial/patch.py#l51
2023-03-30 00:06:56 +09:00
dependabot[bot]
05e6609efc cargo: bump serde_json from 1.0.94 to 1.0.95
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.94 to 1.0.95.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.94...v1.0.95)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-28 10:16:06 -07:00
dependabot[bot]
77164d6456 cargo: bump regex from 1.7.2 to 1.7.3
Bumps [regex](https://github.com/rust-lang/regex) from 1.7.2 to 1.7.3.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.7.2...1.7.3)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-27 16:22:29 +00:00
Yuya Nishihara
75988118d3 benches: group unchanged/modified/reversed-line diffs together
Criterion can summarize the grouped benchmarks, which seemed somewhat useful.
2023-03-27 23:38:56 +09:00
Yuya Nishihara
0087f988f7 benches: drop dependency on criterion_bencher_compat 2023-03-27 23:38:56 +09:00
Yuya Nishihara
91d0c28080 benches: move diff_bench to lib crate
It has no dependency on the cli crate.
2023-03-27 23:38:56 +09:00
Yuya Nishihara
7ebffe8e6f cargo: sort dependencies in lexicographical order
This should help future cargo add.
2023-03-27 23:38:56 +09:00
Yuya Nishihara
0532301e03 revset: add latest(candidates, count) predicate
This serves the role of limit() in Mercurial. Since revsets in JJ is
(conceptually) an unordered set, a "limit" predicate should define its
ordering criteria. That's why the added predicate is named as "latest".

Closes #1110
2023-03-25 23:48:50 +09:00
Yuya Nishihara
185549f031 revset: extract helper to parse literal to e.g. usize 2023-03-25 23:48:50 +09:00
Yuya Nishihara
d04556cf18 revset: use unstable sort to enforce ordering of commit ids
This wouldn't matter in practice, but there should be no reason to stick
to stable sort.
2023-03-25 23:48:50 +09:00
Martin von Zweigbergk
ce5c90b4e5 revset: use Index::has_id() for checking if a commit has been indexed
This avoids another use of `IndexEntry`.
2023-03-24 10:09:40 -07:00
Martin von Zweigbergk
baea314fc0 index: get generation number from specific impl in test 2023-03-24 10:09:40 -07:00
Martin von Zweigbergk
a5b79f9b0e index: make topo_order() return commit ids instead of index entries
`IndexEntry` is specific to the default index store; we don't want it
in the interface.
2023-03-24 10:09:40 -07:00
Martin von Zweigbergk
772cb1a0e9 revset: replace an unnecessary iterator adapter by a simple map()
As noted by @yuja in #1423.
2023-03-24 10:09:40 -07:00
Martin von Zweigbergk
75605e36af revset: iterate over commit ids instead of index entries
There are no remaining places where we iterate over a revset and need
the `IndexEntry`s, so we can now make `Revset::iter()` yield
`CommitId`s instead.
2023-03-23 21:58:15 -07:00
Martin von Zweigbergk
b5ea79f32e revset: add new graph iterator function for tests
I'm about to make `Revset::iter()` yield just `CommitId`s, but the
tests in `test_default_revset_graph_iterator.rs` need an `IndexEntry`
iterator so they can pass it into `RevsetGraphIterator::new()`. This
commits prepares for the change by adding a
`RevsetImpl::iter_graph_impl()` that returns `RevsetGraphIterator`,
keeping `InternalRevset` still hidden within the revset engine. We
could instead have made that (and `ToPredicateFn`) visible to tests. I
can't say which is better.
2023-03-23 21:58:15 -07:00
Martin von Zweigbergk
c8f387d5b3 revset: pass IndexEntry iterator to graph iterator
The graph iterator is specific to the index implementation, and it
needs access to `IndexEntry`, which `Revset::iter()` will soon not
yield.
2023-03-23 21:58:15 -07:00
Martin von Zweigbergk
0b506d8461 index: remove position-based methods 2023-03-23 20:49:15 -07:00
Martin von Zweigbergk
d4e1156957 repo: move IdIndex to revset engine 2023-03-23 20:49:15 -07:00
Martin von Zweigbergk
13a000caa7 repo: get change id index from revset also for mutable repo
I don't know if we ever resolve revsets in a mutable repo, but now
that we can get a change id index from a revset, it's easier to
implement this functionality that way.
2023-03-23 20:49:15 -07:00
Martin von Zweigbergk
68cff2fa22 repo: get change id index from revset instead of building it in repo
This replaces the direct use of `IdIndex` in `ReadonlyRepo` by use of
`Revset::change_id_index()`.

I made the `Index` trait require `Send` and `Sync` in order to be able
to store an instance of it in `ReadonlyRepo` (via `ChangeIdIndex`) and
still have that be `Send` and `Sync`. We could alternatively store the
`ChangeIdIndex` in a `Mutex`. Now that will be up to the
`ChangeIdIndex` instead.
2023-03-23 20:49:15 -07:00
Martin von Zweigbergk
27a7fccefa revset: add a method returning a change id index
One of the remaining places we depend on index positions is when
creating a `ChangeIdIndex`. This moves that into the revset engine
(which is coupled to the commit index implementation) by adding a
`Revset::change_id_index()` method. We will also use this function
later when add support for resolving change id prefixes within a small
revset.

The current implementation simply creates an in-memory index using the
existing `IdIndex` we have in `repo.rs`.

The custom implementation at Google might do the same for small
revsets that are available on the client, but for revsets involving
many commits on the server, it might use a suboptimmal implementation
that uses longer-than-necessary prefixes for performance reasons. That
can be done by querying a server-side index including changes not in
the revset, and then verifying that the resulting commits are actually
in the revset.
2023-03-23 20:49:15 -07:00
Martin von Zweigbergk
a65e0e771c revset: remove unnecessary wrapping of every node in RevsetImpl
Thanks to @yuja for the suggestion.
2023-03-23 20:49:15 -07:00
dependabot[bot]
4dc97de928 cargo: bump insta from 1.28.0 to 1.29.0
Bumps [insta](https://github.com/mitsuhiko/insta) from 1.28.0 to 1.29.0.
- [Release notes](https://github.com/mitsuhiko/insta/releases)
- [Changelog](https://github.com/mitsuhiko/insta/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mitsuhiko/insta/compare/1.28.0...1.29.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-23 09:34:27 -07:00
Yuya Nishihara
9d661d6f69 cli: render other kind of revset error suggestion as hint 2023-03-23 23:08:17 +09:00
Yuya Nishihara
ddeb645d7f cli: provide hint for typo of revset function name
This is similar to what Mercurial does. The similarity threshold is copied
from clap, but we might want to adjust it later.
2023-03-23 23:08:17 +09:00
Yuya Nishihara
d3d8afc77b revset: rewrite match table of builtin functions as HashMap
So that we can build a list of function names.
2023-03-23 23:08:17 +09:00
Martin von Zweigbergk
5709822f05 rewrite: keep commits to visit instead of looking up again
Since the commits are cached in `Store`, this doesn't have any impact
on performance, but it's a little simpler.
2023-03-23 04:50:33 -07:00
Martin von Zweigbergk
e81890b319 rewrite: work with commits instead of index entries in setup code
When deciding the order to visit commits to rebase, we currently look
up parents in the index. I'm trying to remove the current `IndexEntry`
type and will probably have revsets iterators yield simply
`CommitId`. Let's therefore look up commit objects here.

I timed this by rewriting all commits in the jj repo. I couldn't
measure any difference. That makes sense since we cache the commits in
`Store` and we would read the commit when rebasing it anyway.
2023-03-23 04:50:33 -07:00
Martin von Zweigbergk
d3cf543abc revset: move revset_for_commits() to test
The function is only used in tests, so it doesn't belong in
`default_revset_engine`. Also, it's not specific to that
implementation, so I rewrote as a revset evaluation.
2023-03-23 04:50:33 -07:00
Martin von Zweigbergk
5f74dd5db3 repo: implement Repo on ReadonlyRepo instead of its Arc
I'd like to be able to pass a `self` of `type `&ReadonlyRepo` to
functions that take a `&dyn Repo`. For that, we need `ReadonlyRepo`
itself to implement `Repo` instead of having `Arc<ReadonlyRepo>`
implement it. I could have solved it in a different way, but the `Arc`
requirement seems like an unnecessary constraint.
2023-03-21 21:43:44 -07:00
Martin von Zweigbergk
d089c22232 repo: move base_repo() off of Repo trait
We only ever call `base_repo()` on `MutableRepo` instances.
2023-03-21 21:43:44 -07:00
Martin von Zweigbergk
ea498df539 repo: when resolving change id prefix, directly return commit ids
The functions resolving a change id to commits currently return a
`Vec<IndexEntry>`. We want to avoid depending on `IndexEntry` and we
only need the commit ids here.
2023-03-21 21:43:44 -07:00
dependabot[bot]
942bb4c8c4 cargo: bump regex from 1.7.1 to 1.7.2
Bumps [regex](https://github.com/rust-lang/regex) from 1.7.1 to 1.7.2.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.7.1...1.7.2)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-21 16:15:53 +00:00
dependabot[bot]
522de4f8c7 cargo: bump thiserror from 1.0.39 to 1.0.40
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.39 to 1.0.40.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/1.0.39...1.0.40)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-20 20:34:15 +00:00
Martin von Zweigbergk
01d7239732 revset: make graph iterator yield commit ids (not index entries)
We only need `CommitId`s, and `IndexEntry` is specific to the default
index implementation.
2023-03-20 01:45:54 -07:00
Martin von Zweigbergk
2f876861ae graphlog: key by commit id (not index position)
The index position is specific to the default index implementation and
we don't want to use it in outside of there. This commit removes the
use of it as a key for nodes in the graphlog.

I timed it on the git.git repo using `jj log -r 'all()' -T commit_id`
(the worst case I can think of) and it slowed down from ~2.02 s to
~2.20 s (~9%).
2023-03-20 01:45:54 -07:00
Martin von Zweigbergk
91df7ec4c5 revset: rename graph iterator test to match implementation 2023-03-20 01:45:54 -07:00
Martin von Zweigbergk
e721a81780 revset: update documentation of Revset::iter()
Since we hid the graph iterator implementation behind
`Revset::iter_graph()`, I don't think we have any callers of
`Revset::iter()` require the iteration to be in index position order,
so let's not promise that. We do want to promise that the iteration is
in topological order with children before parents, however.
2023-03-20 01:45:54 -07:00
Martin von Zweigbergk
f758b646a9 commit_builder: add accessors for most fields
I'd like to be able to access the current committer on a
`CommitBuilder`.
2023-03-19 00:48:05 -07:00
Martin von Zweigbergk
2495c8f27e cargo: update MSRV to 1.64
We need 1.64 to bump `clap` to `4.1`. We don't really need to upgrade
to that, but being on an older version causes minor confusions like
#1393. Rust 1.64 is very close to 6 months old at this point.
2023-03-17 22:44:29 -07:00
Martin von Zweigbergk
70d4a0f42e revset: remove context parameter from evaluate()
The `RevsetWorkspaceContext` argument is now instead used by the new
`resolve_symbol()` function.
2023-03-17 22:42:41 -07:00
Martin von Zweigbergk
d971148e4e revset: move resolve_symbol() back to revset module
The only caller is now in `revset.rs`.
2023-03-17 22:42:41 -07:00
Martin von Zweigbergk
94aec90bee revset: resolve symbols earlier, before passing to revset engine
For large repos, it's useful to be able to use shorter change id and
commit id prefixes by resolving the prefix in a limited subset of the
repo (typically the same subset that you'd want to see in your default
log output). For very large repos, like Google's internal one, the
shortest unique prefix evaluated within the whole repo is practically
useless because it's long enough that the user would want to copy and
paste it anyway.

Mercurial supports this with its `revisions.disambiguatewithin` config
(added in https://www.mercurial-scm.org/repo/hg/rev/503f936489dd). I'd
like to add the same feature to jj. Mercurial's implementation works
by attempting to resolve the prefix in the whole repo and then, if the
prefix was ambiguous, it resolves it in the configured subset
instead. The advantage of doing it that way is that there's no extra
cost of resolving the revset defining the subset if the prefix was not
ambiguous within the whole repo. However, there are two important
reasons to do it differently in jj:

* We support very large repos using custom backends, and it's probably
  cheaper to resolve a prefix within the subset because it can all be
  cached on the client. Resolving the prefix within the whole repo
  requires a roundtrip to the server.

* We want to be able to resolve change id prefixes, which is always
  done in *some* revset. That revset is currently `all()`, i.e. all
  visible commits. Even on local disk, it's probably cheaper to
  resolve a small revset first and then resolve the prefix within that
  than it is to build up the index of all visible change ids.

We could achieve the goal by letting each revset engine respect the
configured subset, but since the solution proposed above makes sense
also for local-disk repos, I think it's better to do it outside of the
revset engine, so all revset engines can share the code.

This commit prepares for the new functionality by moving the symbol
resolution out of `Index::evaluate_revset()`.
2023-03-17 22:42:41 -07:00
Martin von Zweigbergk
1711cb61fb revset: add a Result version of transform_expression_bottom_up()
I'd like to add a stage after optimization for resolving most symbols
to commit IDs, and that needs to be able to fail.
2023-03-17 22:42:41 -07:00
Martin von Zweigbergk
5afe5091a0 revset: add default_ prefix to graph iterator module
The current revset graph iterator is the default one, which the
default revset engine provides.
2023-03-14 05:32:02 -07:00
Martin von Zweigbergk
3871efd2f9 revset: move ReverseRevsetGraphIterator into revset module
The iterator is not specific to the implementation in
`revset_graph_iterator`, so it belongs in the standard `revset`
module.
2023-03-14 05:32:02 -07:00
Martin von Zweigbergk
f62fac24ac revset: move graph iteration onto Revset trait
We want to allow custom revset engines define their own graph
iterator. This commit helps with that by adding a
`Revset::iter_graph()` function that returns an abstract iterator.

The current `RevsetGraphIterator` can be configured to skip or include
transitive edges. It skips them by default and we don't expose option
in the CLI. I didn't bother including that functionality in the new
`iter_graph()` either. At least for now, it will be up to the
implementation whether it includes such edges (it would of course be
free to ignore the caller's request even if we added an option for it
in the API).
2023-03-14 05:32:02 -07:00
Martin von Zweigbergk
28cbd7b1c5 revset: move evaluation into index
This commit adds an `evaluate_revset()` function to the `Index`
trait. It will require some further cleanup, but it already achieves
the goal of letting the index implementation decide which revset
engine to use.
2023-03-14 05:32:02 -07:00
Martin von Zweigbergk
eed0b23009 revset: move current implementation to new module
We want to allow customization of the revset engine, so it can query
server indexes, for example. The current revset implementation will be
our default implementation for now. What's left in the `revset` module
after this commit is mostly parsing code.
2023-03-14 05:32:02 -07:00
dependabot[bot]
1e55fa6c9b cargo: bump whoami from 1.3.0 to 1.4.0
Bumps [whoami](https://github.com/ardaku/whoami) from 1.3.0 to 1.4.0.
- [Release notes](https://github.com/ardaku/whoami/releases)
- [Changelog](https://github.com/ardaku/whoami/blob/stable/CHANGELOG.md)
- [Commits](https://github.com/ardaku/whoami/compare/v1.3.0...v1.4.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-13 10:42:22 -07:00
dependabot[bot]
f5de5707b2 cargo: bump chrono from 0.4.23 to 0.4.24
Bumps [chrono](https://github.com/chronotope/chrono) from 0.4.23 to 0.4.24.
- [Release notes](https://github.com/chronotope/chrono/releases)
- [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md)
- [Commits](https://github.com/chronotope/chrono/compare/v0.4.23...v0.4.24)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-13 10:41:49 -07:00
Martin von Zweigbergk
6a57456067 revset: remove is_empty() implementation from trait
Now that there's a single implementation of `Revset`, I think it makes
more sense for `is_empty()` to be defined there. Maybe different
revset engines have different ways of implementing it. Even if they
don't, this is trivial to re-implement in each revset engine.
2023-03-13 07:20:35 -07:00
Martin von Zweigbergk
2d1b13b338 revset: make ToPredicateFn private, decouple public type from private
As the comment above `ToPredicateFn` says, it could be a private
type. This commit makes that happen by making the private `Revset`
implementations (`DifferenceRevset` etc.) instead implement an
internal revset type called `InternalRevset`. That type is what
extends `ToPredicateFn`, so the public type doesn't have to. The new
type will not need to implement the new functions I'm about to add to
the `Revset` trait.
2023-03-13 07:20:35 -07:00
Martin von Zweigbergk
9e6c139fa0 revset: create wrapper for current revset implementation
We don't want the public `Revset` interface to know about
`ToPredicateFn`. In order to hide it, I'm wrapping the internal type
in another type, so only the internal type can keep implementing
`ToPredicateFn`.
2023-03-13 07:20:35 -07:00
Martin von Zweigbergk
6c9cefb8a0 revset: make evaluate_revset() private and use it internally
I'd like to be able to change the return type of `evaluate_revset()`
to be an internal type. Since all external callers currently call the
function via `RevsetExpression::evaluate()`, it turns out it's easy to
make it private. To benefit from an internal type, we also need to
make the recursive calls be directly to the internal function.
2023-03-13 07:20:35 -07:00
Martin von Zweigbergk
ada48c6f71 revset: rename file() test for consistency
This should have been part of bbd6ef0c7b.
2023-03-13 07:20:35 -07:00
Martin von Zweigbergk
74ffe7f688 index: remove num_commits() from API 2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
0a7de2540f tests: call num_commits() on specific implementation
This removes the last calls to `Index::num_commits()`.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
52e4bee3fe index: remove stats() from API
The `stats()` function is specific to the default implementation, so
it shouldn't be part of the `Index` trait.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
5423feb8e1 tests: call stats() on specific implementation
This removes the remaining calls to `Index::stats()`.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
59b40d8380 tests: avoid some unnecessary calls to index().stats()
The tests adding and removing heads to the repo mostly want to verify
that the set of heads is expected. Some of them also check that
commits are available in the index. But they shouldn't care about the
exact index stats.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
121b86c89c tests: remove an obsolete TODO about unreachable commits in index
I don't think there's much to gain from making the index match exactly
what's reachable from the view. FWIW, our cloud-based implementation
at Google will probably make everyone's commits visible in the index
regardless of which operation they're at.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
8c5c0f0e83 cli: make jj debug index get stats from specific implementation
We don't want custom index implementations to have to conform to the
same kind of stats as the default implementation. This commit also
makes the command error out on non-default index types.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
504a2b3fd0 cli: add test of jj debug reindex, do full reindexing
I broke the commands in a27da7d8d5 and thought I just fixed it in
c7cf914694a8. However, as I added a test, I realized that I made it
only reindex the commits since the previous operation. I meant for the
command to do a full reindexing of th repo. This fixes that.
2023-03-12 22:08:31 -07:00
Martin von Zweigbergk
63b3c0899a index: make jj debug reindex actually reindex
I broke `jj debug reindex` in a27da7d8d5. From that commit, we no
longer delete the pointer to the old index, so nothing happens when we
reload the index. This commit fixes that, and also makes the command
error out if run on a repo with a non-default index type.
2023-03-12 03:23:59 -07:00
Martin von Zweigbergk
ff1b6ce3d1 index: extract a MutableIndex trait
This is yet another step towards making the index pluggable. The
`IndexStore` trait seems reasonable after this commit. There's still a
lot of work to remove `IndexPosition` from the `Index` trait.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
b02fac7786 index: drop pub keyword from functions on private types
It has no effect, and these functions were not meant to be public.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
65a6353f06 index: stop implementing Index trait on wrapper type
Since `ReadonlyIndex` and `Index` are different types, we don't need
to implement `Index` on `ReadonlyIndexWrapper`.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
2eab85964a index: extract a ReadonlyIndex trait
I didn't make `ReadonlyIndex` extend `Index` because it needed an
`as_index()` to convert to `&dyn Index` trait object
anyway. Separating the types also gives us flexibility to implement
the two traits on different types.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
d2457d3f38 index: wrap ReadonlyIndex in new type, hiding Arc
Not all index implementations may want to store the readonly index
implementation in an Arc. Exposing the Arc in the interface is also
problematic because `Arc<IndexImpl>` cannot be cast to `Arc<dyn
Index>`.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
6ab8d9d0d0 index: merge index_store.rs into index.rs
These two files are closely related, and `Index` and `IndexStore` are
expected to be customized together, so it seems better to keep them in
a single file.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
e5ba9d9e42 index: move current implementation to default_index_store.rs
The idea is that `index.rs` contains the interface, similar to
`backend.rs` for commits, and `op_store.rs` for operations.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
8fc2062a38 index: move DefaultIndexStore to new default_index_store.rs 2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
37151e0ff9 index: load store based on type recorded in .jj/repo/index/type
This is another step towards allowing a custom `jj` binary to have its
own index type. We're going to have a server-backed index
implementation at Google, for example.
2023-03-11 22:22:46 -08:00
Martin von Zweigbergk
3e4e0dc916 index_store: extract trait
This is a step towards making the index storage pluggable. The
interface will probably change a bit soon, but let's start with
functions that match the current implementation.

I called the current implementation the `DefaultIndexStore`. Calling
it `SimpleIndexStore` (like `SimpleOpStore` and `SimpleOpHeadsStore`)
didn't seem accurate.
2023-03-11 22:22:46 -08:00
dependabot[bot]
4e7430a81a cargo: bump pest_derive from 2.5.5 to 2.5.6
Bumps [pest_derive](https://github.com/pest-parser/pest) from 2.5.5 to 2.5.6.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.5...v2.5.6)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-07 17:32:21 +01:00
dependabot[bot]
7da0994d58 cargo: bump thiserror from 1.0.38 to 1.0.39
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.38 to 1.0.39.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/1.0.38...1.0.39)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-06 18:48:04 +00:00
dependabot[bot]
ee7b9dc030 cargo: bump serde_json from 1.0.93 to 1.0.94
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.93 to 1.0.94.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.93...v1.0.94)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-06 10:26:35 -08:00
dependabot[bot]
1656117e6a cargo: bump pest from 2.5.5 to 2.5.6
Bumps [pest](https://github.com/pest-parser/pest) from 2.5.5 to 2.5.6.
- [Release notes](https://github.com/pest-parser/pest/releases)
- [Commits](https://github.com/pest-parser/pest/compare/v2.5.5...v2.5.6)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-06 10:20:09 -08:00
Samuel Tardieu
616058c2fa lib: add Commit::is_discardable() 2023-03-05 23:50:20 +01:00
Yuya Nishihara
8f9bc4e7a6 revset: ignore all ascii whitespace characters 2023-03-04 00:01:54 +09:00
Martin von Zweigbergk
ba94f58d7e index_store: remove unused reinit() function 2023-03-02 12:33:11 -08:00
Martin von Zweigbergk
94bdbb7ff7 index: make IndexStore factory functions take &Path
This is just for consistency with the other backends.
2023-03-02 12:33:11 -08:00
Martin von Zweigbergk
da1c259211 index_store: use custom error type for write errors
Public APIs should use custom error types (not `io::Error` as
here). The caller isn't affected by this commit because it just
unwraps the error.
2023-03-02 12:33:11 -08:00
Martin von Zweigbergk
2cc15f40ef store: remove obsolete comment about root commit
The commit backends are responsible defining the root commit since
5ab2854df6.
2023-03-02 12:33:11 -08:00
Samuel Tardieu
d4b13d7495 git: use our own default refspec 2023-03-02 10:09:08 +01:00
Samuel Tardieu
5ecdeed606 git: only consider references matching globs when fetching 2023-03-02 10:09:08 +01:00
Samuel Tardieu
182919ff6f git: add function to import a selection of the git refs 2023-03-02 10:09:08 +01:00
Samuel Tardieu
0ca4e2dad2 git: absence of globs is None rather than &[]
In `git_fetch()`, any glob present in `globs` is an "allow" mark. Using
`&[]` to represent an "allow-all" may be misleading, as it could
indicate that no branch (only the git HEAD) should be fetched.

By using an `Option<&[&str]>`, it is clearer that `None` means that
all branches are fetched.
2023-03-02 10:09:08 +01:00
Samuel Tardieu
6fd65cca30 git: use &[&str] instead of &[String]
Using &[String] forces the caller to materalize owned strings if they
have only references, which is costly. Using &[&str] makes it cheap
if the caller owns strings as well.
2023-03-02 10:09:08 +01:00
Martin von Zweigbergk
bbd6ef0c7b revset: remove filter_by_diff(), have caller intersect expression
To be able to make e.g. `jj log some/path` perform well on cloud-based
repos, a custom revset engine needs to be able to see the paths to
filter by. That way it is able pass those to a server-side index. This
commit helps with that by effectively converting `jj log -r foo
some/path` into `jj log -r 'foo & file(some/path)'`.
2023-02-28 17:45:34 -08:00
dependabot[bot]
26597ba61a cargo: bump prost-build from 0.11.7 to 0.11.8
Bumps [prost-build](https://github.com/tokio-rs/prost) from 0.11.7 to 0.11.8.
- [Release notes](https://github.com/tokio-rs/prost/releases)
- [Commits](https://github.com/tokio-rs/prost/commits/v0.11.8)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-28 16:13:14 +00:00
Martin von Zweigbergk
fd6c7f3bb3 op_heads_store: let caller create initial operation
It makes the APIs much simpler if we don't have to pass in information
about the initial operation when we create the `OpHeadsStore`. It also
makes the alternative `OpHeadsStore` implementations simpler since we
move some logic into a shared location (`ReadonlyRepo::init()`).

This effectively undoes ec07104126. Maybe some further refactoring
made it possible to move it back as I'm doing in this commit?
2023-02-28 08:08:31 -08:00
dependabot[bot]
7de17ce4e7 cargo: bump tempfile from 3.3.0 to 3.4.0
Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.3.0 to 3.4.0.
- [Release notes](https://github.com/Stebalien/tempfile/releases)
- [Changelog](https://github.com/Stebalien/tempfile/blob/master/NEWS)
- [Commits](https://github.com/Stebalien/tempfile/commits)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-27 11:06:51 -08:00
dependabot[bot]
b34daa9423 cargo: bump prost from 0.11.7 to 0.11.8
Bumps [prost](https://github.com/tokio-rs/prost) from 0.11.7 to 0.11.8.
- [Release notes](https://github.com/tokio-rs/prost/releases)
- [Commits](https://github.com/tokio-rs/prost/commits/v0.11.8)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-27 10:59:19 -08:00