Skip to content

worktree stack supports excludes #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 121 commits into from
Apr 30, 2022
Merged

worktree stack supports excludes #397

merged 121 commits into from
Apr 30, 2022

Conversation

Byron
Copy link
Member

@Byron Byron commented Apr 21, 2022

A way to obtain a set of attributes given a path, efficiently.

Each path we handle needs one lookup there during checkout, thus
it must be lazy and per thread.

git seems to implement it as stack which is efficient if similar paths are handled together,
and then drops information as it is no longer needed. This seems like the way to go
as we never have to optimize for random access.

Tasks

  • study existing dircache stack and see if it can be generalized
  • implement stack for git-ignore and use git-glob for matching and be sure dir-excludes work
  • gix repo exclude query

Byron added 30 commits April 21, 2022 11:25
It doesn't work as one would expect due to it wanting to match relative
paths only. Thus it's better to spare folks the surprise and instead
use `wildmatch()` directly. It works the same, but doesn't
have certain shortcuts which aren't needed for standard matches
anyway.
It caches as much as it can for each pattern list.

Many more tests are needed, but that will come in with
tests that compare git with our implementation.
Also allow to read from bytes directly, which happens if the file is
read from the index/odb.
Also it turns out that we can't really unify the pattern list creation
yet, unless we'd add parse errors to the trait which maybe is preferable
over duplicating some code.
…which haven't been covered by tests and which show that the current
implementation isn't sufficient.

It also makes clear that the match styles of git-attributes and
git-ignore are quite different.

It's unclear why, even though the way both algorithms work are
quite different. So have to take a step back and find a way
to figure it out.
The failing tests are due to shortcomings in git-glob pattern matching
right now.
…#301)

The stack-based matching is responsible for excluding entire directories
which is something the git-attributes based matching doesn't do.
Byron added 25 commits April 28, 2022 21:30
This way the original pattern can be reproduced on the fly without
actually storing it, saving one allocation.
…but it feels a little like a hack. Maybe this should tell us that
we need to reorganize code elsewhere?
Very similar to `string()`, but as path, whose query can never fail.
That way it's possible to call certain methods that take a separate
path buffer.
XDG home is still needs to be made accessible, along with a few other
improvements.
A lightweight, general purpose error to display permissions violations
that cause errors. This should make it useable across crates.
…ery` (#301)

Details are still to be fixed, and reading from stdin should be
implemented one day.

Issue right now is that the source path is normalized for some reason,
let's see where that happens.
If and only if it canonicalized the source path. That way, users will
still get a familiar path. This is due to `parent()` not operating
in the file system, which otherwise would be equivalent to `..`,
but that's not how we work.

Maybe we should overhaul the way this works to use `../` instead
and just 'absoluteize' the path later (std::path::absolute()) is
on the way for that.
It doesn't reproduce on a local VM though.
@Byron Byron merged commit 98da8ba into main Apr 30, 2022
@Byron Byron deleted the worktree-stack branch April 30, 2022 02:53
EliahKagan added a commit to EliahKagan/gitoxide that referenced this pull request Feb 15, 2025
The `to_unix_separators` and `to_windows_separators` functions in
`gix_path::convert` had TODO comments saying they should use the
`path-slash` crate "to handle escapes". These comments were added
as part of e4f4c4b (GitoxideLabs#397) but the context there and in the broader
related issue GitoxideLabs#301 does not seem to clarify the basis for this.

It is not really clear what handling escapes would entail here, and
it seems like there is not a way to do it without substantially
changing the interface of these conversion functions in `gix-path`,
which currently take a single argument representing a path and
return a single string-like value also representing a path. If
escape sequences appaer in the input to such a path conversion
function, it would not have a way to know if they are meant
literally or as escape sequences. (An analogous concern applies if
a function is to add escape sequences in its return value; it would
have no way to know if the caller expects them.)

Furthermore, while `path-slash` can convert some `\` paths to use
`/` instead, it does not appear to do anything related to handling
escape sequencs or distinguishing which occurrences of `\` or any
other character may be intended as part of an escape sequence.
Its documentation does prominently mention that `\` in escape
sequnces should not be converted to `/`:

> On Unix-like OS, the path separator is `/`. So any conversion is
> not necessary. But on Windows, the file path separator is `\`,
> and needs to be replaced with `/` for converting the paths to
> "slash paths". Of course, `\`s used for escaping characters
> should not be replaced.

But it looks like the part about `\` characters used for escaping
is meant as advice on how and when to use `path-slash`, rather than
meaning that `path-slash` would itself be able to distinguish
between `\` characters meant as directory separators and `\`
characters that perform quoting/escaping.
EliahKagan added a commit to EliahKagan/gitoxide that referenced this pull request Feb 15, 2025
The `to_unix_separators` and `to_windows_separators` functions in
`gix_path::convert` had TODO comments saying they should use the
`path-slash` crate "to handle escapes". These comments were added
as part of e4f4c4b (GitoxideLabs#397) but the context there and in the broader
related issue GitoxideLabs#301 does not seem to clarify the basis for this.

It is not really clear what handling escapes would entail here, and
it seems like there is not a way to do it without substantially
changing the interface of these conversion functions in `gix-path`,
which currently take a single argument representing a path and
return a single string-like value also representing a path. If
escape sequences appear in the input to such a path conversion
function, it would not have a way to know if they are meant
literally or as escape sequences. (An analogous concern applies if
a function is to add escape sequences in its return value; it would
have no way to know if the caller expects them.)

Furthermore, while `path-slash` can convert some `\` paths to use
`/` instead, it does not appear to do anything related to handling
escape sequences or distinguishing which occurrences of `\` or any
other character may be intended as part of an escape sequence. Its
documentation (https://docs.rs/path-slash/latest/path_slash/) does
prominently mention that `\` in escape sequences should not be
converted to `/`:

> On Unix-like OS, the path separator is `/`. So any conversion is
> not necessary. But on Windows, the file path separator is `\`,
> and needs to be replaced with `/` for converting the paths to
> "slash paths". Of course, `\`s used for escaping characters
> should not be replaced.

But it looks like the part about `\` characters used for escaping
is meant as advice on how and when to use `path-slash`, rather than
meaning that `path-slash` would itself be able to distinguish
between `\` characters meant as directory separators and `\`
characters that perform quoting/escaping.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant