diff options
author | Andre Hartmann <aha_1980@gmx.de> | 2022-11-19 19:00:25 +0100 |
---|---|---|
committer | André Hartmann <aha_1980@gmx.de> | 2022-11-21 15:46:00 +0000 |
commit | 4d63f2a5983c75b43a145efaa1a9b6787972c432 (patch) | |
tree | c49c3d05e9a7342befe3b57c3a499ae9790f412b /src/plugins/git | |
parent | 722312f62fbc5476b1938b4c98df6fa86c986257 (diff) |
Git: use unique_ptr for instant blame marks
Also simplifies the code.
Change-Id: I5da0aeb86ba5a28c9016cde11aab9dcee922d908
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Diffstat (limited to 'src/plugins/git')
-rw-r--r-- | src/plugins/git/gitplugin.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 3d19b55f33..d50bf9ac51 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -236,7 +236,7 @@ public: } }; -static BlameMark *m_blameMark = nullptr; +static std::unique_ptr<BlameMark> m_blameMark; // GitPlugin @@ -1440,8 +1440,7 @@ void GitPluginPrivate::setupInstantBlame() if (!GitClient::instance()->settings().instantBlame.value()) { m_lastVisitedEditorLine = -1; - delete m_blameMark; - m_blameMark = nullptr; + m_blameMark.reset(); return; } @@ -1473,12 +1472,10 @@ void GitPluginPrivate::setupInstantBlame() connect(&GitClient::instance()->settings().instantBlame, &BoolAspect::valueChanged, this, [setupBlameForEditor](bool enabled) { - if (enabled) { + if (enabled) setupBlameForEditor(EditorManager::currentEditor()); - } else { - delete m_blameMark; - m_blameMark = nullptr; - } + else + m_blameMark.reset(); }); connect(EditorManager::instance(), &EditorManager::currentEditorChanged, @@ -1530,16 +1527,14 @@ void GitPluginPrivate::instantBlameOnce() connect(EditorManager::instance(), &EditorManager::currentEditorChanged, this, [editorChangedConn] { disconnect(*editorChangedConn); - delete m_blameMark; - m_blameMark = nullptr; + m_blameMark.reset(); }); auto cursorPosConn = std::make_shared<QMetaObject::Connection>(); *cursorPosConn = connect(widget, &QPlainTextEdit::cursorPositionChanged, this, [cursorPosConn] { disconnect(*cursorPosConn); - delete m_blameMark; - m_blameMark = nullptr; + m_blameMark.reset(); }); const Utils::FilePath workingDirectory = GitPlugin::currentState().topLevel(); @@ -1561,8 +1556,7 @@ void GitPluginPrivate::instantBlame() const int lines = widget->document()->lineCount(); if (line >= lines) { - delete m_blameMark; - m_blameMark = nullptr; + m_blameMark.reset(); return; } @@ -1581,8 +1575,7 @@ void GitPluginPrivate::instantBlame() connect(command, &VcsCommand::done, this, [command, filePath, line, this]() { const QString output = command->cleanedStdOut(); const CommitInfo info = parseBlameOutput(output.split('\n'), filePath, m_author); - delete m_blameMark; - m_blameMark = new BlameMark(filePath, line, info); + m_blameMark.reset(new BlameMark(filePath, line, info)); }); } |