|
KiCad PCB EDA Suite
|
#include <dialogs/git/git_status_entries.h>#include <fstream>#include <map>#include <memory>#include <optional>#include <set>#include <sys/stat.h>#include <mutex>#include <vector>#include <wx/choicdlg.h>#include <wx/dir.h>#include <wx/filename.h>#include <wx/richmsgdlg.h>#include <wx/weakref.h>#include <reporter.h>#include <confirm.h>#include <dialogs/git/dialog_text_diff.h>#include <dialogs/git/git_transfer.h>#include <dialogs/git/git_ui_utils.h>#include <diff_merge/diff_doc_kind.h>#include <diff_merge/diff_scene.h>#include <diff_merge/merge_dispatch.h>#include <git/text_diff.h>#include <git/git_compare_handler.h>#include <git/git_branch_handler.h>#include <eda_base_frame.h>#include <frame_type.h>#include <git/kicad_git_common.h>#include <git/git_status_handler.h>#include <git/project_git_utils.h>#include <i18n_utility.h>#include <kiway.h>#include <kiway_player.h>#include <mail_type.h>#include <pgm_base.h>#include <project.h>#include <project/project_file.h>#include <project/project_local_settings.h>#include <settings/common_settings.h>#include <settings/settings_manager.h>#include <wildcards_and_files_ext.h>Go to the source code of this file.
Functions | |
| static bool | statusToDisplay (KIGIT_COMMON::GIT_STATUS aStatus, wxString &aWord, BITMAPS &aIcon, wxColour &aColour, const KICAD_DIFF::DIFF_COLOR_THEME &aTheme) |
| std::vector< FILE_CHECKLIST_ENTRY > | BuildGitChangeEntries (KIGIT_COMMON &aCommon, const wxString &aProjectPath, bool aDarkTheme) |
| Build the file checklist entries for the project's changed files, transient files filtered out and each path stored relative to the working directory. | |
| EDITOR_SNAPSHOT | CaptureOpenEditorDocs (KIWAY &aKiway) |
| Record the on-disk identity of the open documents, before an operation that may rewrite them. | |
| void | ReloadOpenEditors (KIWAY &aKiway, const EDITOR_SNAPSHOT &aBefore) |
| Tell the open board and schematic editors to reload from disk. | |
| void | ProjectClearOfUncommittedWork (EDA_BASE_FRAME *aFrame, wxWindow *aParent, KIGIT_QUERY &aQuery, std::function< void(const GIT_WORKTREE_STATUS &)> aReady) |
| Check the working tree and Git LFS on a worker, then run aReady on the UI thread when the operation can proceed. | |
| void | SwitchProjectToBranch (EDA_BASE_FRAME *aFrame, wxWindow *aParent, const wxString &aBranch, KIGIT_QUERY &aQuery, std::function< void()> aFinished) |
| Check the working tree on a worker, then confirm switching to aBranch and recheck unsaved editors. | |
| bool | DocumentEditorsDirty (KIWAY &aKiway) |
| Unsaved schematic or board edits can be saved for a commit, even with no changes on disk. | |
| bool | EditorsDirty (KIWAY &aKiway) |
| Unsaved document or library edits block operations that rewrite files. Call on the UI thread. | |
| std::vector< wxString > | LibraryEditorsWithUnsavedChanges (KIWAY &aKiway) |
| Names of the library editors holding unsaved changes. | |
| std::vector< wxString > | ChangedTrackedFilesOutsideProject (KIGIT_COMMON &aCommon, const wxString &aProjectPath) |
| Repository relative paths of tracked files changed outside the project directory, which the checklist does not show. | |
| GIT_WORKTREE_STATUS | ReadGitWorktreeStatus (KIGIT_COMMON &aCommon, const wxString &aProjectPath) |
| Read tracked changes and Git LFS using a captured project path. | |
| bool | ProjectSafeToRewrite (EDA_BASE_FRAME *aFrame, wxWindow *aParent, const GIT_WORKTREE_STATUS &aStatus, bool aAllowTrackedChanges) |
| Combine the repository snapshot with live editor state and explain any refusal. | |
| bool | PrepareEditorsForGitOperation (EDA_BASE_FRAME *aFrame, GIT_EDITOR_PREP aPurpose, bool *aSavedEditors) |
| Offer to save unsaved schematic and board edits before a git operation. | |
| void | ShowGitFileDiff (EDA_BASE_FRAME *aFrame, const wxString &aRelativePath) |
| Open the diff for a changed file, comparing the committed version at HEAD with the working copy. | |
| bool | MaterializeWorkingFile (KIGIT_COMMON &aCommon, GIT_DIFF_WORKSPACE &aWorkspace, const wxString &aRelativePath, GIT_FILE_SIDES &aSides) |
| Write the committed version of a file into aWorkspace and name its working copy beside it. | |
| void | ShowGitCommitDiff (EDA_BASE_FRAME *aFrame, const wxString &aCommitHash, wxWindow *aParentWindow, const wxString &aRelativePath) |
| Open the diff for what a commit changed, comparing it against its parent. | |
| bool | MaterializeCommitFile (KIGIT_COMMON &aCommon, GIT_DIFF_WORKSPACE &aWorkspace, const wxString &aCommitHash, const wxString &aRelativePath, GIT_FILE_SIDES &aSides) |
| Write both sides of one file a commit changed into aWorkspace, the parent's version and the commit's. | |
| std::vector< FILE_CHECKLIST_ENTRY > BuildGitChangeEntries | ( | KIGIT_COMMON & | aCommon, |
| const wxString & | aProjectPath, | ||
| bool | aDarkTheme ) |
Build the file checklist entries for the project's changed files, transient files filtered out and each path stored relative to the working directory.
Shared by the docked commit panel and the advanced window so both show the same list.
Uses project values and the theme captured on the UI thread. The caller holds the session's action lock. This function never reads a live PROJECT or UI settings.
Definition at line 99 of file git_status_entries.cpp.
References _, FILE_CHECKLIST_ENTRY::checked, KICAD_DIFF::DIFF_COLOR_THEME::ForText(), GIT_STATUS_HANDLER::GetFileStatus(), KIGIT_COMMON::GetProjectPrefix(), GIT_STATUS_HANDLER::GetWorkingDirectory(), FILE_CHECKLIST_ENTRY::icon, INVALID_BITMAP, KIGIT::PROJECT_GIT_UTILS::IsTransientGitFile(), KIGIT::PROJECT_GIT_UTILS::IsWithinProjectPath(), FILE_CHECKLIST_ENTRY::label, FILE_CHECKLIST_ENTRY::path, path, FILE_CHECKLIST_ENTRY::section, FILE_CHECKLIST_ENTRY::status, FILE_CHECKLIST_ENTRY::statusColour, and statusToDisplay().
Referenced by BOOST_AUTO_TEST_CASE(), and GIT_COMMIT_PANE::RefreshFileList().
| EDITOR_SNAPSHOT CaptureOpenEditorDocs | ( | KIWAY & | aKiway | ) |
Record the on-disk identity of the open documents, before an operation that may rewrite them.
Takes the KIWAY rather than a frame, because the completion that consumes the snapshot must outlive the window that took it.
Definition at line 310 of file git_status_entries.cpp.
References EDITOR_SNAPSHOT::editors, and EDITOR_SNAPSHOT::settings.
Referenced by GIT_COMMIT_PANE::confirmDiscardFile(), GIT_ADVANCED_DIALOG::ConfirmWorkingTreeChange(), GIT_ADVANCED_DIALOG::ConfirmWorkingTreeChange(), GIT_COMMIT_PANE::finishAbandonOperation(), PANEL_GIT_HISTORY::restoreVersion(), GIT_COMMIT_PANE::startPull(), and SwitchProjectToBranch().
| std::vector< wxString > ChangedTrackedFilesOutsideProject | ( | KIGIT_COMMON & | aCommon, |
| const wxString & | aProjectPath ) |
Repository relative paths of tracked files changed outside the project directory, which the checklist does not show.
Uses a captured project path. The caller holds the action lock.
Definition at line 638 of file git_status_entries.cpp.
References GIT_STATUS_HANDLER::GetFileStatus(), KIGIT_COMMON::GetRepo(), GIT_STATUS_HANDLER::GetWorkingDirectory(), KIGIT::PROJECT_GIT_UTILS::IsWithinProjectPath(), and path.
Referenced by GIT_COMMIT_PANE::abandonOperation(), and ReadGitWorktreeStatus().
| bool DocumentEditorsDirty | ( | KIWAY & | aKiway | ) |
Unsaved schematic or board edits can be saved for a commit, even with no changes on disk.
Library edits do not count. Call on the UI thread.
Definition at line 620 of file git_status_entries.cpp.
Referenced by GIT_COMMIT_PANE::applyStatus(), GIT_COMMIT_PANE::doCommit(), GIT_COMMIT_PANE::onIdle(), and PANEL_GIT_HISTORY::restoreVersion().
| bool EditorsDirty | ( | KIWAY & | aKiway | ) |
Unsaved document or library edits block operations that rewrite files. Call on the UI thread.
Definition at line 626 of file git_status_entries.cpp.
Referenced by GIT_COMMIT_PANE::confirmDiscardFile(), GIT_COMMIT_PANE::finishAbandonOperation(), and GIT_COMMIT_PANE::finishPullConflictPreparation().
| std::vector< wxString > LibraryEditorsWithUnsavedChanges | ( | KIWAY & | aKiway | ) |
Names of the library editors holding unsaved changes.
They cannot be saved by mail, so an operation that rewrites files refuses until the user saves or discards them.
Definition at line 632 of file git_status_entries.cpp.
Referenced by PrepareEditorsForGitOperation(), and PANEL_GIT_HISTORY::restoreVersion().
| bool MaterializeCommitFile | ( | KIGIT_COMMON & | aCommon, |
| GIT_DIFF_WORKSPACE & | aWorkspace, | ||
| const wxString & | aCommitHash, | ||
| const wxString & | aRelativePath, | ||
| GIT_FILE_SIDES & | aSides ) |
Write both sides of one file a commit changed into aWorkspace, the parent's version and the commit's.
False, with the error set, when the commit did not change the file or a side could not be read. The caller holds the session's action lock and keeps the workspace alive until the UI has finished using the materialized documents.
Definition at line 1143 of file git_status_entries.cpp.
References _, KIGIT::ADDED, GIT_FILE_SIDES::after, GIT_FILE_SIDES::before, KIGIT::CompareRefs(), KICAD_DIFF::DocKindFromExtension(), GIT_FILE_SIDES::error, KIGIT_COMMON::GetRepo(), git_repository, GIT_FILE_SIDES::kind, GIT_DIFF_WORKSPACE::Materialize(), and KIGIT::REMOVED.
| bool MaterializeWorkingFile | ( | KIGIT_COMMON & | aCommon, |
| GIT_DIFF_WORKSPACE & | aWorkspace, | ||
| const wxString & | aRelativePath, | ||
| GIT_FILE_SIDES & | aSides ) |
Write the committed version of a file into aWorkspace and name its working copy beside it.
False, with the error set, when the committed side could not be read. The caller holds the session's action lock and keeps the workspace alive until the UI has loaded its documents.
Definition at line 1032 of file git_status_entries.cpp.
References _, GIT_FILE_SIDES::after, GIT_FILE_SIDES::before, KICAD_DIFF::DocKindFromExtension(), GIT_FILE_SIDES::error, KIGIT_COMMON::GetRepo(), GIT_STATUS_HANDLER::GetWorkingDirectory(), git_repository, KIGIT_COMMON::IsPathInHead(), GIT_FILE_SIDES::kind, and GIT_DIFF_WORKSPACE::Materialize().
| bool PrepareEditorsForGitOperation | ( | EDA_BASE_FRAME * | aFrame, |
| GIT_EDITOR_PREP | aPurpose, | ||
| bool * | aSavedEditors = nullptr ) |
Offer to save unsaved schematic and board edits before a git operation.
Returns false when the user cancelled or a save failed. Library edits must be saved or discarded in their editor before a working tree rewrite. They do not block a commit or take part in its save prompt.
When the working tree is about to be rewritten the only choices are to save or to cancel, since a stale editor's next save would overwrite whatever arrived. The project file is written only for a commit, because before a merge it would dirty the file and fail the checkout. The caller must first check LfsRefusal on a worker before saving editors.
| aSavedEditors | When supplied, receives true only after dirty editors were successfully saved. False for Commit Anyway or when no editor needed saving, so a caller need not rescan for changes produced by an editor save. |
Definition at line 750 of file git_status_entries.cpp.
References _, COMMIT, DisplayErrorMessage(), DisplayInfoMessage(), editor, KIWAY::ExpressMail(), EDA_BASE_FRAME::GetSettingsManager(), KIWAY_HOLDER::Kiway(), LibraryEditorsWithUnsavedChanges(), message, name, SETTINGS_MANAGER::SaveProject(), and WORKING_TREE.
Referenced by GIT_ADVANCED_DIALOG::ConfirmWorkingTreeChange(), and GIT_COMMIT_PANE::saveForCommit().
| void ProjectClearOfUncommittedWork | ( | EDA_BASE_FRAME * | aFrame, |
| wxWindow * | aParent, | ||
| KIGIT_QUERY & | aQuery, | ||
| std::function< void(const GIT_WORKTREE_STATUS &)> | aReady ) |
Check the working tree and Git LFS on a worker, then run aReady on the UI thread when the operation can proceed.
Otherwise explain why it is refused. Rechecks unsaved editor changes and the current session after the read. aReady receives the snapshot to recheck editors after any confirmation. aQuery belongs to the window starting the action.
Definition at line 458 of file git_status_entries.cpp.
Referenced by GIT_ADVANCED_DIALOG::RefuseOverUncommittedWork(), and PROJECT_TREE_PANE::switchGitBranch().
| bool ProjectSafeToRewrite | ( | EDA_BASE_FRAME * | aFrame, |
| wxWindow * | aParent, | ||
| const GIT_WORKTREE_STATUS & | aStatus, | ||
| bool | aAllowTrackedChanges = false ) |
Combine the repository snapshot with live editor state and explain any refusal.
Called on the UI thread before rewriting files, and again after a confirmation that could allow edits.
Definition at line 736 of file git_status_entries.cpp.
References DisplayInfoMessage(), KIWAY_HOLDER::Kiway(), message, and GIT_WORKTREE_STATUS::RefusalMessage().
Referenced by PANEL_GIT_STASHES::checkStashChanges(), GIT_ADVANCED_DIALOG::ConfirmWorkingTreeChange(), GIT_COMMIT_PANE::onPushDone(), GIT_COMMIT_PANE::submitPull(), and SwitchProjectToBranch().
| GIT_WORKTREE_STATUS ReadGitWorktreeStatus | ( | KIGIT_COMMON & | aCommon, |
| const wxString & | aProjectPath ) |
Read tracked changes and Git LFS using a captured project path.
The caller holds the action lock on a worker. An unavailable repository leaves checked false and cannot authorize a rewrite.
Definition at line 672 of file git_status_entries.cpp.
References ChangedTrackedFilesOutsideProject(), GIT_WORKTREE_STATUS::checked, KIGIT_COMMON::GetRepo(), GIT_WORKTREE_STATUS::hasTrackedChanges, KIGIT_COMMON::HasUncommittedTrackedChanges(), GIT_WORKTREE_STATUS::lfsMessage, KIGIT::PROJECT_GIT_UTILS::LfsRefusal(), and GIT_WORKTREE_STATUS::outsideProject.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), GIT_COMMIT_PANE::onPushDone(), and GIT_COMMIT_PANE::submitPull().
| void ReloadOpenEditors | ( | KIWAY & | aKiway, |
| const EDITOR_SNAPSHOT & | aBefore ) |
Tell the open board and schematic editors to reload from disk.
Only a document whose files changed since aBefore is reloaded, because reloading discards undo history and the view state. An editor holding unsaved changes to one asks whether to reload or keep the edits. Settings changes reach editors whose document did not reload.
aBefore must come from CaptureOpenEditorDocs() taken before the operation.
Definition at line 323 of file git_status_entries.cpp.
References EDITOR_SNAPSHOT::editors, KIWAY::ExpressMail(), PROJECT::GetLocalSettings(), PROJECT::GetProjectFile(), PROJECT::GetProjectPath(), PGM_BASE::GetSettingsManager(), JSON_SETTINGS::LoadFromFile(), PROJECT_FILE::LoadFromFile(), path, Pgm(), KIWAY::Player(), SETTINGS_MANAGER::Prj(), and EDITOR_SNAPSHOT::settings.
Referenced by GIT_COMMIT_PANE::confirmDiscardFile(), GIT_COMMIT_PANE::finishAbandonOperation(), GIT_COMMIT_PANE::finishPullConflictPreparation(), PANEL_GIT_HISTORY::restoreVersion(), GIT_COMMIT_PANE::startPull(), and SwitchProjectToBranch().
| void ShowGitCommitDiff | ( | EDA_BASE_FRAME * | aFrame, |
| const wxString & | aCommitHash, | ||
| wxWindow * | aParentWindow = nullptr, | ||
| const wxString & | aRelativePath = wxEmptyString ) |
Open the diff for what a commit changed, comparing it against its parent.
When the commit changed more than one file the user picks which one to compare. Design files open the visual diff and other text files a line diff.
| aFrame | Frame whose project supplies the repository. |
| aCommitHash | Hash of the commit to inspect. |
| aParentWindow | Window to parent the diff to, or null to use aFrame. Pass the calling dialog so it stays open behind the diff instead of being dismissed. |
Definition at line 1066 of file git_status_entries.cpp.
References changedPaths(), and KIGIT::CompareRefs().
Referenced by PANEL_GIT_STASHES::PANEL_GIT_STASHES().
| void ShowGitFileDiff | ( | EDA_BASE_FRAME * | aFrame, |
| const wxString & | aRelativePath ) |
Open the diff for a changed file, comparing the committed version at HEAD with the working copy.
Design files open the visual diff, other text files a line diff, and a new file is compared against an empty committed side. Binary content gets a message instead.
| aFrame | Frame to parent the diff to, and whose project supplies the repository. |
| aRelativePath | Path of the file relative to the repository working directory. |
Definition at line 1025 of file git_status_entries.cpp.
Referenced by GIT_COMMIT_PANE::onFileActivated(), and GIT_COMMIT_PANE::onShowDiff().
|
static |
Definition at line 68 of file git_status_entries.cpp.
References _, KICAD_DIFF::DIFF_COLOR_THEME::added, KICAD_DIFF::DIFF_COLOR_THEME::conflict, git_add, git_conflict, git_delete, git_modified, KIGIT_COMMON::GIT_STATUS_ADDED, KIGIT_COMMON::GIT_STATUS_CONFLICTED, KIGIT_COMMON::GIT_STATUS_DELETED, KIGIT_COMMON::GIT_STATUS_MODIFIED, KIGIT_COMMON::GIT_STATUS_UNTRACKED, KICAD_DIFF::DIFF_COLOR_THEME::modified, KICAD_DIFF::DIFF_COLOR_THEME::removed, and KIGFX::COLOR4D::ToColour().
Referenced by BuildGitChangeEntries().
| void SwitchProjectToBranch | ( | EDA_BASE_FRAME * | aFrame, |
| wxWindow * | aParent, | ||
| const wxString & | aBranch, | ||
| KIGIT_QUERY & | aQuery, | ||
| std::function< void()> | aFinished = {} ) |
Check the working tree on a worker, then confirm switching to aBranch and recheck unsaved editors.
On success the editors reload and every Git surface refreshes. aQuery belongs to the window starting the action and cancels the continuation when that window closes. aFinished runs after success or refusal, while the owner still exists.
Definition at line 469 of file git_status_entries.cpp.
References _, CaptureOpenEditorDocs(), Conflict, DisplayErrorMessage(), DisplayInfoMessage(), Error, KIGIT_ERRORS::GetErrorString(), KIGIT_COMMON::GetLastGitError(), IsOK(), ProjectSafeToRewrite(), ReloadOpenEditors(), result, Success, GIT_BRANCH_HANDLER::SwitchToBranch(), and KIGIT::TryLockAction().
Referenced by PROJECT_TREE_PANE::switchGitBranch(), and GIT_ADVANCED_DIALOG::SwitchToBranch().