summaryrefslogtreecommitdiff
path: root/src/plugins/git/gitclient.cpp
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2023-01-20 13:53:04 +0100
committerhjk <hjk@qt.io>2023-01-23 07:15:17 +0000
commit2336ff5570664dd278656d5362d749c3e84f85e3 (patch)
tree1366f46c59b3c4d8d06f50474bf141c34efaeb54 /src/plugins/git/gitclient.cpp
parentec28990dd57ccc3dc2022d8e3e3aed9ed0a6396e (diff)
downloadqt-creator-2336ff5570664dd278656d5362d749c3e84f85e3.tar.gz
Git: Some more FilePath proliferation
Change-Id: I8d3d97d0c7979d741a7da333f922ce93359afef8 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/git/gitclient.cpp')
-rw-r--r--src/plugins/git/gitclient.cpp69
1 files changed, 32 insertions, 37 deletions
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index c5a7f4cfbb..ac69d52689 100644
--- a/src/plugins/git/gitclient.cpp
+++ b/src/plugins/git/gitclient.cpp
@@ -774,17 +774,17 @@ FilePath GitClient::findRepositoryForDirectory(const FilePath &directory) const
return {};
}
-QString GitClient::findGitDirForRepository(const FilePath &repositoryDir) const
+FilePath GitClient::findGitDirForRepository(const FilePath &repositoryDir) const
{
- static QHash<FilePath, QString> repoDirCache;
- QString &res = repoDirCache[repositoryDir];
+ static QHash<FilePath, FilePath> repoDirCache;
+ FilePath &res = repoDirCache[repositoryDir];
if (!res.isEmpty())
return res;
- synchronousRevParseCmd(repositoryDir, "--git-dir", &res);
+ QString output;
+ synchronousRevParseCmd(repositoryDir, "--git-dir", &output);
- if (!QDir(res).isAbsolute())
- res.prepend(repositoryDir.toString() + '/');
+ res = repositoryDir.resolvePath(output);
return res;
}
@@ -1625,9 +1625,9 @@ QString GitClient::synchronousCurrentLocalBranch(const FilePath &workingDirector
if (result.result() == ProcessResult::FinishedWithSuccess) {
branch = result.cleanedStdOut().trimmed();
} else {
- const QString gitDir = findGitDirForRepository(workingDirectory);
- const QString rebaseHead = gitDir + "/rebase-merge/head-name";
- QFile head(rebaseHead);
+ const FilePath gitDir = findGitDirForRepository(workingDirectory);
+ const FilePath rebaseHead = gitDir / "rebase-merge/head-name";
+ QFile head(rebaseHead.toFSPathString());
if (head.open(QFile::ReadOnly))
branch = QString::fromUtf8(head.readLine()).trimmed();
}
@@ -2265,19 +2265,18 @@ QString GitClient::commandInProgressDescription(const FilePath &workingDirectory
GitClient::CommandInProgress GitClient::checkCommandInProgress(const FilePath &workingDirectory) const
{
- const QString gitDir = findGitDirForRepository(workingDirectory);
- if (QFile::exists(gitDir + "/MERGE_HEAD"))
+ const FilePath gitDir = findGitDirForRepository(workingDirectory);
+ if (gitDir.pathAppended("MERGE_HEAD").exists())
return Merge;
- else if (QFile::exists(gitDir + "/rebase-apply"))
+ if (gitDir.pathAppended("rebase-apply").exists())
return Rebase;
- else if (QFile::exists(gitDir + "/rebase-merge"))
+ if (gitDir.pathAppended("rebase-merge").exists())
return RebaseMerge;
- else if (QFile::exists(gitDir + "/REVERT_HEAD"))
+ if (gitDir.pathAppended("REVERT_HEAD").exists())
return Revert;
- else if (QFile::exists(gitDir + "/CHERRY_PICK_HEAD"))
+ if (gitDir.pathAppended("CHERRY_PICK_HEAD").exists())
return CherryPick;
- else
- return NoCommand;
+ return NoCommand;
}
void GitClient::continueCommandIfNeeded(const FilePath &workingDirectory, bool allowContinue)
@@ -2646,9 +2645,10 @@ bool GitClient::getCommitData(const FilePath &workingDirectory,
commitData.panelInfo.repository = repoDirectory;
- const QString gitDir = findGitDirForRepository(repoDirectory);
+ const FilePath gitDir = findGitDirForRepository(repoDirectory);
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;
}
@@ -2720,9 +2720,8 @@ bool GitClient::getCommitData(const FilePath &workingDirectory,
}
case SimpleCommit: {
bool authorFromCherryPick = false;
- QDir gitDirectory(gitDir);
// 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);
commitData.amendSHA1.clear();
}
@@ -2732,21 +2731,17 @@ bool GitClient::getCommitData(const FilePath &workingDirectory,
commitData.panelData.email = author.email;
}
// Commit: Get the commit template
- QString templateFilename = gitDirectory.absoluteFilePath("MERGE_MSG");
- if (!QFile::exists(templateFilename))
- templateFilename = gitDirectory.absoluteFilePath("SQUASH_MSG");
- if (!QFile::exists(templateFilename)) {
- FilePath templateName = FilePath::fromUserInput(
- readConfigValue(workingDirectory, "commit.template"));
- templateFilename = templateName.toString();
+ FilePath templateFile = gitDir / "MERGE_MSG";
+ if (!templateFile.exists())
+ templateFile = gitDir / "SQUASH_MSG";
+ if (!templateFile.exists()) {
+ templateFile = FilePath::fromUserInput(
+ readConfigValue(workingDirectory, "commit.template"));
}
- if (!templateFilename.isEmpty()) {
- // Make relative to repository
- const QFileInfo templateFileInfo(templateFilename);
- if (templateFileInfo.isRelative())
- templateFilename = repoDirectory.toString() + '/' + templateFilename;
+ if (!templateFile.isEmpty()) {
+ templateFile = repoDirectory.resolvePath(templateFile);
FileReader reader;
- if (!reader.fetch(Utils::FilePath::fromString(templateFilename), QIODevice::Text, errorMessage))
+ if (!reader.fetch(templateFile, QIODevice::Text, errorMessage))
return false;
*commitTemplate = QString::fromLocal8Bit(reader.data());
}
@@ -3237,9 +3232,9 @@ bool GitClient::synchronousMerge(const FilePath &workingDirectory, const QString
bool GitClient::canRebase(const FilePath &workingDirectory) const
{
- const QString gitDir = findGitDirForRepository(workingDirectory);
- if (QFileInfo::exists(gitDir + "/rebase-apply")
- || QFileInfo::exists(gitDir + "/rebase-merge")) {
+ const FilePath gitDir = findGitDirForRepository(workingDirectory);
+ if (gitDir.pathAppended("rebase-apply").exists()
+ || gitDir.pathAppended("rebase-merge").exists()) {
VcsOutputWindow::appendError(
Tr::tr("Rebase, merge or am is in progress. Finish "
"or abort it and then try again."));