-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Do not normalize safe.directory paths #6668
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
Conversation
8c5ed29
to
9a2df4d
Compare
src/libgit2/repository.c
Outdated
|
||
if (git_fs_path_prettify_dir(&data->tmp, test_path, NULL) == 0 && | ||
strcmp(data->tmp.ptr, data->repo_path) == 0) | ||
git_str_sets(&tmp, data->repo_path); |
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.
We were passing the git_str
here to avoid re-allocing a git_str
on every call. We can just re-use the one we have. No need to undo that, I don't think.
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.
Also, you're looking at data->repo_path
, not test_path
, which we've mutated to handle WSL paths. We should keep that.
@@ -582,10 +582,14 @@ static int validate_ownership_cb(const git_config_entry *entry, void *payload) | |||
strncmp(test_path, "//wsl.localhost/", strlen("//wsl.localhost/")) != 0) | |||
test_path++; | |||
#endif | |||
|
|||
if (git_fs_path_prettify_dir(&data->tmp, test_path, NULL) == 0 && |
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 think that instead of prettify
, we need only call path_to_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.
I don't think that using path_to_dir
is the right way. This would accept safe.directory
entries ending with a slash which vanilla Git does not accept.
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.
Is that actually a problem, though? We also accept //wsl.localhost/...
prefixed paths which Git for Windows doesn't accept.
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.
From my point of view, I would keep it as consistent as possible.
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.
Let's do one fix at the time. It's ok for me if we take your suggested patch.
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.
From my point of view, I would keep it as consistent as possible.
OK. Let's do that. This feels like a (minor) bug in git that it doesn't allow trailing slashes, but I've often said that libgit2's goal is to be "bug for bug compatible".
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.
@ethomson
I updated the branch and hope that I did not forget anything.
Agree that we don't need to hit the filesystem on every excluded path. I think that the simplest fix is: diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c
index 05ece6efc..9fa616fb0 100644
--- a/src/libgit2/repository.c
+++ b/src/libgit2/repository.c
@@ -583,8 +583,11 @@ static int validate_ownership_cb(const git_config_entry *entry, void *payload)
test_path++;
#endif
- if (git_fs_path_prettify_dir(&data->tmp, test_path, NULL) == 0 &&
- strcmp(data->tmp.ptr, data->repo_path) == 0)
+ if (git_str_sets(&data->tmp, test_path) < 0 ||
+ git_fs_path_to_dir(&data->tmp) < 0)
+ return -1;
+
+ if (strcmp(data->tmp.ptr, data->repo_path) == 0)
*data->is_safe = true;
}
This keeps the This does not add the trailing |
Thanks @csware for digging in here to understand the perf problem - it's slow for me to develop / test on Windows - and apologies for causing it in the first place. |
9a2df4d
to
9586445
Compare
@ethomson I'd like to talk to you about libgit2, some open PRs and TortoiseGit. Would be nice if we could meet next year. |
9586445
to
4e5a980
Compare
Vanilla Git does not do it either (cf. https://github.com/gitster/git/blob/master/setup.c#L1150) and calling git_fs_path_prettify_dir can cause performance issues (cf. issue libgit2#6649). Signed-off-by: Sven Strickroth <email@cs-ware.de>
Signed-off-by: Sven Strickroth <email@cs-ware.de>
4e5a980
to
73f034c
Compare
@ethomson |
Manually merged with a tweak - thanks again! |
This is also relevant for 1.7, right?! |
@ethomson I don't quite understand your tweak either. Now more copies are needed, right? Particularly, I don't understand the comment regarding the backslash. |
@@ -582,9 +581,7 @@ static int validate_ownership_cb(const git_config_entry *entry, void *payload) | |||
strncmp(test_path, "//wsl.localhost/", strlen("//wsl.localhost/")) != 0) |
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.
Remove this else if
part if %(prefix)/
is not required.
Vanilla Git does not do it either (cf. https://github.com/gitster/git/blob/master/setup.c#L1150) and calling git_fs_path_prettify_dir can cause performance issues (cf. issue #6649).
Still needed: expansion of "~/"... (but not this PR)