Commit 0a963831 authored by Michal Humpula's avatar Michal Humpula

kateproject: add git submodule file listing

drawbacks:

* when opening files from submodules, kate will create the new project
  on demand as in main repository
* doesn't recognize the submodules of submodules

Closes: D12629
parent 2178e67a
......@@ -29,6 +29,7 @@
#include <QRegularExpression>
#include <QSet>
#include <QTime>
#include <QSettings>
KateProjectWorker::KateProjectWorker(const QString &baseDir, const QVariantMap &projectMap)
: QObject()
......@@ -246,31 +247,70 @@ QStringList KateProjectWorker::findFiles(const QDir &dir, const QVariantMap& fil
QStringList KateProjectWorker::filesFromGit(const QDir &dir, bool recursive)
{
QStringList relFiles = gitLsFiles(dir);
relFiles << gitSubmodulesFiles(dir);
QStringList files;
for (const QString &relFile : relFiles) {
if (!recursive && (relFile.indexOf(QStringLiteral("/")) != -1)) {
continue;
}
QProcess git;
git.setWorkingDirectory(dir.absolutePath());
files.append(dir.absolutePath() + QLatin1Char('/') + relFile);
}
return files;
}
QStringList KateProjectWorker::gitLsFiles(const QDir &dir)
{
QStringList files;
// git ls-files -z results a bytearray where each entry is \0-terminated.
// NOTE: Without -z, Umlauts such as "Der Bäcker/Das Brötchen.txt" do not work (#389415)
QStringList args;
args << QStringLiteral("ls-files") << QStringLiteral("-z") << QStringLiteral(".");
QProcess git;
git.setWorkingDirectory(dir.absolutePath());
git.start(QStringLiteral("git"), args);
if (!git.waitForStarted() || !git.waitForFinished()) {
return files;
}
// git ls-files -z results a bytearray where each entry is \0-terminated.
// NOTE: Without -z, Umlauts such as "Der Bäcker/Das Brötchen.txt" do not work (#389415)
const QList<QByteArray> byteArrayList = git.readAllStandardOutput().split('\0');
QStringList relFiles;
for (const QByteArray & byteArray : byteArrayList) {
relFiles << QString::fromUtf8(byteArray);
files << QString::fromUtf8(byteArray);
}
for (const QString &relFile : relFiles) {
if (!recursive && (relFile.indexOf(QStringLiteral("/")) != -1)) {
continue;
}
return files;
}
files.append(dir.absolutePath() + QLatin1Char('/') + relFile);
QStringList KateProjectWorker::gitSubmodulesFiles(const QDir &dir)
{
/**
* git submodule command gives little to use for reliable file listing
* so reading the .gitmodule file directly. After the module paths are found
* just treat the new repositories as the main one.
*/
QStringList files;
QString modulesPath = dir.filePath(QStringLiteral(".gitmodules"));
if (!QFile::exists(modulesPath)) {
return files;
}
QSettings config(modulesPath, QSettings::IniFormat);
for (const QString &module: config.childGroups()) {
QString path = config.value(module + QStringLiteral("/path")).toString();
QDir moduleDir = dir.filePath(path);
QStringList relFiles = gitLsFiles(moduleDir);
for (const QString &file: relFiles) {
files << path + QLatin1Char('/') + file;
}
}
return files;
......
......@@ -85,6 +85,9 @@ private:
QStringList filesFromDarcs(const QDir &dir, bool recursive);
QStringList filesFromDirectory(const QDir &dir, bool recursive, const QStringList &filters);
QStringList gitLsFiles(const QDir &dir);
QStringList gitSubmodulesFiles(const QDir &dir);
private:
/**
* our project, only as QObject, we only send messages back and forth!
......
Markdown is supported
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