forked from qt-creator/qt-creator
Git: Some more FilePath proliferation
Change-Id: I8d3d97d0c7979d741a7da333f922ce93359afef8 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -774,17 +774,17 @@ FilePath GitClient::findRepositoryForDirectory(const FilePath &directory) const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GitClient::findGitDirForRepository(const FilePath &repositoryDir) const
|
FilePath GitClient::findGitDirForRepository(const FilePath &repositoryDir) const
|
||||||
{
|
{
|
||||||
static QHash<FilePath, QString> repoDirCache;
|
static QHash<FilePath, FilePath> repoDirCache;
|
||||||
QString &res = repoDirCache[repositoryDir];
|
FilePath &res = repoDirCache[repositoryDir];
|
||||||
if (!res.isEmpty())
|
if (!res.isEmpty())
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
synchronousRevParseCmd(repositoryDir, "--git-dir", &res);
|
QString output;
|
||||||
|
synchronousRevParseCmd(repositoryDir, "--git-dir", &output);
|
||||||
|
|
||||||
if (!QDir(res).isAbsolute())
|
res = repositoryDir.resolvePath(output);
|
||||||
res.prepend(repositoryDir.toString() + '/');
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1625,9 +1625,9 @@ QString GitClient::synchronousCurrentLocalBranch(const FilePath &workingDirector
|
|||||||
if (result.result() == ProcessResult::FinishedWithSuccess) {
|
if (result.result() == ProcessResult::FinishedWithSuccess) {
|
||||||
branch = result.cleanedStdOut().trimmed();
|
branch = result.cleanedStdOut().trimmed();
|
||||||
} else {
|
} else {
|
||||||
const QString gitDir = findGitDirForRepository(workingDirectory);
|
const FilePath gitDir = findGitDirForRepository(workingDirectory);
|
||||||
const QString rebaseHead = gitDir + "/rebase-merge/head-name";
|
const FilePath rebaseHead = gitDir / "rebase-merge/head-name";
|
||||||
QFile head(rebaseHead);
|
QFile head(rebaseHead.toFSPathString());
|
||||||
if (head.open(QFile::ReadOnly))
|
if (head.open(QFile::ReadOnly))
|
||||||
branch = QString::fromUtf8(head.readLine()).trimmed();
|
branch = QString::fromUtf8(head.readLine()).trimmed();
|
||||||
}
|
}
|
||||||
@@ -2265,19 +2265,18 @@ QString GitClient::commandInProgressDescription(const FilePath &workingDirectory
|
|||||||
|
|
||||||
GitClient::CommandInProgress GitClient::checkCommandInProgress(const FilePath &workingDirectory) const
|
GitClient::CommandInProgress GitClient::checkCommandInProgress(const FilePath &workingDirectory) const
|
||||||
{
|
{
|
||||||
const QString gitDir = findGitDirForRepository(workingDirectory);
|
const FilePath gitDir = findGitDirForRepository(workingDirectory);
|
||||||
if (QFile::exists(gitDir + "/MERGE_HEAD"))
|
if (gitDir.pathAppended("MERGE_HEAD").exists())
|
||||||
return Merge;
|
return Merge;
|
||||||
else if (QFile::exists(gitDir + "/rebase-apply"))
|
if (gitDir.pathAppended("rebase-apply").exists())
|
||||||
return Rebase;
|
return Rebase;
|
||||||
else if (QFile::exists(gitDir + "/rebase-merge"))
|
if (gitDir.pathAppended("rebase-merge").exists())
|
||||||
return RebaseMerge;
|
return RebaseMerge;
|
||||||
else if (QFile::exists(gitDir + "/REVERT_HEAD"))
|
if (gitDir.pathAppended("REVERT_HEAD").exists())
|
||||||
return Revert;
|
return Revert;
|
||||||
else if (QFile::exists(gitDir + "/CHERRY_PICK_HEAD"))
|
if (gitDir.pathAppended("CHERRY_PICK_HEAD").exists())
|
||||||
return CherryPick;
|
return CherryPick;
|
||||||
else
|
return NoCommand;
|
||||||
return NoCommand;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::continueCommandIfNeeded(const FilePath &workingDirectory, bool allowContinue)
|
void GitClient::continueCommandIfNeeded(const FilePath &workingDirectory, bool allowContinue)
|
||||||
@@ -2646,9 +2645,10 @@ bool GitClient::getCommitData(const FilePath &workingDirectory,
|
|||||||
|
|
||||||
commitData.panelInfo.repository = repoDirectory;
|
commitData.panelInfo.repository = repoDirectory;
|
||||||
|
|
||||||
const QString gitDir = findGitDirForRepository(repoDirectory);
|
const FilePath gitDir = findGitDirForRepository(repoDirectory);
|
||||||
if (gitDir.isEmpty()) {
|
if (gitDir.isEmpty()) {
|
||||||
*errorMessage = Tr::tr("The repository \"%1\" is not initialized.").arg(repoDirectory.toString());
|
*errorMessage = Tr::tr("The repository \"%1\" is not initialized.")
|
||||||
|
.arg(repoDirectory.toUserOutput());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2720,9 +2720,8 @@ bool GitClient::getCommitData(const FilePath &workingDirectory,
|
|||||||
}
|
}
|
||||||
case SimpleCommit: {
|
case SimpleCommit: {
|
||||||
bool authorFromCherryPick = false;
|
bool authorFromCherryPick = false;
|
||||||
QDir gitDirectory(gitDir);
|
|
||||||
// For cherry-picked commit, read author data from the commit (but template from MERGE_MSG)
|
// For cherry-picked commit, read author data from the commit (but template from MERGE_MSG)
|
||||||
if (gitDirectory.exists(CHERRY_PICK_HEAD)) {
|
if (gitDir.pathAppended(CHERRY_PICK_HEAD).exists()) {
|
||||||
authorFromCherryPick = readDataFromCommit(repoDirectory, CHERRY_PICK_HEAD, commitData);
|
authorFromCherryPick = readDataFromCommit(repoDirectory, CHERRY_PICK_HEAD, commitData);
|
||||||
commitData.amendSHA1.clear();
|
commitData.amendSHA1.clear();
|
||||||
}
|
}
|
||||||
@@ -2732,21 +2731,17 @@ bool GitClient::getCommitData(const FilePath &workingDirectory,
|
|||||||
commitData.panelData.email = author.email;
|
commitData.panelData.email = author.email;
|
||||||
}
|
}
|
||||||
// Commit: Get the commit template
|
// Commit: Get the commit template
|
||||||
QString templateFilename = gitDirectory.absoluteFilePath("MERGE_MSG");
|
FilePath templateFile = gitDir / "MERGE_MSG";
|
||||||
if (!QFile::exists(templateFilename))
|
if (!templateFile.exists())
|
||||||
templateFilename = gitDirectory.absoluteFilePath("SQUASH_MSG");
|
templateFile = gitDir / "SQUASH_MSG";
|
||||||
if (!QFile::exists(templateFilename)) {
|
if (!templateFile.exists()) {
|
||||||
FilePath templateName = FilePath::fromUserInput(
|
templateFile = FilePath::fromUserInput(
|
||||||
readConfigValue(workingDirectory, "commit.template"));
|
readConfigValue(workingDirectory, "commit.template"));
|
||||||
templateFilename = templateName.toString();
|
|
||||||
}
|
}
|
||||||
if (!templateFilename.isEmpty()) {
|
if (!templateFile.isEmpty()) {
|
||||||
// Make relative to repository
|
templateFile = repoDirectory.resolvePath(templateFile);
|
||||||
const QFileInfo templateFileInfo(templateFilename);
|
|
||||||
if (templateFileInfo.isRelative())
|
|
||||||
templateFilename = repoDirectory.toString() + '/' + templateFilename;
|
|
||||||
FileReader reader;
|
FileReader reader;
|
||||||
if (!reader.fetch(Utils::FilePath::fromString(templateFilename), QIODevice::Text, errorMessage))
|
if (!reader.fetch(templateFile, QIODevice::Text, errorMessage))
|
||||||
return false;
|
return false;
|
||||||
*commitTemplate = QString::fromLocal8Bit(reader.data());
|
*commitTemplate = QString::fromLocal8Bit(reader.data());
|
||||||
}
|
}
|
||||||
@@ -3237,9 +3232,9 @@ bool GitClient::synchronousMerge(const FilePath &workingDirectory, const QString
|
|||||||
|
|
||||||
bool GitClient::canRebase(const FilePath &workingDirectory) const
|
bool GitClient::canRebase(const FilePath &workingDirectory) const
|
||||||
{
|
{
|
||||||
const QString gitDir = findGitDirForRepository(workingDirectory);
|
const FilePath gitDir = findGitDirForRepository(workingDirectory);
|
||||||
if (QFileInfo::exists(gitDir + "/rebase-apply")
|
if (gitDir.pathAppended("rebase-apply").exists()
|
||||||
|| QFileInfo::exists(gitDir + "/rebase-merge")) {
|
|| gitDir.pathAppended("rebase-merge").exists()) {
|
||||||
VcsOutputWindow::appendError(
|
VcsOutputWindow::appendError(
|
||||||
Tr::tr("Rebase, merge or am is in progress. Finish "
|
Tr::tr("Rebase, merge or am is in progress. Finish "
|
||||||
"or abort it and then try again."));
|
"or abort it and then try again."));
|
||||||
|
@@ -127,7 +127,7 @@ public:
|
|||||||
const VcsBase::CommandHandler &handler = {});
|
const VcsBase::CommandHandler &handler = {});
|
||||||
|
|
||||||
Utils::FilePath findRepositoryForDirectory(const Utils::FilePath &directory) const;
|
Utils::FilePath findRepositoryForDirectory(const Utils::FilePath &directory) const;
|
||||||
QString findGitDirForRepository(const Utils::FilePath &repositoryDir) const;
|
Utils::FilePath findGitDirForRepository(const Utils::FilePath &repositoryDir) const;
|
||||||
bool managesFile(const Utils::FilePath &workingDirectory, const QString &fileName) const;
|
bool managesFile(const Utils::FilePath &workingDirectory, const QString &fileName) const;
|
||||||
Utils::FilePaths unmanagedFiles(const Utils::FilePaths &filePaths) const;
|
Utils::FilePaths unmanagedFiles(const Utils::FilePaths &filePaths) const;
|
||||||
|
|
||||||
|
@@ -493,8 +493,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
FilePath trackFile(const FilePath &repository) override
|
FilePath trackFile(const FilePath &repository) override
|
||||||
{
|
{
|
||||||
const QString gitDir = m_client->findGitDirForRepository(repository);
|
const FilePath gitDir = m_client->findGitDirForRepository(repository);
|
||||||
return gitDir.isEmpty() ? FilePath() : FilePath::fromString(gitDir + "/HEAD");
|
return gitDir.isEmpty() ? FilePath() : gitDir / "HEAD";
|
||||||
}
|
}
|
||||||
|
|
||||||
QString refreshTopic(const FilePath &repository) override
|
QString refreshTopic(const FilePath &repository) override
|
||||||
|
Reference in New Issue
Block a user