Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc03d231

Browse files
author
Volker Vogelhuber
committed
Added diff to working copy
Quick and dirty implementation of allowing a diff between a selected changeset and the current working copy. Adresses issue#663
1 parent7ca4043 commitc03d231

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

‎src/tools/DiffTool.cpp‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ DiffTool::DiffTool(const QString &file, const git::Blob &localBlob,
1919
: ExternalTool(file, parent), mLocalBlob(localBlob),
2020
mRemoteBlob(remoteBlob) {}
2121

22+
DiffTool::DiffTool(const QString &file,
23+
const git::Blob &remoteBlob, QObject *parent)
24+
: ExternalTool(file, parent),
25+
mRemoteBlob(remoteBlob) {Q_ASSERT(!mLocalBlob); }
26+
2227
boolDiffTool::isValid()const {
23-
return (ExternalTool::isValid() &&mLocalBlob.isValid());
28+
return (ExternalTool::isValid() &&mRemoteBlob.isValid());
2429
}
2530

2631
ExternalTool::KindDiffTool::kind()const {return Diff; }
2732

28-
QStringDiffTool::name()const {returntr("External Diff"); }
33+
QStringDiffTool::name()const {returnmLocalBlob ?tr("External Diff") :tr("External Diff to working copy"); }
2934

3035
boolDiffTool::start() {
3136
Q_ASSERT(isValid());
@@ -37,12 +42,15 @@ bool DiffTool::start() {
3742

3843
// Write temporary files.
3944
QString templatePath =QDir::temp().filePath(QFileInfo(mFile).fileName());
40-
QTemporaryFile *local =newQTemporaryFile(templatePath,this);
41-
if (!local->open())
42-
returnfalse;
45+
QTemporaryFile *local =nullptr;
46+
if (mLocalBlob.isValid()) {
47+
local =newQTemporaryFile(templatePath,this);
48+
if (!local->open())
49+
returnfalse;
4350

44-
local->write(mLocalBlob.content());
45-
local->flush();
51+
local->write(mLocalBlob.content());
52+
local->flush();
53+
}
4654

4755
QString remotePath;
4856
if (!mRemoteBlob.isValid()) {
@@ -71,7 +79,7 @@ bool DiffTool::start() {
7179
});
7280

7381
#if defined(FLATPAK) || defined(DEBUG_FLATPAK)
74-
QStringList arguments = {"--host","--env=LOCAL=" + local->fileName(),
82+
QStringList arguments = {"--host","--env=LOCAL=" + local ? local->fileName() :QFileInfo(mFile).absoluteFilePath(),
7583
"--env=REMOTE=" + remotePath,
7684
"--env=MERGED=" +mFile,"--env=BASE=" +mFile};
7785
arguments.append("sh");
@@ -81,7 +89,7 @@ bool DiffTool::start() {
8189
#else
8290

8391
QProcessEnvironment env =QProcessEnvironment::systemEnvironment();
84-
env.insert("LOCAL", local->fileName());
92+
env.insert("LOCAL", local ? local->fileName() :QFileInfo(mFile).absoluteFilePath());
8593
env.insert("REMOTE", remotePath);
8694
env.insert("MERGED",mFile);
8795
env.insert("BASE",mFile);

‎src/tools/DiffTool.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class DiffTool : public ExternalTool {
2020
DiffTool(const QString &file,const git::Blob &localBlob,
2121
const git::Blob &remoteBlob, QObject *parent =nullptr);
2222

23+
DiffTool(const QString &file,
24+
const git::Blob &remoteBlob, QObject *parent =nullptr);
25+
2326
boolisValid()constoverride;
2427

2528
Kindkind()constoverride;

‎src/tools/ExternalTool.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ QList<ExternalTool::Info> ExternalTool::readBuiltInTools(const QString &key) {
9797
}
9898

9999
ExternalTool *ExternalTool::create(const QString &file,const git::Diff &diff,
100-
const git::Repository &repo,
100+
const git::Repository &repo,bool againstWorkingDir,
101101
QObject *parent) {
102102
if (!diff.isValid())
103103
returnnullptr;
@@ -110,7 +110,7 @@ ExternalTool *ExternalTool::create(const QString &file, const git::Diff &diff,
110110
QString path = repo.workdir().filePath(file);
111111

112112
// Create merge tool.
113-
if (diff.status(index) == GIT_DELTA_CONFLICTED) {
113+
if (!againstWorkingDir &&diff.status(index) == GIT_DELTA_CONFLICTED) {
114114
git::Index::Conflict conflict = repo.index().conflict(file);
115115
git::Blob local = repo.lookupBlob(conflict.ours);
116116
git::Blob remote = repo.lookupBlob(conflict.theirs);
@@ -121,5 +121,5 @@ ExternalTool *ExternalTool::create(const QString &file, const git::Diff &diff,
121121
// Create diff tool.
122122
git::Blob local = repo.lookupBlob(diff.id(index, git::Diff::OldFile));
123123
git::Blob remote = repo.lookupBlob(diff.id(index, git::Diff::NewFile));
124-
returnnewDiffTool(path, local, remote, parent);
124+
returnagainstWorkingDir ?newDiffTool(path, remote, parent) :newDiffTool(path, local, remote, parent);
125125
}

‎src/tools/ExternalTool.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ExternalTool : public QObject {
5454
static QList<Info>readBuiltInTools(const QString &key);
5555

5656
static ExternalTool *create(const QString &file,const git::Diff &diff,
57-
const git::Repository &repo,
57+
const git::Repository &repo,bool againstWorkingDir =false,
5858
QObject *parent =nullptr);
5959

6060
signals:

‎src/ui/FileContextMenu.cpp‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ FileContextMenu::FileContextMenu(RepoView *view, const QStringList &files,
100100
QList<ExternalTool *> showTools;
101101
QList<ExternalTool *> editTools;
102102
QList<ExternalTool *> diffTools;
103+
QList<ExternalTool *> diffToLocalTools;
103104
QList<ExternalTool *> mergeTools;
104105
foreach (const QString &file, files) {
105106
// Convert to absolute path.
@@ -112,7 +113,25 @@ FileContextMenu::FileContextMenu(RepoView *view, const QStringList &files,
112113
editTools.append(newEditTool(path,this));
113114

114115
// Add diff or merge tool.
115-
if (ExternalTool *tool =ExternalTool::create(file, diff, repo,this)) {
116+
if (ExternalTool *tool =ExternalTool::create(file, diff, repo,true,this)) {
117+
Q_ASSERT(tool->kind() == ExternalTool::Diff);
118+
diffToLocalTools.append(tool);
119+
connect(tool, &ExternalTool::error, [this](ExternalTool::Error error) {
120+
if (error != ExternalTool::BashNotFound)
121+
return;
122+
123+
QString title =tr("Bash Not Found");
124+
QString text =tr("Bash was not found on your PATH.");
125+
QMessageBoxmsg(QMessageBox::Warning, title, text, QMessageBox::Ok,
126+
this);
127+
msg.setInformativeText(
128+
tr("Bash is required to execute external tools."));
129+
msg.exec();
130+
});
131+
}
132+
133+
// Add diff or merge tool.
134+
if (ExternalTool *tool =ExternalTool::create(file, diff, repo,false,this)) {
116135
switch (tool->kind()) {
117136
case ExternalTool::Diff:
118137
diffTools.append(tool);
@@ -147,6 +166,7 @@ FileContextMenu::FileContextMenu(RepoView *view, const QStringList &files,
147166
addExternalToolsAction(showTools);
148167
addExternalToolsAction(editTools);
149168
addExternalToolsAction(diffTools);
169+
addExternalToolsAction(diffToLocalTools);
150170
addExternalToolsAction(mergeTools);
151171

152172
if (!isEmpty())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp