- Notifications
You must be signed in to change notification settings - Fork2.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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 thegit_str
here to avoid re-allocing agit_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 atdata->repo_path
, nottest_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 ofprettify
, we need only callpath_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 usingpath_to_dir
is the right way. This would acceptsafe.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.cindex 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. |
@ethomson I'd like to talk to you about libgit2, some open PRs and TortoiseGit. Would be nice if we could meet next year. |
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. issuelibgit2#6649).Signed-off-by: Sven Strickroth <email@cs-ware.de>
Signed-off-by: Sven Strickroth <email@cs-ware.de>
@ethomson |
Manually merged with a tweak - thanks again! |
This is also relevant for 1.7, right?! |
csware commentedJan 14, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@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 thiselse if
part if%(prefix)/
is not required.
Uh oh!
There was an error while loading.Please reload this page.
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)