Browse Source

Properly cleanup git repos and memory on project/frame deletion

* Ensure the git backend is deleted when the project tree is deleted.
* Unload the git repo for a project when the project is unloaded from
  the tree.
newinvert
Ian McInerney 2 years ago
committed by Ian McInerney
parent
commit
9456f35491
  1. 1
      common/git/kicad_git_errors.h
  2. 2
      kicad/project_tree.cpp
  3. 6
      kicad/project_tree.h
  4. 7
      kicad/project_tree_pane.cpp

1
common/git/kicad_git_errors.h

@ -33,6 +33,7 @@ class KIGIT_ERRORS
public: public:
KIGIT_ERRORS() = default; KIGIT_ERRORS() = default;
virtual ~KIGIT_ERRORS() = default;
const std::vector<wxString>& GetErrorStrings() const const std::vector<wxString>& GetErrorStrings() const
{ {

2
kicad/project_tree.cpp

@ -50,7 +50,7 @@ PROJECT_TREE::PROJECT_TREE( PROJECT_TREE_PANE* parent ) :
m_statusImageList( nullptr ) m_statusImageList( nullptr )
{ {
m_projectTreePane = parent; m_projectTreePane = parent;
m_gitCommon = new KIGIT_COMMON( nullptr );
m_gitCommon = std::make_unique<KIGIT_COMMON>( nullptr );
// Make sure the GUI font scales properly on GTK // Make sure the GUI font scales properly on GTK
SetFont( KIUI::GetControlFont( this ) ); SetFont( KIUI::GetControlFont( this ) );

6
kicad/project_tree.h

@ -25,6 +25,8 @@
#ifndef PROJECT_TREE_H #ifndef PROJECT_TREE_H
#define PROJECT_TREE_H #define PROJECT_TREE_H
#include <memory>
#include <git/kicad_git_common.h> #include <git/kicad_git_common.h>
#include <wx/treectrl.h> #include <wx/treectrl.h>
@ -45,7 +47,7 @@ private:
PROJECT_TREE_PANE* m_projectTreePane; PROJECT_TREE_PANE* m_projectTreePane;
wxImageList* m_imageList; wxImageList* m_imageList;
wxImageList* m_statusImageList; wxImageList* m_statusImageList;
KIGIT_COMMON* m_gitCommon;
std::unique_ptr<KIGIT_COMMON> m_gitCommon;
public: public:
PROJECT_TREE_PANE* GetProjectTreePane() const { return m_projectTreePane; } PROJECT_TREE_PANE* GetProjectTreePane() const { return m_projectTreePane; }
@ -58,7 +60,7 @@ public:
void SetGitRepo( git_repository* aRepo ) { m_gitCommon->SetRepo( aRepo ); } void SetGitRepo( git_repository* aRepo ) { m_gitCommon->SetRepo( aRepo ); }
git_repository* GetGitRepo() const { return m_gitCommon->GetRepo(); } git_repository* GetGitRepo() const { return m_gitCommon->GetRepo(); }
KIGIT_COMMON* GitCommon() const { return m_gitCommon; }
KIGIT_COMMON* GitCommon() const { return m_gitCommon.get(); }
private: private:
/* overridden sort function */ /* overridden sort function */

7
kicad/project_tree_pane.cpp

@ -1482,6 +1482,13 @@ void PROJECT_TREE_PANE::EmptyTreePrj()
shutdownFileWatcher(); shutdownFileWatcher();
m_TreeProject->DeleteAllItems(); m_TreeProject->DeleteAllItems();
// Remove the git repository when the project is unloaded
if( m_TreeProject->GetGitRepo() )
{
git_repository_free( m_TreeProject->GetGitRepo() );
m_TreeProject->SetGitRepo( nullptr );
}
} }

Loading…
Cancel
Save