Commit graph

29 commits

Author SHA1 Message Date
Yuya Nishihara
b3fa9e5b6c matchers: rename Dirs to RepoPathTree as it no longer represents directory 2022-12-30 14:15:27 +09:00
Yuya Nishihara
4f875ff9b7 matchers: leverage Dirs tree to test prefix matches, no .to_vec() in loop
No special case for prefix.is_root() is needed since the root entry can
also be flagged as a file.
2022-12-30 14:15:27 +09:00
Yuya Nishihara
996ac22921 matchers: simplify FilesMatcher::new() to take slice of paths 2022-12-30 14:15:27 +09:00
Yuya Nishihara
c7eaee3d86 matchers: remove redundant files set from FilesMatcher, use Dirs 2022-12-30 14:15:27 +09:00
Yuya Nishihara
2fb0363c03 matchers: add method to create visit sets from Dirs, remove separate getters
We might also want to eliminate .collect()/clone() here, but that's not
considered yet.
2022-12-30 14:15:27 +09:00
Yuya Nishihara
ba632e6ef6 matchers: build tree of Dirs so prefix match works out of the box
A file entry is represented as a Dirs of is_file flag set. This might seem
odd at this point, but allows us to remove special case from PrefixMatcher.
PrefixMatcher::new(&[RepoPath::root()]) will set is_file to the root entry.
2022-12-30 14:15:27 +09:00
Martin von Zweigbergk
7f9a0a2820 cleanup: let new Clippy move variables into format strings
I ran an upgraded Clippy on the codebase. All the changes seem to be
about using variables directly in format strings instead of passing
them as separate arguments.
2022-12-14 21:30:58 -08:00
Martin von Zweigbergk
d8feed9be4 copyright: change from "Google LLC" to "The Jujutsu Authors"
Let's acknowledge everyone's contributions by replacing "Google LLC"
in the copyright header by "The Jujutsu Authors". If I understand
correctly, it won't have any legal effect, but maybe it still helps
reduce concerns from contributors (though I haven't heard any
concerns).

