aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <[email protected]>2025-04-23 08:46:43 +0200
committerEike Ziller <[email protected]>2025-04-23 08:53:35 +0000
commit916e369f89ac52a7205578d73568d5953949bb94 (patch)
tree36aa617153f1cf3d1a15f561da2bb5f6e4bc4e8d
parent69976a70ee98cf300275edf3c45e84691bd711dc (diff)
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 <[email protected]>
-rw-r--r--src/plugins/git/instantblame.cpp71
1 files changed, 37 insertions, 34 deletions
diff --git a/src/plugins/git/instantblame.cpp b/src/plugins/git/instantblame.cpp
index 928952cfee5..22be00d901a 100644
--- a/src/plugins/git/instantblame.cpp
+++ b/src/plugins/git/instantblame.cpp
@@ -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;
-
- 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);
+ 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();
+
+ 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;
}