Skip to content
Snippets Groups Projects
gitclient.cpp 87.6 KiB
Newer Older
/**************************************************************************
con's avatar
con committed
**
** This file is part of Qt Creator
**
con's avatar
con committed
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
**
hjk's avatar
hjk committed
** Contact: Nokia Corporation (info@qt.nokia.com)
con's avatar
con committed
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
con's avatar
con committed
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
** Nokia at info@qt.nokia.com.
con's avatar
con committed
**
**************************************************************************/
hjk's avatar
hjk committed

con's avatar
con committed
#include "gitclient.h"
#include "gitutils.h"
con's avatar
con committed
#include "commitdata.h"
hjk's avatar
hjk committed
#include "gitconstants.h"
#include "gitplugin.h"
#include "gitversioncontrol.h"
con's avatar
con committed

#include <coreplugin/actionmanager/actionmanager.h>
hjk's avatar
hjk committed
#include <coreplugin/coreconstants.h>
con's avatar
con committed
#include <coreplugin/editormanager/editormanager.h>
hjk's avatar
hjk committed
#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/filemanager.h>
#include <coreplugin/iversioncontrol.h>

con's avatar
con committed
#include <texteditor/itexteditor.h>
hjk's avatar
hjk committed
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/synchronousprocess.h>
#include <utils/fileutils.h>
Tobias Hunger's avatar
Tobias Hunger committed
#include <vcsbase/command.h>
hjk's avatar
hjk committed
#include <vcsbase/vcsbaseeditor.h>
#include <vcsbase/vcsbaseeditorparameterwidget.h>
#include <vcsbase/vcsbaseoutputwindow.h>
#include <vcsbase/vcsbaseplugin.h>
con's avatar
con committed

#include <QtCore/QRegExp>
#include <QtCore/QTemporaryFile>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/QSignalMapper>
con's avatar
con committed

#include <QtGui/QComboBox>
#include <QtGui/QMainWindow> // for msg box parent
hjk's avatar
hjk committed
#include <QtGui/QMessageBox>
#include <QtGui/QToolButton>
con's avatar
con committed

static const char kGitDirectoryC[] = ".git";
static const char kBranchIndicatorC[] = "# On branch";
con's avatar
con committed

namespace Git {
namespace Internal {

class BaseGitDiffArgumentsWidget : public VCSBase::VCSBaseEditorParameterWidget
Friedemann Kleint's avatar
Friedemann Kleint committed
    Q_OBJECT
public:
    BaseGitDiffArgumentsWidget(GitClient *client, const QString &directory,
                               const QStringList &args) :
        m_workingDirectory(directory),
        m_client(client),
        m_args(args)
        Q_ASSERT(!directory.isEmpty());
        Q_ASSERT(m_client);
        mapSetting(addToggleButton(QLatin1String("--patience"), tr("Patience"),
                                   tr("Use the patience algorithm for calculating the differences.")),
                   client->settings()->boolPointer(GitSettings::diffPatienceKey));
        mapSetting(addToggleButton("--ignore-space-change", tr("Ignore Whitespace"),
                                   tr("Ignore whitespace only changes.")),
                   m_client->settings()->boolPointer(GitSettings::ignoreSpaceChangesInDiffKey));
    QString m_workingDirectory;
    GitClient *m_client;
    QStringList m_args;
};

class GitCommitDiffArgumentsWidget : public BaseGitDiffArgumentsWidget
{
Friedemann Kleint's avatar
Friedemann Kleint committed
    Q_OBJECT
public:
    GitCommitDiffArgumentsWidget(Git::Internal::GitClient *client, const QString &directory,
                                 const QStringList &args, const QStringList &unstaged,
                                 const QStringList &staged) :
        BaseGitDiffArgumentsWidget(client, directory, args),
        m_unstagedFileNames(unstaged),
        m_stagedFileNames(staged)
    { }

    void executeCommand()
        m_client->diff(m_workingDirectory, m_args, m_unstagedFileNames, m_stagedFileNames);
    }

private:
    const QStringList m_unstagedFileNames;
    const QStringList m_stagedFileNames;
};

class GitFileDiffArgumentsWidget : public BaseGitDiffArgumentsWidget
{
Friedemann Kleint's avatar
Friedemann Kleint committed
    Q_OBJECT
public:
    GitFileDiffArgumentsWidget(Git::Internal::GitClient *client, const QString &directory,
                               const QStringList &args, const QString &file) :
        BaseGitDiffArgumentsWidget(client, directory, args),
        m_fileName(file)
    { }

    void executeCommand()
        m_client->diff(m_workingDirectory, m_args, m_fileName);
    }

private:
    const QString m_fileName;
};

class GitBranchDiffArgumentsWidget : public BaseGitDiffArgumentsWidget
{
Friedemann Kleint's avatar
Friedemann Kleint committed
    Q_OBJECT
public:
    GitBranchDiffArgumentsWidget(Git::Internal::GitClient *client, const QString &directory,
                                 const QStringList &args, const QString &branch) :
        BaseGitDiffArgumentsWidget(client, directory, args),
        m_branchName(branch)
    { }

    void redoCommand()
    {
        m_client->diffBranch(m_workingDirectory, m_args, m_branchName);
    }

private:
    const QString m_branchName;
};

class GitShowArgumentsWidget : public VCSBase::VCSBaseEditorParameterWidget
Friedemann Kleint's avatar
Friedemann Kleint committed
    Q_OBJECT
    GitShowArgumentsWidget(Git::Internal::GitClient *client,
                           const QString &directory,
                           const QStringList &args,
                           const QString &id) :
        m_client(client),
        m_workingDirectory(directory),
        m_args(args),
        QList<ComboBoxItem> prettyChoices;
        prettyChoices << ComboBoxItem(tr("oneline"), QLatin1String("oneline"))
                      << ComboBoxItem(tr("short"), QLatin1String("short"))
                      << ComboBoxItem(tr("medium"), QLatin1String("medium"))
                      << ComboBoxItem(tr("full"), QLatin1String("full"))
                      << ComboBoxItem(tr("fuller"), QLatin1String("fuller"))
                      << ComboBoxItem(tr("email"), QLatin1String("email"))
                      << ComboBoxItem(tr("raw"), QLatin1String("raw"));
        mapSetting(addComboBox(QLatin1String("--pretty"), prettyChoices),
                   m_client->settings()->stringPointer(GitSettings::showPrettyFormatKey));
    }

    void executeCommand()
        m_client->show(m_workingDirectory, m_id, m_args);
Loading
Loading full blame...