Google employees can read about Google's policy at
go/releasing/contributions#copyright.
2022-11-28 06:05:45 -10:00
Martin von Zweigbergk
b654a1fe84 cleanup: remove extern crate declarations
`extern crate` is no longer needed since edition 2018.
2022-09-21 22:24:09 -07:00
Josh Soref
0e26e4bac4 spelling: the
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2022-09-09 11:58:37 -07:00
Martin von Zweigbergk
e8e03880cf matchers: add IntersectionMatcher
I plan to use this matcher for some future `jj add` command (for
#323). The idea is that we'll do a path-restricted walk of the working
copy based on the intersection of the sparse patterns and any patterns
specified by the user. However, I think it will be useful before that,
for @arxanas's fsmonitor feature (#362).
2022-06-09 21:27:51 -07:00
Martin von Zweigbergk
4fda0f8b6a matchers: simplify DifferenceMatcher slightly
The new `Visit::Nothing` variant lets us more easily restructure
`DifferenceMatcher::visit()` to make it handle the case of not
removing anything. I think this makes the code a little clearer.
2022-06-09 21:27:51 -07:00
Martin von Zweigbergk
169261ca21 matchers: add a Visit::Nothing variant
I didn't initially create a `Visit::Nothing` variant because I was
worried that the fact that there then are two ways of expressing this
value (there's also `Visit::Specific` with empty sets). However, the
value is quite useful for pattern matching, so I'm now thinking it's
worth the risk.
2022-06-09 21:27:51 -07:00
Martin von Zweigbergk
cb0ab6b360 matchers: add composite matcher for differences (#52)
This adds a matcher that takes two input matchers and creates a new
matcher from them. The composite matcher matches paths matched by the
first matcher but not matched by the second matcher. I plan to use
this for sparse checkouts. They'll also be useful if we add support
for negative patterns to filter e.g. `jj files` by.
2022-04-26 14:52:17 -07:00
Martin von Zweigbergk
4c2c1fedff matchers: add a matcher not matching anything (#52)
It can be useful for at least testing purposes to have a matcher that
doesn't match any paths.
2022-04-26 14:52:17 -07:00
Martin von Zweigbergk
277b9bb08e matchers: let matchers indicate that directory matches recursively (#52)
Knowing that a matchers matches everything recursively from a certain
directory is useful for various optimizations. For example, it lets
you avoid visiting a directory if you're using a matcher with a
negative condition (so you return what does *not* match).
2022-04-26 14:52:17 -07:00
Martin von Zweigbergk
cce12261d8 matchers: add a matcher for path prefixes (#52)
It's useful to be able to match path prefixes for many commands,
e.g. to allow `jj restore src` to restore all files in under `src/`
(or a file called `src`). I also plan to use it for sparse checkouts.

We'll need to be able to match path prefixes
2022-02-06 14:49:22 -08:00
Martin von Zweigbergk
d49892431b matchers: make visit() return cloned sets instead of references
This is just to avoid the lifetime parameter. It was a premature
optimization to return a reference (we don't even use the matchers
yet, so it cloning these sets clearly doesn't show up in profiling).
2022-02-05 20:24:53 -08:00
Martin von Zweigbergk
4c416dd864 cleanup: let Clippy fix a bunch of warnings 2021-06-14 00:27:31 -07:00
Martin von Zweigbergk
dd4c47f373 tree: support filtering diff by matcher
This change teaches `Tree::diff()` to filter by a matcher. It only
filters the result so far; it does not restrict the tree walk to what
`Matcher::visit()` says is necessary yet. It also doesn't teach the
CLI to create a matcher and pass it in.
2021-06-09 16:26:58 -07:00
Martin von Zweigbergk
54f6165ef1 repo_path: replace remaining uses of DirRepoPath by RepoPath 2021-05-19 15:11:04 -07:00
Martin von Zweigbergk
5421251e72 repo_path: change representation of RepoPath to have only a list of components 2021-05-19 15:11:04 -07:00
Martin von Zweigbergk
c66990d3a3 repo_path: rename from() to from_internal_{,dir}_string()
Since `RepoPath` can be either a file or a directory, I made its name
not include `file`.
2021-05-19 15:11:04 -07:00
Martin von Zweigbergk
03ae1b747c repo_path: remove FileRepoPath in favor of just RepoPath
I had initially hoped that the type-safety provided by the separate
`FileRepoPath` and `DirRepoPath` types would help prevent bugs. I'm
not sure if it has prevented any bugs so far. It has turned out that
there are more cases than I had hoped where it's unknown whether a
path is for a directory or a file. One such example is for the path of
a conflict. Since it can be conflict between a directory and a file,
it doesn't make sense to use either. Instead we end up with quite a
bit of conversion between the types. I feel like they are not worth
the extra complexity. This patch therefore starts simplifying it by
replacing uses of `FileRepoPath` by `RepoPath`. `DirRepoPath` is a
little more complicated because its string form ends with a '/'. I'll
address that in separate patches.
2021-05-19 15:11:04 -07:00
Martin von Zweigbergk
b6038399f0 matchers: rename AlwaysMatcher to EverythingMatcher 2021-05-16 21:21:34 -07:00
Martin von Zweigbergk
c8f2de1ecc matchers: simplify tests using hashset! macro and improve coverage 2021-05-16 10:44:45 -07:00
Martin von Zweigbergk
13134bd5a4 cleanup: address warnings reported by new clippy version 2021-04-28 09:12:48 -07:00
Martin von Zweigbergk
a7f4f4cf5b rustfmt: configure to merge imports by module
Perhaps we should even set the config to "Item" to reduce merge conflicts.
2021-03-14 10:53:14 -07:00
Martin von Zweigbergk
6b1427cb46 import commit 0f15be02bf4012c116636913562691a0aaa7aed2 from my hg repo 2020-12-12 00:23:38 -08:00