Git: Stop blame attempts for unmanaged files in the repository

A file that is in the repository directory, but not managed by Git should
not attempt to run instant blame on every cursor change.

Change-Id: Ia7daa2ae9980cea4363e010a98fb1e2f2a3ec05f
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Orgad Shaneh
2022-11-21 15:08:27 +02:00
committed by Orgad Shaneh
parent 4d63f2a598
commit 252179b938

View File

@@ -430,6 +430,7 @@ public:
Author m_author;
int m_lastVisitedEditorLine = -1;
QTimer *m_cursorPositionChangedTimer = nullptr;
QMetaObject::Connection m_blameCursorPosConn;
GitSettingsPage settingPage{&m_settings};
@@ -1456,11 +1457,10 @@ void GitPluginPrivate::setupInstantBlame()
if (qobject_cast<const VcsBaseEditorWidget *>(widget))
return; // Skip in VCS editors like log or blame
auto cursorPosConn = std::make_shared<QMetaObject::Connection>();
*cursorPosConn = connect(widget, &QPlainTextEdit::cursorPositionChanged, this,
[this, cursorPosConn] {
m_blameCursorPosConn = connect(widget, &QPlainTextEdit::cursorPositionChanged, this,
[this] {
if (!GitClient::instance()->settings().instantBlame.value()) {
disconnect(*cursorPosConn);
disconnect(m_blameCursorPosConn);
return;
}
m_cursorPositionChangedTimer->start(500);
@@ -1571,8 +1571,13 @@ void GitPluginPrivate::instantBlame()
const QString lineString = QString("%1,%1").arg(line);
const VcsCommand *command = GitClient::instance()->vcsExec(
workingDirectory, {"blame", "-p", "-L", lineString, "--", filePath.toString()},
nullptr, false, RunFlags::SuppressCommandLogging | RunFlags::ProgressiveOutput);
nullptr, false, RunFlags::NoOutput);
connect(command, &VcsCommand::done, this, [command, filePath, line, this]() {
if (command->result() == ProcessResult::FinishedWithError &&
command->cleanedStdErr().contains("no such path")) {
disconnect(m_blameCursorPosConn);
return;
}
const QString output = command->cleanedStdOut();
const CommitInfo info = parseBlameOutput(output.split('\n'), filePath, m_author);
m_blameMark.reset(new BlameMark(filePath, line, info));