Commit ca4efa4a authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Git: Speed up diff/show output



* Avoid calling git --version repeatedly
* Use VcsManager to find toplevel directory which does caching.

Task-number: QTCREATORBUG-6906
Change-Id: Ib9ba94751bbecac686a0e116baeded9b2f6f3d90
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent 928a4450
......@@ -113,7 +113,7 @@ QString BazaarEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) c
for (QTextBlock block = inBlock; block.isValid(); block = block.previous()) {
const QString line = block.text();
if (m_diffFileId.indexIn(line) != -1)
return findDiffFile(m_diffFileId.cap(1), BazaarPlugin::instance()->versionControl());
return findDiffFile(m_diffFileId.cap(1));
}
return QString();
}
......@@ -366,7 +366,7 @@ const char *GitClient::decorateOption = "--decorate";
QString GitClient::findRepositoryForDirectory(const QString &dir)
{
if (synchronousGitVersion(true) >= 0x010700) {
if (gitVersion(true) >= 0x010700) {
// Find a directory to run git in:
const QString root = QDir::rootPath();
const QString home = QDir::homePath();
......@@ -530,6 +530,7 @@ void GitClient::diff(const QString &workingDirectory,
connect(editor, SIGNAL(diffChunkReverted(VcsBase::DiffChunk)), argWidget, SLOT(executeCommand()));
editor->setRevertDiffChunkEnabled(true);
}
editor->setDiffBaseDirectory(workingDirectory);
GitFileDiffArgumentsWidget *argWidget = qobject_cast<GitFileDiffArgumentsWidget *>(editor->configurationWidget());
QStringList userDiffArgs = argWidget->arguments();
......@@ -556,6 +557,7 @@ void GitClient::diffBranch(const QString &workingDirectory,
editor = createVcsEditor(editorId, title, sourceFile, CodecSource, "BranchName", branchName,
new GitBranchDiffArgumentsWidget(this, workingDirectory,
diffArgs, branchName));
editor->setDiffBaseDirectory(workingDirectory);
GitBranchDiffArgumentsWidget *argWidget = qobject_cast<GitBranchDiffArgumentsWidget *>(editor->configurationWidget());
QStringList userDiffArgs = argWidget->arguments();
......@@ -683,6 +685,7 @@ void GitClient::show(const QString &source, const QString &id, const QStringList
const QFileInfo sourceFi(source);
const QString workDir = sourceFi.isDir() ? sourceFi.absoluteFilePath() : sourceFi.absolutePath();
editor->setDiffBaseDirectory(workDir);
executeGit(workDir, arguments, editor);
}
......@@ -1743,7 +1746,7 @@ bool GitClient::getCommitData(const QString &workingDirectory,
if (amend) {
// Amend: get last commit data as "SHA1@message".
QStringList args(QLatin1String("log"));
const QString format = synchronousGitVersion(true) > 0x010701 ?
const QString format = gitVersion(true) > 0x010701 ?
QLatin1String("%h@%B") :
QLatin1String("%h@%s%n%n%b");
args << QLatin1String("--max-count=1") << QLatin1String("--pretty=format:") + format;
......
......@@ -130,7 +130,7 @@ QString GitEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) cons
QString diffFileName = block.text();
if (diffFileName.startsWith(newFileIndicator)) {
diffFileName.remove(0, newFileIndicator.size());
return findDiffFile(diffFileName, GitPlugin::instance()->versionControl());
return findDiffFile(diffFileName);
}
}
return QString();
......
......@@ -110,7 +110,7 @@ QString MercurialEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock
QString diffFileName = block.text();
if (diffFileName.startsWith(newFileIndicator)) {
diffFileName.remove(0, newFileIndicator.size());
return findDiffFile(diffFileName, MercurialPlugin::instance()->versionControl());
return findDiffFile(diffFileName);
}
}
......
......@@ -134,7 +134,7 @@ QString SubversionEditor::fileNameFromDiffSpecification(const QTextBlock &inBloc
const int tabIndex = diffFileName.lastIndexOf(QLatin1Char('\t'));
if (tabIndex != -1)
diffFileName.truncate(tabIndex);
const QString rc = findDiffFile(diffFileName, SubversionPlugin::instance()->versionControl());
const QString rc = findDiffFile(diffFileName);
if (Subversion::Constants::debug)
qDebug() << Q_FUNC_INFO << diffFileName << rc << source();
return rc;
......
......@@ -39,10 +39,12 @@
#include "vcsbaseplugin.h"
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/ifile.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/vcsmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/editorconfiguration.h>
#include <projectexplorer/projectexplorer.h>
......@@ -1341,8 +1343,7 @@ QWidget *VcsBaseEditorWidget::configurationWidget() const
}
// Find the complete file from a diff relative specification.
QString VcsBaseEditorWidget::findDiffFile(const QString &f,
Core::IVersionControl *control /* = 0 */) const
QString VcsBaseEditorWidget::findDiffFile(const QString &f) const
{
// Check if file is absolute
const QFileInfo in(f);
......@@ -1366,11 +1367,14 @@ QString VcsBaseEditorWidget::findDiffFile(const QString &f,
return sourceFileInfo.absoluteFilePath();
QString topLevel;
if (control && control->managesDirectory(sourceDir, &topLevel)) {
const QFileInfo topLevelFileInfo(topLevel + slash + f);
if (topLevelFileInfo.isFile())
return topLevelFileInfo.absoluteFilePath();
}
Core::VcsManager *vcsManager = Core::ICore::vcsManager();
vcsManager->findVersionControlForDirectory(sourceDir, &topLevel); //
if (topLevel.isEmpty())
return QString();
const QFileInfo topLevelFileInfo(topLevel + slash + f);
if (topLevelFileInfo.isFile())
return topLevelFileInfo.absoluteFilePath();
}
// 3) Try working directory
......
......@@ -236,7 +236,7 @@ protected:
/* A helper that can be used to locate a file in a diff in case it
* is relative. Tries to derive the directory from base directory,
* source and version control. */
QString findDiffFile(const QString &f, Core::IVersionControl *control = 0) const;
QString findDiffFile(const QString &f) const;
virtual bool canApplyDiffChunk(const DiffChunk &dc) const;
// Revert a patch chunk. Default implementation uses patch.exe
......
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