forked from qt-creator/qt-creator
VCS[git]: Make version fail warning less obtrusive.
Display correct warning if git is not installed. Do not display it as error (popping up the log pane) from IVersionControl. Introduce separate caching flag to avoid repeated execution if git is not installed.
This commit is contained in:
@@ -132,7 +132,8 @@ GitClient::GitClient(GitPlugin* plugin)
|
||||
m_plugin(plugin),
|
||||
m_core(Core::ICore::instance()),
|
||||
m_repositoryChangedSignalMapper(0),
|
||||
m_cachedGitVersion(0)
|
||||
m_cachedGitVersion(0),
|
||||
m_hasCachedGitVersion(false)
|
||||
{
|
||||
if (QSettings *s = m_core->settings()) {
|
||||
m_settings.fromSettings(s);
|
||||
@@ -1021,16 +1022,24 @@ bool GitClient::synchronousGit(const QString &workingDirectory,
|
||||
process.setWorkingDirectory(workingDirectory);
|
||||
process.setEnvironment(processEnvironment());
|
||||
|
||||
QStringList args = binary();
|
||||
QStringList args = binary(); // "cmd /c git" on Windows
|
||||
const QString executable = args.front();
|
||||
args.pop_front();
|
||||
args.append(gitArguments);
|
||||
process.start(executable, args);
|
||||
process.closeWriteChannel();
|
||||
if (!process.waitForStarted()) {
|
||||
if (errorText) {
|
||||
const QString msg = QString::fromLatin1("Unable to execute '%1': %2:")
|
||||
.arg(binary().join(QString(QLatin1Char(' '))), process.errorString());
|
||||
*errorText = msg.toLocal8Bit();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!process.waitForFinished()) {
|
||||
if (errorText)
|
||||
*errorText = "Error: Git timed out";
|
||||
*errorText = "Error: Git timed out.";
|
||||
process.kill();
|
||||
return false;
|
||||
}
|
||||
@@ -1556,6 +1565,7 @@ void GitClient::setSettings(const GitSettings &s)
|
||||
m_settings.toSettings(s);
|
||||
m_binaryPath = m_settings.gitBinaryPath();
|
||||
m_cachedGitVersion = 0u;
|
||||
m_hasCachedGitVersion = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1573,16 +1583,20 @@ void GitClient::connectRepositoryChanged(const QString & repository, GitCommand
|
||||
}
|
||||
|
||||
// determine version as '(major << 16) + (minor << 8) + patch' or 0.
|
||||
unsigned GitClient::gitVersion(QString *errorMessage /* = 0 */)
|
||||
unsigned GitClient::gitVersion(bool silent, QString *errorMessage /* = 0 */)
|
||||
{
|
||||
if (!m_cachedGitVersion)
|
||||
m_cachedGitVersion = synchronousGitVersion(errorMessage);
|
||||
if (!m_hasCachedGitVersion) {
|
||||
// Do not execute repeatedly if that fails (due to git
|
||||
// not being installed) until settings are changed.
|
||||
m_cachedGitVersion = synchronousGitVersion(silent, errorMessage);
|
||||
m_hasCachedGitVersion = true;
|
||||
}
|
||||
return m_cachedGitVersion;
|
||||
}
|
||||
|
||||
QString GitClient::gitVersionString(QString *errorMessage)
|
||||
QString GitClient::gitVersionString(bool silent, QString *errorMessage)
|
||||
{
|
||||
if (const unsigned version = gitVersion(errorMessage)) {
|
||||
if (const unsigned version = gitVersion(silent, errorMessage)) {
|
||||
QString rc;
|
||||
QTextStream(&rc) << (version >> 16) << '.'
|
||||
<< (0xFF & (version >> 8)) << '.'
|
||||
@@ -1593,7 +1607,7 @@ QString GitClient::gitVersionString(QString *errorMessage)
|
||||
}
|
||||
|
||||
// determine version as '(major << 16) + (minor << 8) + patch' or 0.
|
||||
unsigned GitClient::synchronousGitVersion(QString *errorMessage /* = 0 */)
|
||||
unsigned GitClient::synchronousGitVersion(bool silent, QString *errorMessage /* = 0 */)
|
||||
{
|
||||
// run git --version
|
||||
QByteArray outputText;
|
||||
@@ -1603,9 +1617,13 @@ unsigned GitClient::synchronousGitVersion(QString *errorMessage /* = 0 */)
|
||||
const QString msg = tr("Unable to determine git version: %1").arg(commandOutputFromLocal8Bit(errorText));
|
||||
if (errorMessage) {
|
||||
*errorMessage = msg;
|
||||
} else {
|
||||
if (silent) {
|
||||
VCSBase::VCSBaseOutputWindow::instance()->append(msg);
|
||||
} else {
|
||||
VCSBase::VCSBaseOutputWindow::instance()->appendError(msg);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// cut 'git version 1.6.5.1.sha'
|
||||
|
||||
@@ -147,8 +147,8 @@ public:
|
||||
QString *branch = 0, QString *errorMessage = 0);
|
||||
// determine version as '(major << 16) + (minor << 8) + patch' or 0
|
||||
// with some smart caching.
|
||||
unsigned gitVersion(QString *errorMessage = 0);
|
||||
QString gitVersionString(QString *errorMessage = 0);
|
||||
unsigned gitVersion(bool silent, QString *errorMessage = 0);
|
||||
QString gitVersionString(bool silent, QString *errorMessage = 0);
|
||||
|
||||
void pull(const QString &workingDirectory);
|
||||
void push(const QString &workingDirectory);
|
||||
@@ -234,7 +234,7 @@ private:
|
||||
QByteArray* errorText = 0,
|
||||
bool logCommandToWindow = true);
|
||||
// determine version as '(major << 16) + (minor << 8) + patch' or 0.
|
||||
unsigned synchronousGitVersion(QString *errorMessage = 0);
|
||||
unsigned synchronousGitVersion(bool silent, QString *errorMessage = 0);
|
||||
|
||||
enum RevertResult { RevertOk, RevertUnchanged, RevertCanceled, RevertFailed };
|
||||
RevertResult revertI(QStringList files, bool *isDirectory, QString *errorMessage);
|
||||
@@ -247,6 +247,7 @@ private:
|
||||
QString m_binaryPath;
|
||||
QSignalMapper *m_repositoryChangedSignalMapper;
|
||||
unsigned m_cachedGitVersion;
|
||||
bool m_hasCachedGitVersion;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ QString GitVersionControl::displayName() const
|
||||
// Add: Implement using "git add --intent-to-add" starting from 1.6.1
|
||||
static inline bool addOperationSupported()
|
||||
{
|
||||
return gitClient()->gitVersion() >= version(1, 6, 1);
|
||||
return gitClient()->gitVersion(true) >= version(1, 6, 1);
|
||||
}
|
||||
|
||||
bool GitVersionControl::supportsOperation(Operation operation) const
|
||||
|
||||
Reference in New Issue
Block a user