-
Notifications
You must be signed in to change notification settings - Fork 12
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
refactor: migrate git2 to gix #121
Conversation
Signed-off-by: tison <wander4096@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for giving it a shot!
It really depends how many files this exclusion check is currently run on, as the version I see here probably won't be much faster than git2
, maybe even slower, I never tried.
If it's not slower, it might already be OK to keep it, as making this fast is going to need some refactoring. select_files_with_git()
should keep the state it needs on the stack, instead of putting it into a separate GitHelper
structure (it's not helping in this case). Taking the gix::Repository
directly should do the trick.
fmt/src/git.rs
Outdated
self.repo.is_path_ignored(path).context(GitOpSnafu) | ||
let mut stack = self | ||
.repo | ||
.excludes(&self.state, None, Source::default()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To not have to deal with the index, I suggested repo.worktree()?.excludes()
previously. Otherwise, the index can be opened with repo.index()?
.
However, doing this is no better, performance-wise, than git2
as it will have to do a lot of repetitive work each time the path is queried.
It's probably OK to keep it at first just to get it to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I found that the lifecycle mark make it hard to hold the AttributeStack and I'm trying to get rid of git2 first.
If we can make it work as better as current, we can make further improvements.
fmt/src/git.rs
Outdated
.map_err(Box::new) | ||
.context(GixExcludeOpSnafu)?; | ||
let result = stack | ||
.at_path(&path, Some(is_dir)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path
should be prefix-stripped with the worktree directory to become relative to it. gix
can't do that reliably and with the desired performance, as only the caller knows which root the input paths are relative to.
Without that knowledge, they need to be canonicalized which is very expensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I work it around with pathdiff
and pseudo code:
let path = path.canonicalize();
let workdir = self.repo.work_dir().canonicalize();
let at_path = pathdiff::diff_paths(path, workdir);
It works as expected now. But perhaps we can improve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When GitHelper
is gone, improving it will be quite straightforward I think.
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
Make sense. This code is ported from Java JNI one. So you know, a wrapper class/object is normal, lol. |
But I'm not quite familiar with "keep the state it needs on the stack". All things work well now. I'll try to reduce the Docker layer and merge this one. If you can give some hints how I can leverage gix better, I can give it a try. Or I'm glad to review/collaborate on a draft PR also.. |
I had a feeling this could be the case…😁. |
If it works for you as is, it's fine to merge for sure. I might just make the changes myself later to make it fast. |
Signed-off-by: tison <wander4096@gmail.com>
Thank you! I guess you mean flatten the git code from |
Merging... Thanks for your information again and "nudge" me to make it happen :D |
Yes, that's quite what I had in mind. Let me try a PR real quick. (It's here: #126) |
@Byron Thanks a lot for pointing me that we can check ignore with gix.
I'm still investigating how to get the
Platform
struct but draft here for further conversation.Said we'd like to call
AttributeStack::at_path
and thenPlatform::is_excluded
. The first lacking thing is how to get Attribute. I found:I can get a repository now, but have no ideas on the other params.
Also some issues I ever encountered with git2: