Newer
Older
/****************************************************************************
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
** GNU Lesser General Public License Usage
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "gitconstants.h"
#include "gitplugin.h"
#include "gitsubmiteditor.h"
#include "gitversioncontrol.h"
#include <vcsbase/submitfilemodel.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/id.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/coreconstants.h>
#include <utils/synchronousprocess.h>
#include <vcsbase/vcsbaseeditorparameterwidget.h>
#include <vcsbase/vcsbaseoutputwindow.h>
#include <vcsbase/vcsbaseplugin.h>
#include <diffeditor/diffeditor.h>
#include <diffeditor/diffshoweditor.h>
#include <diffeditor/diffeditorconstants.h>
#include <QSignalMapper>
#include <QToolButton>
#include <QTextCodec>
static const char GIT_DIRECTORY[] = ".git";
static const char graphLogFormatC[] = "%h %d %an %s %ci";
static const char HEAD[] = "HEAD";
static const char noColorOption[] = "--no-color";
static const char decorateOption[] = "--decorate";
namespace Git {
namespace Internal {
class GitDiffSwitcher : public QObject
{
Q_OBJECT
public:
enum DiffType {
DiffRepository,
DiffFile,
DiffFileList,
DiffProjectList,
DiffBranch,
DiffShow
};
GitDiffSwitcher(Core::IEditor *parentEditor, GitClient *gitClient, GitClient::DiffEditorType switchToType)
: QObject(parentEditor),
m_editor(parentEditor),
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
m_gitClient(gitClient),
m_editorType(switchToType)
{
QIcon actionIcon = switchToType == GitClient::SideBySideDiffEditor
? QIcon(QLatin1String(Core::Constants::ICON_SIDE_BY_SIDE_DIFF))
: QIcon(QLatin1String(Core::Constants::ICON_TEXT_DIFF));
const QString actionToolTip = switchToType == GitClient::SideBySideDiffEditor
? tr("Switch to Side By Side Diff Editor")
: tr("Switch to Text Diff Editor");
QAction *switchAction = new QAction(actionIcon, actionToolTip, parentEditor);
parentEditor->toolBar()->addAction(switchAction);
connect(switchAction, SIGNAL(triggered()), this, SLOT(execute()));
}
void setWorkingDirectory(const QString &workingDir) { m_workingDirectory = workingDir; }
void setDiffType(DiffType type) { m_diffType = type; }
void setFileName(const QString &fileName) { m_fileName = fileName; }
void setFileList(const QStringList &stagedFiles, const QStringList &unstagedFiles)
{
m_stagedFiles = stagedFiles;
m_unstagedFiles = unstagedFiles;
}
void setProjectList(const QStringList &projectFiles) { m_projectFiles = projectFiles; }
void setBranchName(const QString &branchName) { m_branchName = branchName; }
void setId(const QString &id) { m_id = id; }
void setDisplayName(const QString &displayName) { m_displayName = displayName; }
void setBaseArguments(const QStringList &args) { m_baseArguments = args; }
public slots:
void execute();
private:
Core::IEditor *m_editor;
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
GitClient *m_gitClient;
QString m_workingDirectory;
DiffType m_diffType;
GitClient::DiffEditorType m_editorType;
QString m_fileName;
QStringList m_stagedFiles;
QStringList m_unstagedFiles;
QStringList m_projectFiles;
QString m_branchName;
QString m_id;
QString m_displayName;
QStringList m_baseArguments;
};
void GitDiffSwitcher::execute()
{
switch (m_diffType) {
case DiffRepository:
m_gitClient->diff(m_workingDirectory, QStringList(), QStringList(), m_editorType);
break;
case DiffFile:
m_gitClient->diff(m_workingDirectory, m_fileName, m_editorType);
break;
case DiffFileList:
m_gitClient->diff(m_workingDirectory, m_unstagedFiles, m_stagedFiles, m_editorType);
break;
case DiffProjectList:
m_gitClient->diff(m_workingDirectory, m_projectFiles, QStringList(), m_editorType);
break;
case DiffBranch:
m_gitClient->diffBranch(m_workingDirectory, m_baseArguments, m_branchName, m_editorType);
break;
case DiffShow:
m_gitClient->show(m_fileName, m_id, m_baseArguments, m_displayName, m_editorType);
break;
default:
break;
}
Core::EditorManager::closeEditor(m_editor, false);
class GitDiffHandler : public QObject
{
Q_OBJECT
public:
enum RevisionType {
WorkingTree,
Index,
Other
};
struct Revision {
Revision() : type(WorkingTree) { }
Revision(RevisionType t) : type(t) { }
Revision(RevisionType t, const QString &i) : type(t), id(i) { }
RevisionType type;
QString id; // can be sha or HEAD
QString infoText() const
{
switch (type) {
Loading
Loading full blame...