forked from qt-creator/qt-creator
Merge branch 'master' of git@scm.dev.nokia.troll.no:creator/mainline
This commit is contained in:
@@ -20,7 +20,8 @@ HEADERS += gitplugin.h \
|
|||||||
gitversioncontrol.h \
|
gitversioncontrol.h \
|
||||||
gitsettings.h \
|
gitsettings.h \
|
||||||
branchdialog.h \
|
branchdialog.h \
|
||||||
branchmodel.h
|
branchmodel.h \
|
||||||
|
gitcommand.h
|
||||||
SOURCES += gitplugin.cpp \
|
SOURCES += gitplugin.cpp \
|
||||||
gitoutputwindow.cpp \
|
gitoutputwindow.cpp \
|
||||||
gitclient.cpp \
|
gitclient.cpp \
|
||||||
@@ -34,7 +35,8 @@ SOURCES += gitplugin.cpp \
|
|||||||
gitversioncontrol.cpp \
|
gitversioncontrol.cpp \
|
||||||
gitsettings.cpp \
|
gitsettings.cpp \
|
||||||
branchdialog.cpp \
|
branchdialog.cpp \
|
||||||
branchmodel.cpp
|
branchmodel.cpp \
|
||||||
|
gitcommand.cpp
|
||||||
FORMS += changeselectiondialog.ui \
|
FORMS += changeselectiondialog.ui \
|
||||||
settingspage.ui \
|
settingspage.ui \
|
||||||
gitsubmitpanel.ui \
|
gitsubmitpanel.ui \
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include "gitclient.h"
|
#include "gitclient.h"
|
||||||
|
#include "gitcommand.h"
|
||||||
|
|
||||||
#include "commitdata.h"
|
#include "commitdata.h"
|
||||||
#include "gitconstants.h"
|
#include "gitconstants.h"
|
||||||
@@ -49,7 +50,6 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <vcsbase/vcsbaseeditor.h>
|
#include <vcsbase/vcsbaseeditor.h>
|
||||||
|
|
||||||
#include <QtCore/QFuture>
|
|
||||||
#include <QtCore/QRegExp>
|
#include <QtCore/QRegExp>
|
||||||
#include <QtCore/QTemporaryFile>
|
#include <QtCore/QTemporaryFile>
|
||||||
#include <QtCore/QTime>
|
#include <QtCore/QTime>
|
||||||
@@ -61,7 +61,6 @@
|
|||||||
using namespace Git;
|
using namespace Git;
|
||||||
using namespace Git::Internal;
|
using namespace Git::Internal;
|
||||||
|
|
||||||
const char *const kGitCommand = "git";
|
|
||||||
const char *const kGitDirectoryC = ".git";
|
const char *const kGitDirectoryC = ".git";
|
||||||
const char *const kBranchIndicatorC = "# On branch";
|
const char *const kBranchIndicatorC = "# On branch";
|
||||||
|
|
||||||
@@ -186,19 +185,45 @@ VCSBase::VCSBaseEditor
|
|||||||
|
|
||||||
void GitClient::diff(const QString &workingDirectory,
|
void GitClient::diff(const QString &workingDirectory,
|
||||||
const QStringList &diffArgs,
|
const QStringList &diffArgs,
|
||||||
const QStringList &fileNames)
|
const QStringList &unstagedFileNames,
|
||||||
|
const QStringList &stagedFileNames)
|
||||||
{
|
{
|
||||||
if (Git::Constants::debug)
|
|
||||||
qDebug() << "diff" << workingDirectory << fileNames;
|
|
||||||
QStringList arguments;
|
|
||||||
arguments << QLatin1String("diff") << diffArgs << QLatin1String("--") << fileNames;
|
|
||||||
|
|
||||||
|
if (Git::Constants::debug)
|
||||||
|
qDebug() << "diff" << workingDirectory << unstagedFileNames << stagedFileNames;
|
||||||
|
|
||||||
|
const QString binary = QLatin1String(Constants::GIT_BINARY);
|
||||||
const QString kind = QLatin1String(Git::Constants::GIT_DIFF_EDITOR_KIND);
|
const QString kind = QLatin1String(Git::Constants::GIT_DIFF_EDITOR_KIND);
|
||||||
const QString title = tr("Git Diff");
|
const QString title = tr("Git Diff");
|
||||||
|
|
||||||
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, workingDirectory, true, "originalFileName", workingDirectory);
|
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, workingDirectory, true, "originalFileName", workingDirectory);
|
||||||
executeGit(workingDirectory, arguments, editor);
|
|
||||||
|
|
||||||
|
// Create a batch of 2 commands to be run after each other in case
|
||||||
|
// we have a mixture of staged/unstaged files as is the case
|
||||||
|
// when using the submit dialog.
|
||||||
|
GitCommand *command = createCommand(workingDirectory, editor);
|
||||||
|
// Directory diff?
|
||||||
|
if (unstagedFileNames.empty() && stagedFileNames.empty()) {
|
||||||
|
QStringList arguments;
|
||||||
|
arguments << QLatin1String("diff") << diffArgs;
|
||||||
|
m_plugin->outputWindow()->append(formatCommand(binary, arguments));
|
||||||
|
command->addJob(arguments);
|
||||||
|
} else {
|
||||||
|
// Files diff.
|
||||||
|
if (!unstagedFileNames.empty()) {
|
||||||
|
QStringList arguments;
|
||||||
|
arguments << QLatin1String("diff") << diffArgs << QLatin1String("--") << unstagedFileNames;
|
||||||
|
m_plugin->outputWindow()->append(formatCommand(binary, arguments));
|
||||||
|
command->addJob(arguments);
|
||||||
|
}
|
||||||
|
if (!stagedFileNames.empty()) {
|
||||||
|
QStringList arguments;
|
||||||
|
arguments << QLatin1String("diff") << QLatin1String("--cached") << diffArgs << QLatin1String("--") << stagedFileNames;
|
||||||
|
m_plugin->outputWindow()->append(formatCommand(binary, arguments));
|
||||||
|
command->addJob(arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
command->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::diff(const QString &workingDirectory,
|
void GitClient::diff(const QString &workingDirectory,
|
||||||
@@ -439,42 +464,47 @@ bool GitClient::synchronousShow(const QString &workingDirectory, const QString &
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Factory function to create an asynchronous command
|
||||||
void GitClient::executeGit(const QString &workingDirectory, const QStringList &arguments,
|
GitCommand *GitClient::createCommand(const QString &workingDirectory,
|
||||||
VCSBase::VCSBaseEditor* editor,
|
VCSBase::VCSBaseEditor* editor,
|
||||||
bool outputToWindow)
|
bool outputToWindow)
|
||||||
{
|
{
|
||||||
if (Git::Constants::debug)
|
if (Git::Constants::debug)
|
||||||
qDebug() << "executeGit" << workingDirectory << arguments << editor;
|
qDebug() << Q_FUNC_INFO << workingDirectory << editor;
|
||||||
|
|
||||||
GitOutputWindow *outputWindow = m_plugin->outputWindow();
|
GitOutputWindow *outputWindow = m_plugin->outputWindow();
|
||||||
outputWindow->append(formatCommand(QLatin1String(kGitCommand), arguments));
|
|
||||||
|
|
||||||
QProcess process;
|
|
||||||
ProjectExplorer::Environment environment = ProjectExplorer::Environment::systemEnvironment();
|
ProjectExplorer::Environment environment = ProjectExplorer::Environment::systemEnvironment();
|
||||||
|
|
||||||
if (m_settings.adoptPath)
|
if (m_settings.adoptPath)
|
||||||
environment.set(QLatin1String("PATH"), m_settings.path);
|
environment.set(QLatin1String("PATH"), m_settings.path);
|
||||||
|
|
||||||
GitCommand* command = new GitCommand();
|
GitCommand* command = new GitCommand(workingDirectory, environment);
|
||||||
if (outputToWindow) {
|
if (outputToWindow) {
|
||||||
if (!editor) { // assume that the commands output is the important thing
|
if (!editor) { // assume that the commands output is the important thing
|
||||||
connect(command, SIGNAL(outputText(QString)), this, SLOT(appendAndPopup(QString)));
|
|
||||||
connect(command, SIGNAL(outputData(QByteArray)), this, SLOT(appendDataAndPopup(QByteArray)));
|
connect(command, SIGNAL(outputData(QByteArray)), this, SLOT(appendDataAndPopup(QByteArray)));
|
||||||
} else {
|
} else {
|
||||||
connect(command, SIGNAL(outputText(QString)), outputWindow, SLOT(append(QString)));
|
|
||||||
connect(command, SIGNAL(outputData(QByteArray)), outputWindow, SLOT(appendData(QByteArray)));
|
connect(command, SIGNAL(outputData(QByteArray)), outputWindow, SLOT(appendData(QByteArray)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QTC_ASSERT(editor, /**/);
|
QTC_ASSERT(editor, /**/);
|
||||||
connect(command, SIGNAL(outputText(QString)), editor, SLOT(setPlainText(QString)));
|
|
||||||
connect(command, SIGNAL(outputData(QByteArray)), editor, SLOT(setPlainTextData(QByteArray)));
|
connect(command, SIGNAL(outputData(QByteArray)), editor, SLOT(setPlainTextData(QByteArray)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputWindow)
|
if (outputWindow)
|
||||||
connect(command, SIGNAL(errorText(QString)), this, SLOT(appendAndPopup(QString)));
|
connect(command, SIGNAL(errorText(QString)), this, SLOT(appendAndPopup(QString)));
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
command->execute(arguments, workingDirectory, environment);
|
// Execute a single command
|
||||||
|
void GitClient::executeGit(const QString &workingDirectory,
|
||||||
|
const QStringList &arguments,
|
||||||
|
VCSBase::VCSBaseEditor* editor,
|
||||||
|
bool outputToWindow)
|
||||||
|
{
|
||||||
|
m_plugin->outputWindow()->append(formatCommand(QLatin1String(Constants::GIT_BINARY), arguments));
|
||||||
|
GitCommand *command = createCommand(workingDirectory, editor, outputToWindow);
|
||||||
|
command->addJob(arguments);
|
||||||
|
command->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::appendDataAndPopup(const QByteArray &data)
|
void GitClient::appendDataAndPopup(const QByteArray &data)
|
||||||
@@ -497,7 +527,7 @@ bool GitClient::synchronousGit(const QString &workingDirectory,
|
|||||||
{
|
{
|
||||||
if (Git::Constants::debug)
|
if (Git::Constants::debug)
|
||||||
qDebug() << "synchronousGit" << workingDirectory << arguments;
|
qDebug() << "synchronousGit" << workingDirectory << arguments;
|
||||||
const QString binary = QLatin1String(kGitCommand);
|
const QString binary = QLatin1String(Constants::GIT_BINARY);
|
||||||
|
|
||||||
if (logCommandToWindow)
|
if (logCommandToWindow)
|
||||||
m_plugin->outputWindow()->append(formatCommand(binary, arguments));
|
m_plugin->outputWindow()->append(formatCommand(binary, arguments));
|
||||||
@@ -973,67 +1003,3 @@ void GitClient::setSettings(const GitSettings &s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------ GitCommand
|
|
||||||
GitCommand::GitCommand()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
GitCommand::~GitCommand()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void GitCommand::execute(const QStringList &arguments,
|
|
||||||
const QString &workingDirectory,
|
|
||||||
const ProjectExplorer::Environment &environment)
|
|
||||||
{
|
|
||||||
if (Git::Constants::debug)
|
|
||||||
qDebug() << "GitCommand::execute" << workingDirectory << arguments;
|
|
||||||
|
|
||||||
// For some reason QtConcurrent::run() only works on this
|
|
||||||
QFuture<void> task = QtConcurrent::run(this, &GitCommand::run
|
|
||||||
, arguments
|
|
||||||
, workingDirectory
|
|
||||||
, environment);
|
|
||||||
QString taskName = QLatin1String("Git ") + arguments[0];
|
|
||||||
|
|
||||||
Core::ICore *core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>();
|
|
||||||
core->progressManager()->addTask(task, taskName
|
|
||||||
, QLatin1String("Git.action")
|
|
||||||
, Core::ProgressManager::CloseOnSuccess);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GitCommand::run(const QStringList &arguments,
|
|
||||||
const QString &workingDirectory,
|
|
||||||
const ProjectExplorer::Environment &environment)
|
|
||||||
{
|
|
||||||
if (Git::Constants::debug)
|
|
||||||
qDebug() << "GitCommand::run" << workingDirectory << arguments;
|
|
||||||
QProcess process;
|
|
||||||
if (!workingDirectory.isEmpty())
|
|
||||||
process.setWorkingDirectory(workingDirectory);
|
|
||||||
|
|
||||||
ProjectExplorer::Environment env = environment;
|
|
||||||
if (env.toStringList().isEmpty())
|
|
||||||
env = ProjectExplorer::Environment::systemEnvironment();
|
|
||||||
process.setEnvironment(env.toStringList());
|
|
||||||
|
|
||||||
process.start(QLatin1String(kGitCommand), arguments);
|
|
||||||
if (!process.waitForFinished()) {
|
|
||||||
emit errorText(QLatin1String("Error: Git timed out"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QByteArray output = process.readAllStandardOutput();
|
|
||||||
if (output.isEmpty()) {
|
|
||||||
if (arguments.at(0) == QLatin1String("diff"))
|
|
||||||
emit outputText(tr("The file does not differ from HEAD"));
|
|
||||||
} else {
|
|
||||||
emit outputData(output);
|
|
||||||
}
|
|
||||||
const QByteArray error = process.readAllStandardError();
|
|
||||||
if (!error.isEmpty())
|
|
||||||
emit errorText(QString::fromLocal8Bit(error));
|
|
||||||
|
|
||||||
// As it is used asynchronously, we need to delete ourselves
|
|
||||||
this->deleteLater();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
#include <coreplugin/iversioncontrol.h>
|
#include <coreplugin/iversioncontrol.h>
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <projectexplorer/environment.h>
|
|
||||||
|
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
@@ -79,7 +78,8 @@ public:
|
|||||||
static QString findRepositoryForDirectory(const QString &dir);
|
static QString findRepositoryForDirectory(const QString &dir);
|
||||||
|
|
||||||
void diff(const QString &workingDirectory, const QStringList &diffArgs, const QString &fileName);
|
void diff(const QString &workingDirectory, const QStringList &diffArgs, const QString &fileName);
|
||||||
void diff(const QString &workingDirectory, const QStringList &diffArgs, const QStringList &fileNames);
|
void diff(const QString &workingDirectory, const QStringList &diffArgs,
|
||||||
|
const QStringList &unstagedFileNames, const QStringList &stagedFileNames= QStringList());
|
||||||
|
|
||||||
void status(const QString &workingDirectory);
|
void status(const QString &workingDirectory);
|
||||||
void log(const QString &workingDirectory, const QString &fileName);
|
void log(const QString &workingDirectory, const QString &fileName);
|
||||||
@@ -154,6 +154,9 @@ private:
|
|||||||
const char *registerDynamicProperty,
|
const char *registerDynamicProperty,
|
||||||
const QString &dynamicPropertyValue) const;
|
const QString &dynamicPropertyValue) const;
|
||||||
|
|
||||||
|
GitCommand *createCommand(const QString &workingDirectory,
|
||||||
|
VCSBase::VCSBaseEditor* editor = 0,
|
||||||
|
bool outputToWindow = false);
|
||||||
|
|
||||||
void executeGit(const QString &workingDirectory,
|
void executeGit(const QString &workingDirectory,
|
||||||
const QStringList &arguments,
|
const QStringList &arguments,
|
||||||
@@ -175,24 +178,6 @@ private:
|
|||||||
GitSettings m_settings;
|
GitSettings m_settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GitCommand : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
GitCommand();
|
|
||||||
~GitCommand();
|
|
||||||
void execute(const QStringList &arguments,
|
|
||||||
const QString &workingDirectory,
|
|
||||||
const ProjectExplorer::Environment &environment);
|
|
||||||
void run(const QStringList &arguments,
|
|
||||||
const QString &workingDirectory,
|
|
||||||
const ProjectExplorer::Environment &environment);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void outputData(const QByteArray&);
|
|
||||||
void outputText(const QString&);
|
|
||||||
void errorText(const QString&);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Git
|
} // namespace Git
|
||||||
|
|||||||
138
src/plugins/git/gitcommand.cpp
Normal file
138
src/plugins/git/gitcommand.cpp
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
**
|
||||||
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** Non-Open Source Usage
|
||||||
|
**
|
||||||
|
** Licensees may use this file in accordance with the Qt Beta Version
|
||||||
|
** License Agreement, Agreement version 2.2 provided with the Software or,
|
||||||
|
** alternatively, in accordance with the terms contained in a written
|
||||||
|
** agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
**
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU General
|
||||||
|
** Public License versions 2.0 or 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the packaging
|
||||||
|
** of this file. Please review the following information to ensure GNU
|
||||||
|
** General Public Licensing requirements will be met:
|
||||||
|
**
|
||||||
|
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
||||||
|
** http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt GPL Exception
|
||||||
|
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "gitcommand.h"
|
||||||
|
#include "gitconstants.h"
|
||||||
|
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
|
|
||||||
|
#include <QtCore/QDebug>
|
||||||
|
#include <QtCore/QProcess>
|
||||||
|
#include <QtCore/QFuture>
|
||||||
|
#include <QtCore/QtConcurrentRun>
|
||||||
|
|
||||||
|
namespace Git {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
// Convert environment to list, default to system one.
|
||||||
|
static inline QStringList environmentToList(const ProjectExplorer::Environment &environment)
|
||||||
|
{
|
||||||
|
const QStringList list = environment.toStringList();
|
||||||
|
if (!list.empty())
|
||||||
|
return list;
|
||||||
|
return ProjectExplorer::Environment::systemEnvironment().toStringList();
|
||||||
|
}
|
||||||
|
|
||||||
|
GitCommand::Job::Job(const QStringList &a) :
|
||||||
|
arguments(a)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
GitCommand::GitCommand(const QString &workingDirectory,
|
||||||
|
ProjectExplorer::Environment &environment) :
|
||||||
|
m_workingDirectory(workingDirectory),
|
||||||
|
m_environment(environmentToList(environment))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GitCommand::addJob(const QStringList &arguments)
|
||||||
|
{
|
||||||
|
m_jobs.push_back(Job(arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GitCommand::execute()
|
||||||
|
{
|
||||||
|
if (Git::Constants::debug)
|
||||||
|
qDebug() << "GitCommand::execute" << m_workingDirectory << m_jobs.size();
|
||||||
|
|
||||||
|
if (m_jobs.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// For some reason QtConcurrent::run() only works on this
|
||||||
|
QFuture<void> task = QtConcurrent::run(this, &GitCommand::run);
|
||||||
|
const QString taskName = QLatin1String("Git ") + m_jobs.front().arguments.at(0);
|
||||||
|
|
||||||
|
Core::ICore *core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>();
|
||||||
|
core->progressManager()->addTask(task, taskName,
|
||||||
|
QLatin1String("Git.action"),
|
||||||
|
Core::ProgressManager::CloseOnSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GitCommand::run()
|
||||||
|
{
|
||||||
|
if (Git::Constants::debug)
|
||||||
|
qDebug() << "GitCommand::run" << m_workingDirectory << m_jobs.size();
|
||||||
|
QProcess process;
|
||||||
|
if (!m_workingDirectory.isEmpty())
|
||||||
|
process.setWorkingDirectory(m_workingDirectory);
|
||||||
|
|
||||||
|
process.setEnvironment(m_environment);
|
||||||
|
|
||||||
|
QByteArray output;
|
||||||
|
QString error;
|
||||||
|
|
||||||
|
const int count = m_jobs.size();
|
||||||
|
bool ok = true;
|
||||||
|
for (int j = 0; j < count; j++) {
|
||||||
|
if (Git::Constants::debug)
|
||||||
|
qDebug() << "GitCommand::run" << j << '/' << count << m_jobs.at(j).arguments;
|
||||||
|
|
||||||
|
process.start(QLatin1String(Constants::GIT_BINARY), m_jobs.at(j).arguments);
|
||||||
|
if (!process.waitForFinished()) {
|
||||||
|
ok = false;
|
||||||
|
error += QLatin1String("Error: Git timed out");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
output += process.readAllStandardOutput();
|
||||||
|
error += QString::fromLocal8Bit(process.readAllStandardError());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special hack: Always produce output for diff
|
||||||
|
if (ok && output.isEmpty() && m_jobs.front().arguments.at(0) == QLatin1String("diff")) {
|
||||||
|
output += "The file does not differ from HEAD";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok && !output.isEmpty())
|
||||||
|
emit outputData(output);
|
||||||
|
|
||||||
|
if (!error.isEmpty())
|
||||||
|
emit errorText(error);
|
||||||
|
|
||||||
|
// As it is used asynchronously, we need to delete ourselves
|
||||||
|
this->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Git
|
||||||
79
src/plugins/git/gitcommand.h
Normal file
79
src/plugins/git/gitcommand.h
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator
|
||||||
|
**
|
||||||
|
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
|
**
|
||||||
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
||||||
|
**
|
||||||
|
**
|
||||||
|
** Non-Open Source Usage
|
||||||
|
**
|
||||||
|
** Licensees may use this file in accordance with the Qt Beta Version
|
||||||
|
** License Agreement, Agreement version 2.2 provided with the Software or,
|
||||||
|
** alternatively, in accordance with the terms contained in a written
|
||||||
|
** agreement between you and Nokia.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
**
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU General
|
||||||
|
** Public License versions 2.0 or 3.0 as published by the Free Software
|
||||||
|
** Foundation and appearing in the file LICENSE.GPL included in the packaging
|
||||||
|
** of this file. Please review the following information to ensure GNU
|
||||||
|
** General Public Licensing requirements will be met:
|
||||||
|
**
|
||||||
|
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
||||||
|
** http://www.gnu.org/copyleft/gpl.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Nokia gives you certain additional
|
||||||
|
** rights. These rights are described in the Nokia Qt GPL Exception
|
||||||
|
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef GITCOMMAND_H
|
||||||
|
#define GITCOMMAND_H
|
||||||
|
|
||||||
|
#include <projectexplorer/environment.h>
|
||||||
|
|
||||||
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
|
namespace Git {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class GitCommand : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit GitCommand(const QString &workingDirectory,
|
||||||
|
ProjectExplorer::Environment &environment);
|
||||||
|
|
||||||
|
|
||||||
|
void addJob(const QStringList &arguments);
|
||||||
|
void execute();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void run();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void outputData(const QByteArray&);
|
||||||
|
void errorText(const QString&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Job {
|
||||||
|
explicit Job(const QStringList &a);
|
||||||
|
|
||||||
|
QStringList arguments;
|
||||||
|
};
|
||||||
|
|
||||||
|
QStringList environment() const;
|
||||||
|
|
||||||
|
const QString m_workingDirectory;
|
||||||
|
const QStringList m_environment;
|
||||||
|
|
||||||
|
QList<Job> m_jobs;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Git
|
||||||
|
#endif // GITCOMMAND_H
|
||||||
@@ -47,6 +47,7 @@ const char * const GITSUBMITEDITOR_KIND = "Git Submit Editor";
|
|||||||
const char * const SUBMIT_CURRENT = "Nokia.Git.SubmitCurrentLog";
|
const char * const SUBMIT_CURRENT = "Nokia.Git.SubmitCurrentLog";
|
||||||
const char * const DIFF_SELECTED = "Nokia.Git.DiffSelectedFilesInLog";
|
const char * const DIFF_SELECTED = "Nokia.Git.DiffSelectedFilesInLog";
|
||||||
const char * const SUBMIT_MIMETYPE = "application/vnd.nokia.text.git.submit";
|
const char * const SUBMIT_MIMETYPE = "application/vnd.nokia.text.git.submit";
|
||||||
|
const char * const GIT_BINARY = "git";
|
||||||
|
|
||||||
const char * const DIFF_FILE_INDICATOR = "--- ";
|
const char * const DIFF_FILE_INDICATOR = "--- ";
|
||||||
enum { debug = 0 };
|
enum { debug = 0 };
|
||||||
|
|||||||
@@ -446,16 +446,9 @@ void GitPlugin::extensionsInitialized()
|
|||||||
m_projectExplorer = ExtensionSystem::PluginManager::instance()->getObject<ProjectExplorer::ProjectExplorerPlugin>();
|
m_projectExplorer = ExtensionSystem::PluginManager::instance()->getObject<ProjectExplorer::ProjectExplorerPlugin>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitPlugin::submitEditorDiffStaged(const QStringList &files)
|
void GitPlugin::submitEditorDiff(const QStringList &unstaged, const QStringList &staged)
|
||||||
{
|
{
|
||||||
if (!files.empty())
|
m_gitClient->diff(m_submitRepository, QStringList(), unstaged, staged);
|
||||||
m_gitClient->diff(m_submitRepository, QStringList(QLatin1String("--cached")), files);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GitPlugin::submitEditorDiffUnstaged(const QStringList &files)
|
|
||||||
{
|
|
||||||
if (!files.empty())
|
|
||||||
m_gitClient->diff(m_submitRepository, QStringList(), files);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitPlugin::diffCurrentFile()
|
void GitPlugin::diffCurrentFile()
|
||||||
@@ -638,8 +631,7 @@ Core::IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const Commit
|
|||||||
// mechanism. Disable them correctly.
|
// mechanism. Disable them correctly.
|
||||||
submitEditor->registerActions(m_undoAction, m_redoAction, m_submitCurrentAction, m_diffSelectedFilesAction);
|
submitEditor->registerActions(m_undoAction, m_redoAction, m_submitCurrentAction, m_diffSelectedFilesAction);
|
||||||
submitEditor->setCommitData(cd);
|
submitEditor->setCommitData(cd);
|
||||||
connect(submitEditor, SIGNAL(diffStaged(QStringList)), this, SLOT(submitEditorDiffStaged(QStringList)));
|
connect(submitEditor, SIGNAL(diff(QStringList,QStringList)), this, SLOT(submitEditorDiff(QStringList,QStringList)));
|
||||||
connect(submitEditor, SIGNAL(diffUnstaged(QStringList)), this, SLOT(submitEditorDiffUnstaged(QStringList)));
|
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,8 +108,7 @@ public slots:
|
|||||||
private slots:
|
private slots:
|
||||||
void diffCurrentFile();
|
void diffCurrentFile();
|
||||||
void diffCurrentProject();
|
void diffCurrentProject();
|
||||||
void submitEditorDiffUnstaged(const QStringList &);
|
void submitEditorDiff(const QStringList &unstaged, const QStringList &staged);
|
||||||
void submitEditorDiffStaged(const QStringList &);
|
|
||||||
void submitCurrentLog();
|
void submitCurrentLog();
|
||||||
void statusFile();
|
void statusFile();
|
||||||
void statusProject();
|
void statusProject();
|
||||||
|
|||||||
@@ -48,16 +48,14 @@ enum FileType { StagedFile , UnstagedFile, UntrackedFile };
|
|||||||
|
|
||||||
/* The problem with git is that no diff can be obtained to for a random
|
/* The problem with git is that no diff can be obtained to for a random
|
||||||
* multiselection of staged/unstaged files; it requires the --cached
|
* multiselection of staged/unstaged files; it requires the --cached
|
||||||
* option for staged files. So, we set the file list to
|
* option for staged files. So, we sort apart the diff file lists
|
||||||
* single selection and sort the files manual according to a type
|
* according to a type flag we add to the model. */
|
||||||
* flag we add to the model. */
|
|
||||||
|
|
||||||
GitSubmitEditor::GitSubmitEditor(const VCSBase::VCSBaseSubmitEditorParameters *parameters, QWidget *parent) :
|
GitSubmitEditor::GitSubmitEditor(const VCSBase::VCSBaseSubmitEditorParameters *parameters, QWidget *parent) :
|
||||||
VCSBaseSubmitEditor(parameters, new GitSubmitEditorWidget(parent)),
|
VCSBaseSubmitEditor(parameters, new GitSubmitEditorWidget(parent)),
|
||||||
m_model(0)
|
m_model(0)
|
||||||
{
|
{
|
||||||
setDisplayName(tr("Git Commit"));
|
setDisplayName(tr("Git Commit"));
|
||||||
setFileListSelectionMode(QAbstractItemView::SingleSelection);
|
|
||||||
connect(this, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(slotDiffSelected(QStringList)));
|
connect(this, SIGNAL(diffSelectedFiles(QStringList)), this, SLOT(slotDiffSelected(QStringList)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,22 +100,29 @@ void GitSubmitEditor::setCommitData(const CommitData &d)
|
|||||||
|
|
||||||
void GitSubmitEditor::slotDiffSelected(const QStringList &files)
|
void GitSubmitEditor::slotDiffSelected(const QStringList &files)
|
||||||
{
|
{
|
||||||
QList<QStandardItem *> fileRow = m_model->findRow(files.front(), fileNameColumn());
|
// Sort it apart into staged/unstaged files
|
||||||
if (fileRow.empty())
|
QStringList unstagedFiles;
|
||||||
return;
|
QStringList stagedFiles;
|
||||||
const FileType ft = static_cast<FileType>(fileRow.front()->data(FileTypeRole).toInt());
|
const int fileColumn = fileNameColumn();
|
||||||
|
const int rowCount = m_model->rowCount();
|
||||||
|
for (int r = 0; r < rowCount; r++) {
|
||||||
|
const QString fileName = m_model->item(r, fileColumn)->text();
|
||||||
|
if (files.contains(fileName)) {
|
||||||
|
const FileType ft = static_cast<FileType>(m_model->item(r, 0)->data(FileTypeRole).toInt());
|
||||||
switch (ft) {
|
switch (ft) {
|
||||||
case StagedFile:
|
case StagedFile:
|
||||||
emit diffStaged(files);
|
stagedFiles.push_back(fileName);
|
||||||
break;
|
break;
|
||||||
case UnstagedFile:
|
case UnstagedFile:
|
||||||
emit diffUnstaged(files);
|
unstagedFiles.push_back(fileName);
|
||||||
break;
|
break;
|
||||||
case UntrackedFile:
|
case UntrackedFile:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!unstagedFiles.empty() || !stagedFiles.empty())
|
||||||
|
emit diff(unstagedFiles, stagedFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
GitSubmitEditorPanelData GitSubmitEditor::panelData() const
|
GitSubmitEditorPanelData GitSubmitEditor::panelData() const
|
||||||
|
|||||||
@@ -59,8 +59,7 @@ public:
|
|||||||
GitSubmitEditorPanelData panelData() const;
|
GitSubmitEditorPanelData panelData() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void diffStaged(const QStringList &);
|
void diff(const QStringList &unstagedFiles, const QStringList &stagedFiles);
|
||||||
void diffUnstaged(const QStringList &);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void slotDiffSelected(const QStringList &);
|
void slotDiffSelected(const QStringList &);
|
||||||
|
|||||||
@@ -87,14 +87,16 @@ Environment::Environment(QStringList env)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Environment::toStringList()
|
QStringList Environment::toStringList() const
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
QMap<QString, QString>::const_iterator it, end;
|
const QMap<QString, QString>::const_iterator end = m_values.constEnd();
|
||||||
end = m_values.constEnd();
|
for (QMap<QString, QString>::const_iterator it = m_values.constBegin(); it != end; ++it) {
|
||||||
for (it = m_values.constBegin(); it != end; ++it)
|
QString entry = it.key();
|
||||||
result<<(it.key() + "=" + it.value());
|
entry += QLatin1Char('=');
|
||||||
|
entry += it.value();
|
||||||
|
result.push_back(entry);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public:
|
|||||||
explicit Environment(QStringList env);
|
explicit Environment(QStringList env);
|
||||||
static Environment systemEnvironment();
|
static Environment systemEnvironment();
|
||||||
|
|
||||||
QStringList toStringList();
|
QStringList toStringList() const;
|
||||||
QString value(const QString &key) const;
|
QString value(const QString &key) const;
|
||||||
void set(const QString &key, const QString &value);
|
void set(const QString &key, const QString &value);
|
||||||
void unset(const QString &key);
|
void unset(const QString &key);
|
||||||
|
|||||||
Reference in New Issue
Block a user