forked from qt-creator/qt-creator
Git: Simplify diff editor controllers
Change-Id: I3c1fb205a1197d6c3a457067eb2b7f355f28c55c Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
Orgad Shaneh
parent
9e3bbf36f2
commit
0b57675d40
@@ -265,37 +265,62 @@ void DescriptionWidgetDecorator::removeWatch(TextEditor::TextEditorWidget *widge
|
|||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
class GitDiffEditorController : public VcsBaseDiffEditorController
|
class GitBaseDiffEditorController : public VcsBaseDiffEditorController
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
protected:
|
||||||
explicit GitDiffEditorController(IDocument *document);
|
explicit GitBaseDiffEditorController(IDocument *document,
|
||||||
|
const QString &leftCommit);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void runCommand(const QList<QStringList> &args, QTextCodec *codec = nullptr);
|
void runCommand(const QList<QStringList> &args, QTextCodec *codec = nullptr);
|
||||||
|
|
||||||
QStringList addConfigurationArguments(const QStringList &args) const;
|
QStringList addConfigurationArguments(const QStringList &args) const;
|
||||||
QStringList addHeadWhenCommandInProgress() const;
|
QStringList baseArguments() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateBranchList();
|
void updateBranchList();
|
||||||
|
|
||||||
DescriptionWidgetWatcher m_watcher;
|
DescriptionWidgetWatcher m_watcher;
|
||||||
DescriptionWidgetDecorator m_decorator;
|
DescriptionWidgetDecorator m_decorator;
|
||||||
|
QString m_leftCommit;
|
||||||
|
QString m_rightCommit;
|
||||||
};
|
};
|
||||||
|
|
||||||
GitDiffEditorController::GitDiffEditorController(IDocument *document) :
|
class GitDiffEditorController : public GitBaseDiffEditorController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit GitDiffEditorController(IDocument *document,
|
||||||
|
const QString &leftCommit,
|
||||||
|
const QStringList &extraArgs)
|
||||||
|
: GitBaseDiffEditorController(document, leftCommit)
|
||||||
|
{
|
||||||
|
setReloader([this, extraArgs] {
|
||||||
|
runCommand({addConfigurationArguments(baseArguments() << extraArgs)});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GitBaseDiffEditorController::GitBaseDiffEditorController(IDocument *document,
|
||||||
|
const QString &leftCommit) :
|
||||||
VcsBaseDiffEditorController(document),
|
VcsBaseDiffEditorController(document),
|
||||||
m_watcher(this),
|
m_watcher(this),
|
||||||
m_decorator(&m_watcher)
|
m_decorator(&m_watcher),
|
||||||
|
m_leftCommit(leftCommit)
|
||||||
{
|
{
|
||||||
connect(&m_decorator, &DescriptionWidgetDecorator::branchListRequested,
|
connect(&m_decorator, &DescriptionWidgetDecorator::branchListRequested,
|
||||||
this, &GitDiffEditorController::updateBranchList);
|
this, &GitBaseDiffEditorController::updateBranchList);
|
||||||
setDisplayName("Git Diff");
|
setDisplayName("Git Diff");
|
||||||
|
// This is workaround for lack of support for merge commits and resolving conflicts,
|
||||||
|
// we compare the current state of working tree to the HEAD of current branch
|
||||||
|
// instead of showing unsupported combined diff format.
|
||||||
|
GitClient::CommandInProgress commandInProgress = m_instance->checkCommandInProgress(workingDirectory());
|
||||||
|
if (commandInProgress != GitClient::NoCommand)
|
||||||
|
m_rightCommit = HEAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitDiffEditorController::updateBranchList()
|
void GitBaseDiffEditorController::updateBranchList()
|
||||||
{
|
{
|
||||||
const QString revision = description().mid(7, 12);
|
const QString revision = description().mid(7, 12);
|
||||||
if (revision.isEmpty())
|
if (revision.isEmpty())
|
||||||
@@ -347,12 +372,12 @@ void GitDiffEditorController::updateBranchList()
|
|||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
||||||
void GitDiffEditorController::runCommand(const QList<QStringList> &args, QTextCodec *codec)
|
void GitBaseDiffEditorController::runCommand(const QList<QStringList> &args, QTextCodec *codec)
|
||||||
{
|
{
|
||||||
VcsBaseDiffEditorController::runCommand(args, diffExecutionFlags(), codec);
|
VcsBaseDiffEditorController::runCommand(args, diffExecutionFlags(), codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList GitDiffEditorController::addConfigurationArguments(const QStringList &args) const
|
QStringList GitBaseDiffEditorController::addConfigurationArguments(const QStringList &args) const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!args.isEmpty(), return args);
|
QTC_ASSERT(!args.isEmpty(), return args);
|
||||||
|
|
||||||
@@ -372,66 +397,32 @@ QStringList GitDiffEditorController::addConfigurationArguments(const QStringList
|
|||||||
return realArgs;
|
return realArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList GitDiffEditorController::addHeadWhenCommandInProgress() const
|
QStringList GitBaseDiffEditorController::baseArguments() const
|
||||||
{
|
{
|
||||||
// This is workaround for lack of support for merge commits and resolving conflicts,
|
QStringList res = {"diff"};
|
||||||
// we compare the current state of working tree to the HEAD of current branch
|
if (!m_leftCommit.isEmpty())
|
||||||
// instead of showing unsupported combined diff format.
|
res << m_leftCommit;
|
||||||
GitClient::CommandInProgress commandInProgress = m_instance->checkCommandInProgress(workingDirectory());
|
if (!m_rightCommit.isEmpty())
|
||||||
if (commandInProgress != GitClient::NoCommand)
|
res << m_rightCommit;
|
||||||
return {HEAD};
|
return res;
|
||||||
return QStringList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class RepositoryDiffController : public GitDiffEditorController
|
class FileListDiffController : public GitBaseDiffEditorController
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit RepositoryDiffController(IDocument *document) :
|
|
||||||
GitDiffEditorController(document)
|
|
||||||
{
|
|
||||||
setReloader([this] {
|
|
||||||
QStringList args = {"diff"};
|
|
||||||
args.append(addHeadWhenCommandInProgress());
|
|
||||||
runCommand({addConfigurationArguments(args)});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class FileDiffController : public GitDiffEditorController
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FileDiffController(IDocument *document, const QString &fileName) :
|
|
||||||
GitDiffEditorController(document)
|
|
||||||
{
|
|
||||||
setReloader([this, fileName] {
|
|
||||||
QStringList args = {"diff"};
|
|
||||||
args.append(addHeadWhenCommandInProgress());
|
|
||||||
args << "--" << fileName;
|
|
||||||
runCommand({addConfigurationArguments(args)});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class FileListDiffController : public GitDiffEditorController
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileListDiffController(IDocument *document,
|
FileListDiffController(IDocument *document,
|
||||||
const QStringList &stagedFiles, const QStringList &unstagedFiles) :
|
const QStringList &stagedFiles, const QStringList &unstagedFiles) :
|
||||||
GitDiffEditorController(document)
|
GitBaseDiffEditorController(document, {})
|
||||||
{
|
{
|
||||||
setReloader([this, stagedFiles, unstagedFiles] {
|
setReloader([this, stagedFiles, unstagedFiles] {
|
||||||
QList<QStringList> argLists;
|
QList<QStringList> argLists;
|
||||||
if (!stagedFiles.isEmpty()) {
|
if (!stagedFiles.isEmpty()) {
|
||||||
QStringList stagedArgs = {"diff", "--cached", "--"};
|
QStringList stagedArgs = QStringList({"diff", "--cached", "--"}) << stagedFiles;
|
||||||
stagedArgs << stagedFiles;
|
|
||||||
argLists << addConfigurationArguments(stagedArgs);
|
argLists << addConfigurationArguments(stagedArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!unstagedFiles.isEmpty()) {
|
if (!unstagedFiles.isEmpty())
|
||||||
QStringList unstagedArgs = {"diff"};
|
argLists << addConfigurationArguments(baseArguments() << "--" << unstagedFiles);
|
||||||
unstagedArgs << addHeadWhenCommandInProgress() << "--" << unstagedFiles;
|
|
||||||
argLists << addConfigurationArguments(unstagedArgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!argLists.isEmpty())
|
if (!argLists.isEmpty())
|
||||||
runCommand(argLists);
|
runCommand(argLists);
|
||||||
@@ -439,40 +430,12 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProjectDiffController : public GitDiffEditorController
|
class ShowController : public GitBaseDiffEditorController
|
||||||
{
|
|
||||||
public:
|
|
||||||
ProjectDiffController(IDocument *document, const QStringList &projectPaths) :
|
|
||||||
GitDiffEditorController(document)
|
|
||||||
{
|
|
||||||
setReloader([this, projectPaths] {
|
|
||||||
QStringList args = {"diff"};
|
|
||||||
args << addHeadWhenCommandInProgress() << "--" << projectPaths;
|
|
||||||
runCommand({addConfigurationArguments(args)});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class BranchDiffController : public GitDiffEditorController
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BranchDiffController(IDocument *document, const QString &branch) :
|
|
||||||
GitDiffEditorController(document)
|
|
||||||
{
|
|
||||||
setReloader([this, branch] {
|
|
||||||
QStringList args = {"diff"};
|
|
||||||
args << branch << addHeadWhenCommandInProgress();
|
|
||||||
runCommand({addConfigurationArguments(args)});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class ShowController : public GitDiffEditorController
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ShowController(IDocument *document, const QString &id) :
|
ShowController(IDocument *document, const QString &id) :
|
||||||
GitDiffEditorController(document),
|
GitBaseDiffEditorController(document, {}),
|
||||||
m_id(id),
|
m_id(id),
|
||||||
m_state(Idle)
|
m_state(Idle)
|
||||||
{
|
{
|
||||||
@@ -505,7 +468,7 @@ void ShowController::processCommandOutput(const QString &output)
|
|||||||
runCommand(QList<QStringList>() << addConfigurationArguments(args));
|
runCommand(QList<QStringList>() << addConfigurationArguments(args));
|
||||||
} else if (m_state == GettingDiff) {
|
} else if (m_state == GettingDiff) {
|
||||||
m_state = Idle;
|
m_state = Idle;
|
||||||
GitDiffEditorController::processCommandOutput(output);
|
GitBaseDiffEditorController::processCommandOutput(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -978,7 +941,7 @@ void GitClient::diffProject(const QString &workingDirectory, const QString &proj
|
|||||||
requestReload(documentId,
|
requestReload(documentId,
|
||||||
workingDirectory, tr("Git Diff Project"), workingDirectory,
|
workingDirectory, tr("Git Diff Project"), workingDirectory,
|
||||||
[projectDirectory](IDocument *doc){
|
[projectDirectory](IDocument *doc){
|
||||||
return new ProjectDiffController(doc, {projectDirectory});
|
return new GitDiffEditorController(doc, {}, {"--", projectDirectory});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -986,9 +949,10 @@ void GitClient::diffRepository(const QString &workingDirectory) const
|
|||||||
{
|
{
|
||||||
const QString documentId = QLatin1String(Constants::GIT_PLUGIN)
|
const QString documentId = QLatin1String(Constants::GIT_PLUGIN)
|
||||||
+ QLatin1String(".DiffRepository.") + workingDirectory;
|
+ QLatin1String(".DiffRepository.") + workingDirectory;
|
||||||
requestReload(documentId,
|
requestReload(documentId, workingDirectory, tr("Git Diff Repository"), workingDirectory,
|
||||||
workingDirectory, tr("Git Diff Repository"), workingDirectory,
|
[](IDocument *doc) {
|
||||||
[](IDocument *doc) { return new RepositoryDiffController(doc); });
|
return new GitDiffEditorController(doc, {}, {});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::diffFile(const QString &workingDirectory, const QString &fileName) const
|
void GitClient::diffFile(const QString &workingDirectory, const QString &fileName) const
|
||||||
@@ -998,7 +962,9 @@ void GitClient::diffFile(const QString &workingDirectory, const QString &fileNam
|
|||||||
const QString documentId = QLatin1String(Constants::GIT_PLUGIN)
|
const QString documentId = QLatin1String(Constants::GIT_PLUGIN)
|
||||||
+ QLatin1String(".DifFile.") + sourceFile;
|
+ QLatin1String(".DifFile.") + sourceFile;
|
||||||
requestReload(documentId, sourceFile, title, workingDirectory,
|
requestReload(documentId, sourceFile, title, workingDirectory,
|
||||||
[fileName](IDocument *doc) { return new FileDiffController(doc, fileName); });
|
[&fileName](IDocument *doc) {
|
||||||
|
return new GitDiffEditorController(doc, {}, {"--", fileName});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::diffBranch(const QString &workingDirectory, const QString &branchName) const
|
void GitClient::diffBranch(const QString &workingDirectory, const QString &branchName) const
|
||||||
@@ -1007,7 +973,9 @@ void GitClient::diffBranch(const QString &workingDirectory, const QString &branc
|
|||||||
const QString documentId = QLatin1String(Constants::GIT_PLUGIN)
|
const QString documentId = QLatin1String(Constants::GIT_PLUGIN)
|
||||||
+ QLatin1String(".DiffBranch.") + branchName;
|
+ QLatin1String(".DiffBranch.") + branchName;
|
||||||
requestReload(documentId, workingDirectory, title, workingDirectory,
|
requestReload(documentId, workingDirectory, title, workingDirectory,
|
||||||
[branchName](IDocument *doc) { return new BranchDiffController(doc, branchName); });
|
[branchName](IDocument *doc) {
|
||||||
|
return new GitDiffEditorController(doc, branchName, {});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitClient::merge(const QString &workingDirectory,
|
void GitClient::merge(const QString &workingDirectory,
|
||||||
|
Reference in New Issue
Block a user