forked from qt-creator/qt-creator
Git: Fix potential crash in instant blame
When clicking links in the tool tip. The connection was guarded with the label, but was accessing data from the BlameMark. We got a report for a crash that looks like the mark was already gone at this point. It is safer to capture the relevant data explicitly. Change-Id: I16aa30a37c4221c4bf3caf90692a660737be3870 Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
@@ -69,42 +69,45 @@ bool BlameMark::addToolTipContent(QLayout *target) const
|
||||
auto textLabel = new QLabel;
|
||||
textLabel->setText(toolTip());
|
||||
target->addWidget(textLabel);
|
||||
QObject::connect(textLabel, &QLabel::linkActivated, textLabel, [this](const QString &link) {
|
||||
qCInfo(log) << "Link activated with target:" << link;
|
||||
const QString hash = (link == "blameParent") ? m_info.hash + "^" : m_info.hash;
|
||||
QObject::connect(
|
||||
textLabel, &QLabel::linkActivated, textLabel, [info = m_info](const QString &link) {
|
||||
qCInfo(log) << "Link activated with target:" << link;
|
||||
const QString hash = (link == "blameParent") ? info.hash + "^" : info.hash;
|
||||
|
||||
if (link.startsWith("blame") || link == "showFile") {
|
||||
const VcsBasePluginState state = currentState();
|
||||
QTC_ASSERT(state.hasTopLevel(), return);
|
||||
const Utils::FilePath path = state.topLevel();
|
||||
if (link.startsWith("blame") || link == "showFile") {
|
||||
const VcsBasePluginState state = currentState();
|
||||
QTC_ASSERT(state.hasTopLevel(), return);
|
||||
const Utils::FilePath path = state.topLevel();
|
||||
|
||||
const QString originalFileName = m_info.originalFileName;
|
||||
if (link.startsWith("blame")) {
|
||||
qCInfo(log).nospace().noquote() << "Blaming: \"" << path << "/" << originalFileName
|
||||
<< "\":" << m_info.originalLine << " @ " << hash;
|
||||
gitClient().annotate(path, originalFileName, m_info.originalLine, hash);
|
||||
const QString originalFileName = info.originalFileName;
|
||||
if (link.startsWith("blame")) {
|
||||
qCInfo(log).nospace().noquote()
|
||||
<< "Blaming: \"" << path << "/" << originalFileName
|
||||
<< "\":" << info.originalLine << " @ " << hash;
|
||||
gitClient().annotate(path, originalFileName, info.originalLine, hash);
|
||||
} else {
|
||||
qCInfo(log).nospace().noquote()
|
||||
<< "Showing file: \"" << path << "/" << originalFileName << "\" @ " << hash;
|
||||
|
||||
const auto fileName = Utils::FilePath::fromString(originalFileName);
|
||||
gitClient().openShowEditor(path, hash, fileName);
|
||||
}
|
||||
} else if (link == "logLine") {
|
||||
const VcsBasePluginState state = currentState();
|
||||
QTC_ASSERT(state.hasFile(), return);
|
||||
|
||||
qCInfo(log).nospace().noquote()
|
||||
<< "Showing log for: \"" << info.filePath << "\" line:" << info.line;
|
||||
|
||||
const QString lineArg
|
||||
= QString("-L %1,%1:%2").arg(info.line).arg(state.relativeCurrentFile());
|
||||
gitClient().log(state.currentFileTopLevel(), {}, true, {lineArg, "--no-patch"});
|
||||
} else {
|
||||
qCInfo(log).nospace().noquote() << "Showing file: \"" << path << "/"
|
||||
<< originalFileName << "\" @ " << hash;
|
||||
|
||||
const auto fileName = Utils::FilePath::fromString(originalFileName);
|
||||
gitClient().openShowEditor(path, hash, fileName);
|
||||
qCInfo(log).nospace().noquote()
|
||||
<< "Showing commit: " << hash << " for " << info.filePath;
|
||||
gitClient().show(info.filePath, hash);
|
||||
}
|
||||
} else if (link == "logLine") {
|
||||
const VcsBasePluginState state = currentState();
|
||||
QTC_ASSERT(state.hasFile(), return);
|
||||
|
||||
qCInfo(log).nospace().noquote() << "Showing log for: \"" << m_info.filePath
|
||||
<< "\" line:" << m_info.line;
|
||||
|
||||
const QString lineArg = QString("-L %1,%1:%2")
|
||||
.arg(m_info.line).arg(state.relativeCurrentFile());
|
||||
gitClient().log(state.currentFileTopLevel(), {}, true, {lineArg, "--no-patch"});
|
||||
} else {
|
||||
qCInfo(log).nospace().noquote() << "Showing commit: " << hash << " for " << m_info.filePath;
|
||||
gitClient().show(m_info.filePath, hash);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user