Commit 221aaf95 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Git: Fix matching submodule path setting

parent e460a8cb
Pipeline #218715 passed with stage
in 5 minutes and 15 seconds
......@@ -403,6 +403,10 @@ void GitWidget::setSubmodulesPaths()
p.append(QLatin1Char('/'));
}
}
// Sort by size so that we can early out on matching paths later.
std::sort(m_submodulePaths.begin(), m_submodulePaths.end(), [](const QString &l, const QString &r) {
return l.size() > r.size();
});
setActiveGitDir();
}
git->deleteLater();
......@@ -423,14 +427,11 @@ void GitWidget::setActiveGitDir()
int idx = 0;
int activeSubmoduleIdx = -1;
int maxMatchLen = 0;
QString path = av->document()->url().toLocalFile();
for (const auto &submodulePath : m_submodulePaths) {
if (path.indexOf(submodulePath) != -1) {
if (path.size() > maxMatchLen) {
maxMatchLen = path.size();
activeSubmoduleIdx = idx;
}
const QString path = av->document()->url().toLocalFile();
for (const auto &submodulePath : std::as_const(m_submodulePaths)) {
if (path.startsWith(submodulePath)) {
activeSubmoduleIdx = idx;
break;
}
idx++;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment