KiCad PCB EDA Suite
Loading...
Searching...
No Matches
local_history.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#pragma once
25
26#include <vector>
27#include <functional>
28#include <wx/string.h>
29#include <wx/window.h>
30
36{
37public:
39 static bool Init( const wxString& aProjectPath );
40
42 static bool CommitSnapshot( const std::vector<wxString>& aFiles, const wxString& aTitle );
43
49 static bool CommitFullProjectSnapshot( const wxString& aProjectPath, const wxString& aTitle );
50
54 static void RegisterSaver( const std::function<void( const wxString&, std::vector<wxString>& )>& aSaver );
55
57 static bool RunRegisteredSaversAndCommit( const wxString& aProjectPath, const wxString& aTitle );
58
60 static void NoteFileChange( const wxString& aFile );
61
63 static bool CommitPending();
65 static bool HistoryExists( const wxString& aProjectPath );
66
68 static bool TagSave( const wxString& aProjectPath, const wxString& aFileType );
69
72 static bool CommitDuplicateOfLastSave( const wxString& aProjectPath, const wxString& aFileType,
73 const wxString& aMessage );
74
77 static bool EnforceSizeLimit( const wxString& aProjectPath, size_t aMaxBytes );
78
80 static bool HeadNewerThanLastSave( const wxString& aProjectPath );
81
83 static wxString GetHeadHash( const wxString& aProjectPath );
84
86 static bool RestoreCommit( const wxString& aProjectPath, const wxString& aHash );
87
89 static void ShowRestoreDialog( const wxString& aProjectPath, wxWindow* aParent );
90};
91
Simple local history manager built on libgit2.
static bool TagSave(const wxString &aProjectPath, const wxString &aFileType)
Tag a manual save in the local history repository.
static wxString GetHeadHash(const wxString &aProjectPath)
Return the current head commit hash.
static void ShowRestoreDialog(const wxString &aProjectPath, wxWindow *aParent)
Show a dialog allowing the user to choose a snapshot to restore.
static bool HeadNewerThanLastSave(const wxString &aProjectPath)
Return true if the autosave data is newer than the last manual save.
static bool CommitDuplicateOfLastSave(const wxString &aProjectPath, const wxString &aFileType, const wxString &aMessage)
Create a new commit duplicating the tree pointed to by Last_Save_<fileType> and move the Last_Save_<f...
static bool EnforceSizeLimit(const wxString &aProjectPath, size_t aMaxBytes)
Enforce total size limit by rebuilding trimmed history keeping newest commits whose cumulative unique...
static bool Init(const wxString &aProjectPath)
Initialize the local history repository for the given project path.
static bool CommitSnapshot(const std::vector< wxString > &aFiles, const wxString &aTitle)
Commit the given files to the local history repository.
static bool RunRegisteredSaversAndCommit(const wxString &aProjectPath, const wxString &aTitle)
Run all registered savers and, if any staged changes differ from HEAD, create a commit.
static void NoteFileChange(const wxString &aFile)
Record that a file has been modified and should be included in the next snapshot.
static bool CommitPending()
Commit any pending modified files to the history repository.
static bool HistoryExists(const wxString &aProjectPath)
Return true if history exists for the project.
static bool CommitFullProjectSnapshot(const wxString &aProjectPath, const wxString &aTitle)
Commit a snapshot of the entire project directory (excluding the .history directory and ignored trans...
static bool RestoreCommit(const wxString &aProjectPath, const wxString &aHash)
Restore the project files to the state recorded by the given commit hash.
static void RegisterSaver(const std::function< void(const wxString &, std::vector< wxString > &)> &aSaver)
Register a saver callback invoked during autosave history commits.