|
KiCad PCB EDA Suite
|
Simple local history manager built on libgit2. More...
#include <local_history.h>
Public Member Functions | |
| LOCAL_HISTORY () | |
| ~LOCAL_HISTORY () | |
| bool | Init (const wxString &aProjectPath) |
| Initialize the local history repository for the given project path. | |
| bool | CommitSnapshot (const std::vector< wxString > &aFiles, const wxString &aTitle) |
| Commit the given files to the local history repository. | |
| bool | CommitFullProjectSnapshot (const wxString &aProjectPath, const wxString &aTitle) |
| Commit a snapshot of the entire project directory (excluding the .history directory and ignored transient files) to the local history repository. | |
| void | RegisterSaver (const void *aSaverObject, const std::function< void(const wxString &, std::vector< HISTORY_FILE_DATA > &)> &aSaver) |
| Register a saver callback invoked during autosave history commits. | |
| void | UnregisterSaver (const void *aSaverObject) |
| Unregister a previously registered saver callback. | |
| void | ClearAllSavers () |
| Clear all registered savers. | |
| bool | RunRegisteredSaversAndCommit (const wxString &aProjectPath, const wxString &aTitle) |
| Run all registered savers and, if any staged changes differ from HEAD, create a commit. | |
| void | NoteFileChange (const wxString &aFile) |
| Record that a file has been modified and should be included in the next snapshot. | |
| bool | CommitPending () |
| Commit any pending modified files to the history repository. | |
| bool | HistoryExists (const wxString &aProjectPath) |
| Return true if history exists for the project. | |
| bool | TagSave (const wxString &aProjectPath, const wxString &aFileType) |
| Tag a manual save in the local history repository. | |
| 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_<fileType> tag to the new commit (used when user discards changes). | |
| bool | EnforceSizeLimit (const wxString &aProjectPath, size_t aMaxBytes) |
| Enforce total size limit by rebuilding trimmed history keeping newest commits whose cumulative unique blob sizes fit within limit. | |
| bool | HeadNewerThanLastSave (const wxString &aProjectPath) |
| Return true if the autosave data is newer than the last manual save. | |
| wxString | GetHeadHash (const wxString &aProjectPath) |
| Return the current head commit hash. | |
| bool | RestoreCommit (const wxString &aProjectPath, const wxString &aHash, wxWindow *aParent=nullptr) |
| Restore the project files to the state recorded by the given commit hash. | |
| void | ShowRestoreDialog (const wxString &aProjectPath, wxWindow *aParent) |
| Show a dialog allowing the user to choose a snapshot to restore. | |
Private Member Functions | |
| std::vector< LOCAL_HISTORY_SNAPSHOT_INFO > | LoadSnapshots (const wxString &aProjectPath) |
| bool | commitInBackground (const wxString &aProjectPath, const wxString &aTitle, const std::vector< HISTORY_FILE_DATA > &aFileData) |
| Execute file writes and git commit on a background thread. | |
| void | WaitForPendingSave () |
| Block until any pending background save completes. | |
Private Attributes | |
| std::set< wxString > | m_pendingFiles |
| std::map< const void *, std::function< void(const wxString &, std::vector< HISTORY_FILE_DATA > &)> > | m_savers |
| std::atomic< bool > | m_saveInProgress { false } |
| std::future< bool > | m_pendingFuture |
Simple local history manager built on libgit2.
Stores history for project files in a hidden .history git repository within the project directory.
Definition at line 69 of file local_history.h.
| LOCAL_HISTORY::LOCAL_HISTORY | ( | ) |
Definition at line 61 of file local_history.cpp.
| LOCAL_HISTORY::~LOCAL_HISTORY | ( | ) |
Definition at line 65 of file local_history.cpp.
References WaitForPendingSave().
| void LOCAL_HISTORY::ClearAllSavers | ( | ) |
Clear all registered savers.
Definition at line 110 of file local_history.cpp.
References m_savers, traceAutoSave, and WaitForPendingSave().
Referenced by KIWAY::ProjectChanged().
| bool LOCAL_HISTORY::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_<fileType> tag to the new commit (used when user discards changes).
Definition at line 842 of file local_history.cpp.
References HISTORY_LOCK_MANAGER::GetRepository(), HISTORY_LOCK_MANAGER::IsLocked(), and traceAutoSave.
Referenced by PCB_EDIT_FRAME::canCloseWindow(), and SCH_EDIT_FRAME::canCloseWindow().
| bool LOCAL_HISTORY::CommitFullProjectSnapshot | ( | const wxString & | aProjectPath, |
| const wxString & | aTitle ) |
Commit a snapshot of the entire project directory (excluding the .history directory and ignored transient files) to the local history repository.
This does not modify any document dirty flags; it purely mirrors on-disk state for history purposes.
Definition at line 721 of file local_history.cpp.
References collectProjectFiles(), and CommitSnapshot().
Referenced by PCB_EDIT_FRAME::SavePcbFile(), and SCH_EDIT_FRAME::saveSchematicFile().
|
private |
Execute file writes and git commit on a background thread.
Definition at line 192 of file local_history.cpp.
References HISTORY_LOCK_MANAGER::GetIndex(), HISTORY_LOCK_MANAGER::GetLockError(), HISTORY_LOCK_MANAGER::GetRepository(), historyPath(), index, HISTORY_LOCK_MANAGER::IsLocked(), KICAD_FORMAT::Prettify(), and traceAutoSave.
| bool LOCAL_HISTORY::CommitPending | ( | ) |
Commit any pending modified files to the history repository.
Definition at line 351 of file local_history.cpp.
References CommitSnapshot(), and m_pendingFiles.
| bool LOCAL_HISTORY::CommitSnapshot | ( | const std::vector< wxString > & | aFiles, |
| const wxString & | aTitle ) |
Commit the given files to the local history repository.
Definition at line 647 of file local_history.cpp.
References commitSnapshotWithLock(), Committed, HISTORY_LOCK_MANAGER::GetIndex(), HISTORY_LOCK_MANAGER::GetLockError(), HISTORY_LOCK_MANAGER::GetRepository(), historyPath(), index, HISTORY_LOCK_MANAGER::IsLocked(), Pgm(), and traceAutoSave.
Referenced by CommitFullProjectSnapshot(), CommitPending(), and Init().
| bool LOCAL_HISTORY::EnforceSizeLimit | ( | const wxString & | aProjectPath, |
| size_t | aMaxBytes ) |
Enforce total size limit by rebuilding trimmed history keeping newest commits whose cumulative unique blob sizes fit within limit.
Definition at line 936 of file local_history.cpp.
References dirSizeRecursive(), HISTORY_LOCK_MANAGER::GetRepository(), historyPath(), HISTORY_LOCK_MANAGER::IsLocked(), name, and traceAutoSave.
Referenced by KICAD_MANAGER_FRAME::CloseProject().
| wxString LOCAL_HISTORY::GetHeadHash | ( | const wxString & | aProjectPath | ) |
Return the current head commit hash.
Definition at line 1298 of file local_history.cpp.
References historyPath().
Referenced by KICAD_MANAGER_FRAME::LoadProject().
| bool LOCAL_HISTORY::HeadNewerThanLastSave | ( | const wxString & | aProjectPath | ) |
Return true if the autosave data is newer than the last manual save.
Definition at line 787 of file local_history.cpp.
References historyPath().
| bool LOCAL_HISTORY::HistoryExists | ( | const wxString & | aProjectPath | ) |
Return true if history exists for the project.
Definition at line 732 of file local_history.cpp.
References historyPath().
Referenced by KICAD_MANAGER_FRAME::doReCreateMenuBar(), and ShowRestoreDialog().
| bool LOCAL_HISTORY::Init | ( | const wxString & | aProjectPath | ) |
Initialize the local history repository for the given project path.
Definition at line 359 of file local_history.cpp.
References CommitSnapshot(), historyPath(), name, path, Pgm(), TagSave(), and traceAutoSave.
Referenced by EDA_BASE_FRAME::CommonSettingsChanged(), KICAD_MANAGER_FRAME::LoadProject(), PCB_EDIT_FRAME::OnBoardLoaded(), PCB_EDIT_FRAME::OpenProjectFiles(), and SCH_EDIT_FRAME::OpenProjectFiles().
|
private |
Definition at line 2006 of file local_history.cpp.
References historyPath(), and info.
Referenced by ShowRestoreDialog().
| void LOCAL_HISTORY::NoteFileChange | ( | const wxString & | aFile | ) |
Record that a file has been modified and should be included in the next snapshot.
Definition at line 70 of file local_history.cpp.
References m_pendingFiles, and Pgm().
Referenced by PCB_EDIT_FRAME::OnModify(), and SCH_EDIT_FRAME::OnModify().
| void LOCAL_HISTORY::RegisterSaver | ( | const void * | aSaverObject, |
| const std::function< void(const wxString &, std::vector< HISTORY_FILE_DATA > &)> & | aSaver ) |
Register a saver callback invoked during autosave history commits.
The callback receives the project path and should populate aFileData with serialized content or source paths for inclusion.
| aSaverObject | Unique object pointer identifier for this saver (to prevent duplicate registration) |
| aSaver | The saver callback function |
Definition at line 81 of file local_history.cpp.
References m_savers, and traceAutoSave.
Referenced by KICAD_MANAGER_FRAME::ProjectChanged(), PCB_EDIT_FRAME::ProjectChanged(), and SCH_EDIT_FRAME::ProjectChanged().
| bool LOCAL_HISTORY::RestoreCommit | ( | const wxString & | aProjectPath, |
| const wxString & | aHash, | ||
| wxWindow * | aParent = nullptr ) |
Restore the project files to the state recorded by the given commit hash.
Definition at line 1798 of file local_history.cpp.
References _, collectProjectFiles(), commitSnapshotWithLock(), Error, HISTORY_LOCK_MANAGER::GetIndex(), HISTORY_LOCK_MANAGER::GetRepository(), historyPath(), HISTORY_LOCK_MANAGER::IsLocked(), NoChanges, and traceAutoSave.
Referenced by KICAD_MANAGER_FRAME::LoadProject(), and ShowRestoreDialog().
| bool LOCAL_HISTORY::RunRegisteredSaversAndCommit | ( | const wxString & | aProjectPath, |
| const wxString & | aTitle ) |
Run all registered savers and, if any staged changes differ from HEAD, create a commit.
Definition at line 118 of file local_history.cpp.
References m_saveInProgress, m_savers, Pgm(), and traceAutoSave.
Referenced by EDA_BASE_FRAME::doAutoSave().
| void LOCAL_HISTORY::ShowRestoreDialog | ( | const wxString & | aProjectPath, |
| wxWindow * | aParent ) |
Show a dialog allowing the user to choose a snapshot to restore.
Definition at line 1985 of file local_history.cpp.
References DIALOG_RESTORE_LOCAL_HISTORY::GetSelectedHash(), HistoryExists(), LoadSnapshots(), RestoreCommit(), and DIALOG_SHIM::ShowModal().
Referenced by KICAD_MANAGER_FRAME::RestoreLocalHistory().
| bool LOCAL_HISTORY::TagSave | ( | const wxString & | aProjectPath, |
| const wxString & | aFileType ) |
Tag a manual save in the local history repository.
Definition at line 737 of file local_history.cpp.
References HISTORY_LOCK_MANAGER::GetRepository(), HISTORY_LOCK_MANAGER::IsLocked(), and traceAutoSave.
Referenced by KICAD_MANAGER_FRAME::CloseProject(), Init(), KICAD_MANAGER_FRAME::LoadProject(), PCB_EDIT_FRAME::SavePcbFile(), and SCH_EDIT_FRAME::saveSchematicFile().
| void LOCAL_HISTORY::UnregisterSaver | ( | const void * | aSaverObject | ) |
Unregister a previously registered saver callback.
| aSaverObject | The object pointer that was used to register the saver |
Definition at line 96 of file local_history.cpp.
References m_savers, traceAutoSave, and WaitForPendingSave().
Referenced by KICAD_MANAGER_FRAME::CloseProject(), PCB_EDIT_FRAME::doCloseWindow(), and SCH_EDIT_FRAME::doCloseWindow().
|
private |
Block until any pending background save completes.
Definition at line 341 of file local_history.cpp.
References m_pendingFuture, and traceAutoSave.
Referenced by ClearAllSavers(), UnregisterSaver(), and ~LOCAL_HISTORY().
|
private |
Definition at line 150 of file local_history.h.
Referenced by CommitPending(), and NoteFileChange().
|
private |
Definition at line 155 of file local_history.h.
Referenced by WaitForPendingSave().
|
private |
Definition at line 154 of file local_history.h.
Referenced by RunRegisteredSaversAndCommit().
|
private |
Definition at line 152 of file local_history.h.
Referenced by ClearAllSavers(), RegisterSaver(), RunRegisteredSaversAndCommit(), and UnregisterSaver().