-
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
Slightly improved heuristic to find the target root #24
Conversation
Thinking about it as a more general solution, considering that the files could be anywhere, there could be no common path at all, which would return |
I think the subdirectories shouldn't matter? The Like say:
It looks at "Subdir" and "Further" for "/Target", neither matches. So I think the modification needs to check the dirs whether they contain Target at a higher level, and then maybe use the longest path. I.e. instead of just doing I think the proposed patch is incorrect, as it would just always pick the longest subdir, regardless of whether it contains the name we are looking for. I.e. it fails this:
which currently works as expected |
Do you want to give this another try, or should I give it a shot? |
I agree the patch is incorrect, but your second example works: the directories array would contain
and since it looks for the longest path prefix (not just the longest path) it finds It fails when the target contains a file that is outside of its root directory, for example if
I'll try again with your suggestion of searching the longest path containing |
never mind, still wrong :) |
ok, I think it works now. I'm not too happy with how complicated it is but I couldn't find a way to simplify it. If you have a better idea feel free to take over. I also tweaked some of the printed messages that would have helped me to diagnose my problem. |
Use the longest path containing the target name
New patch that I think is clearer. |
Since I don't have any files in my target's root directory (only other subdirectories), the current heuristic can't find my sql file, because it only looks at those subdirectories, so it picks a random one (the first in the list).
I could work around it but moving a file there but I propose a new heuristic that solves the problem by finding the longest common path in the input files directories. Implementation inspired by Python's
os.path.commonpath()
.This is obviously doing a bit more work than before but I don't think it should cause a performance problem – most of the added work is sorting the directories, and I only sort them by string length.