31#include <wx/choicdlg.h>
33#include <wx/filename.h>
34#include <wx/richmsgdlg.h>
35#include <wx/weakref.h>
75 aWord =
_(
"Modified" );
86 aWord =
_(
"Deleted" );
91 aWord =
_(
"Conflict" );
95 default:
return false;
103 std::vector<FILE_CHECKLIST_ENTRY> entries;
113 std::map<wxString, FileStatus> statusMap = handler.
GetFileStatus( *prefix,
true );
116 for(
const auto& [
path, fileStatus] : statusMap )
129 wxString relativePath =
path;
131 if( relativePath.StartsWith( workDir ) )
132 relativePath = relativePath.Mid( workDir.length() );
135 relativePath.Replace( wxS(
"\\" ), wxS(
"/" ) );
141 bool untracked = ( fileStatus.gitStatus & GIT_STATUS_WT_NEW )
142 && !( fileStatus.gitStatus & GIT_STATUS_INDEX_NEW );
147 const wxString pathPrefix = relativePath.Left( prefix->length() );
150 bool inProject = pathPrefix.CmpNoCase( *prefix ) == 0;
152 bool inProject = pathPrefix == *prefix;
164 entry.
path = relativePath;
169 entries.push_back( entry );
187const EDITOR_DOC g_editorDocs[] = {
195bool makeFileStamp(
const wxFileName& aFn,
FILE_STAMP& aOut )
197 if( !aFn.IsOk() || !aFn.FileExists() )
200 wxString
path = aFn.GetFullPath();
203 aOut.
modified = aFn.GetModificationTime().GetValue().GetValue();
207 if( stat(
path.fn_str(), &st ) != 0 )
211 aOut.
modified =
static_cast<long long>( st.st_mtimespec.tv_sec ) * 1000000000LL + st.st_mtimespec.tv_nsec;
213 aOut.
modified =
static_cast<long long>( st.st_mtim.tv_sec ) * 1000000000LL + st.st_mtim.tv_nsec;
217 aOut.
size =
static_cast<long long>( aFn.GetSize().GetValue() );
227 if( makeFileStamp( aFn, stamp ) )
228 aSnapshot.
files[aFn.GetFullPath()] = stamp;
249 if( scanRoot.IsEmpty() )
252 if( !scanRoot.IsEmpty() )
254 wxArrayString sheetFiles;
255 wxDir::GetAllFiles( scanRoot, &sheetFiles, wxS(
"*.kicad_sch" ), wxDIR_FILES | wxDIR_DIRS );
258 for(
const wxString& sheet : sheetFiles )
259 addFileToSnapshot(
result, wxFileName( sheet ) );
280 addFileToSnapshot(
result, prl );
288 std::set<wxString> changed;
290 for(
const auto& [
path, stamp] : aBefore.
files )
294 if( it == aAfter.
files.end() || it->second != stamp )
295 changed.insert(
path );
298 for(
const auto& [
path, stamp] : aAfter.
files )
301 changed.insert(
path );
314 for(
const EDITOR_DOC& doc : g_editorDocs )
315 before.
editors[doc.frameType] = documentSnapshot( aKiway, doc.frameType );
317 before.
settings = settingsSnapshot();
327 bool settingsChanged = !changedFilesBetween( aBefore.
settings, settingsSnapshot() ).empty();
329 if( settingsChanged )
339 for(
const EDITOR_DOC& doc : g_editorDocs )
341 if( !aKiway.
Player( doc.frameType,
false ) )
346 auto it = aBefore.
editors.find( doc.frameType );
348 std::set<wxString> changed = changedFilesBetween( before, documentSnapshot( aKiway, doc.frameType ) );
350 if( changed.empty() )
354 if( settingsChanged )
356 std::string settingsPayload;
357 aKiway.
ExpressMail( doc.frameType, doc.settingsMail, settingsPayload );
367 for(
const wxString&
path : changed )
368 joined +=
path + wxS(
"\n" );
370 std::string payload = joined.utf8_string();
371 aKiway.
ExpressMail( doc.frameType, doc.reloadMail, payload );
381struct WORKTREE_QUERY_CONTEXT
383 WORKTREE_QUERY_CONTEXT( EDA_BASE_FRAME* aFrame, wxWindow* aParent ) :
385 parent( aParent ? aParent : aFrame ),
386 session( aFrame->
Prj().GetGitCommon() )
392 return frame.get() && parent.get() && !frame->IsBeingDeleted() && !parent->IsBeingDeleted();
395 bool IsCurrent()
const
397 return IsAlive() && !session->IsShuttingDown() && frame->Prj().GetGitCommon() == session
399 && !frame->Prj().GetLocalSettings().m_GitIntegrationDisabled;
402 wxWeakRef<EDA_BASE_FRAME> frame;
403 wxWeakRef<wxWindow> parent;
404 std::shared_ptr<KIGIT_COMMON> session;
412 std::function<
void()> aFinished = {} )
416 GIT_WORKTREE_STATUS worktree;
417 wxString currentBranch;
421 auto context = std::make_shared<WORKTREE_QUERY_CONTEXT>( aFrame, aParent );
422 auto outcome = std::make_shared<OUTCOME>();
428 outcome->currentBranch = aCommon.GetCurrentBranchName();
429 outcome->worktree = ReadGitWorktreeStatus( aCommon, projectPath );
431 [context, outcome, aReady, aFinished]()
435 if( !context->IsCurrent() )
440 if( !ProjectSafeToRewrite( context->frame, context->parent, outcome->worktree ) )
443 aReady( outcome->currentBranch, outcome->worktree );
448 if( aFinished && context->IsAlive() )
461 checkProjectWorktree( aFrame, aParent, aQuery,
470 std::function<
void()> aFinished )
472 if( aBranch.IsEmpty() )
480 auto context = std::make_shared<WORKTREE_QUERY_CONTEXT>( aFrame, aParent );
482 checkProjectWorktree(
483 aFrame, aParent, aQuery,
486 const wxWeakRef<EDA_BASE_FRAME>& frame = context->frame;
487 const wxWeakRef<wxWindow>& parent = context->parent;
488 const std::shared_ptr<KIGIT_COMMON>& common = context->session;
490 if( aBranch == aCurrentBranch )
493 if( !
IsOK( parent, wxString::Format(
_(
"Switch to branch '%s'? This replaces the project files "
494 "on disk with that branch's version." ),
501 if( !context->IsCurrent() )
511 if( !context->IsCurrent() )
523 if( !lock.owns_lock() )
533 common->UpdateCurrentBranchInfo();
544 if( resultError.
summary.IsEmpty() )
547 wxString::Format(
_(
"Could not switch to branch '%s'." ), aBranch ),
559 common->NotifyRefreshListeners();
561 std::move( aFinished ) );
568enum class EDITOR_SCOPE
585const GIT_EDITOR g_gitEditors[] = {
594std::vector<const GIT_EDITOR*> dirtyEditors(
KIWAY& aKiway, EDITOR_SCOPE aScope )
596 std::vector<const GIT_EDITOR*> dirty;
598 for(
const GIT_EDITOR&
editor : g_gitEditors )
600 bool document = !
editor.library;
602 if( ( aScope == EDITOR_SCOPE::DOCUMENTS && !document ) || ( aScope == EDITOR_SCOPE::LIBRARIES && document ) )
618 if( payload ==
"yes" )
619 dirty.push_back( &
editor );
623 dirty.push_back( &
editor );
631enum class EDITOR_SAVE
640EDITOR_SAVE saveEditorsBeforeRewrite(
EDA_BASE_FRAME* aFrame, wxWindow* aParent, EDITOR_SCOPE aScope )
642 std::vector<const GIT_EDITOR*> dirty = dirtyEditors( aFrame->
Kiway(), aScope );
645 return EDITOR_SAVE::NONE_NEEDED;
649 for(
const GIT_EDITOR*
editor : dirty )
650 listed += wxString::Format( wxS(
"\n - %s" ), wxGetTranslation(
editor->label ) );
652 bool libraries = aScope == EDITOR_SCOPE::LIBRARIES;
653 wxString
message = libraries ?
_(
"The following editors have unsaved library changes:%s\n\n"
654 "This rewrites files on disk. Save the libraries first, "
655 "otherwise the next save would overwrite what arrives." )
656 :
_(
"The following editors have unsaved changes:%s\n\n"
657 "This rewrites those files on disk. They must be saved "
658 "first, otherwise the next save would overwrite what "
661 wxRichMessageDialog dlg( aParent, wxString::Format(
message, listed ),
662 libraries ?
_(
"Unsaved Library Changes" ) :
_(
"Unsaved Changes" ),
663 wxYES_NO | wxYES_DEFAULT | wxICON_WARNING | wxCENTER );
664 dlg.SetYesNoLabels( libraries ?
_(
"&Save All and Continue" ) :
_(
"&Save and Continue" ),
_(
"Cancel" ) );
666 if( dlg.ShowModal() != wxID_YES )
667 return EDITOR_SAVE::CANCELLED;
669 for(
const GIT_EDITOR*
editor : dirty )
674 if( payload !=
"success" )
677 wxString::Format(
_(
"Could not save %s." ), wxGetTranslation(
editor->label ) ) );
678 return EDITOR_SAVE::CANCELLED;
682 return EDITOR_SAVE::SAVED;
686std::vector<wxString> dirtyEditorNames(
KIWAY& aKiway, EDITOR_SCOPE aScope )
688 std::vector<wxString> names;
690 for(
const GIT_EDITOR*
editor : dirtyEditors( aKiway, aScope ) )
691 names.push_back( wxGetTranslation(
editor->label ) );
701 return !dirtyEditors( aKiway, EDITOR_SCOPE::DOCUMENTS ).empty();
707 return !dirtyEditors( aKiway, EDITOR_SCOPE::ALL ).empty();
713 return dirtyEditorNames( aKiway, EDITOR_SCOPE::LIBRARIES );
719 std::vector<wxString> paths;
727 for(
const auto& [
path, fileStatus] : handler.
GetFileStatus( wxEmptyString,
true ) )
731 if( ( fileStatus.gitStatus & ~( GIT_STATUS_WT_NEW | GIT_STATUS_IGNORED ) ) == GIT_STATUS_CURRENT )
739 wxString relativePath =
path;
741 if( relativePath.StartsWith( workDir ) )
742 relativePath = relativePath.Mid( workDir.length() );
744 paths.push_back( relativePath );
770 bool aAllowTrackedChanges )
const
772 if( !aUnsavedEditors.empty() )
776 for(
const wxString&
name : aUnsavedEditors )
777 listed += wxString::Format( wxS(
"\n - %s" ),
name );
779 wxString
message = aAllowTrackedChanges
780 ?
_(
"The following editors have unsaved changes:%s\n\n"
781 "Save or discard those changes before stashing." )
782 :
_(
"The following editors have unsaved changes:%s\n\n"
783 "Save or discard those changes first. If saving leaves uncommitted "
784 "files, commit or stash them before trying again." );
786 return wxString::Format(
message, listed );
790 return _(
"Could not check the working files. Try again before rewriting project files." );
796 return wxEmptyString;
803 listed += wxS(
"\n " ) +
path;
805 return wxString::Format(
_(
"There are uncommitted changes elsewhere in this repository:%s\n\n"
806 "Commit or discard them from that project first, then try again." ),
810 return _(
"There are changes that are not committed yet, and this would run over them. "
811 "Commit them first, or set them aside with Stash Changes." );
816 bool aAllowTrackedChanges )
818 wxWindow* parent = aParent ? aParent : aFrame;
820 switch( saveEditorsBeforeRewrite( aFrame, parent, EDITOR_SCOPE::LIBRARIES ) )
822 case EDITOR_SAVE::CANCELLED:
return false;
823 case EDITOR_SAVE::NONE_NEEDED:
break;
825 case EDITOR_SAVE::SAVED:
828 ?
_(
"The libraries were saved. Choose the command again to continue." )
829 :
_(
"The libraries were saved. Commit those changes, or set them "
830 "aside with Stash Changes, then choose the command again." ) );
834 std::vector<wxString> unsaved = dirtyEditorNames( aFrame->
Kiway(), EDITOR_SCOPE::ALL );
848 *aSavedEditors =
false;
854 for( EDITOR_SCOPE scope : { EDITOR_SCOPE::LIBRARIES, EDITOR_SCOPE::DOCUMENTS } )
856 EDITOR_SAVE saved = saveEditorsBeforeRewrite( aFrame, aFrame, scope );
858 if( saved == EDITOR_SAVE::CANCELLED )
861 if( saved == EDITOR_SAVE::SAVED && aSavedEditors )
862 *aSavedEditors =
true;
868 std::vector<const GIT_EDITOR*> dirty = dirtyEditors( aFrame->
Kiway(), EDITOR_SCOPE::DOCUMENTS );
875 for(
const GIT_EDITOR*
editor : dirty )
876 listed += wxString::Format( wxS(
"\n - %s" ), wxGetTranslation(
editor->label ) );
878 wxRichMessageDialog dlg( aFrame,
879 wxString::Format(
_(
"The following editors have unsaved changes:%s\n\n"
880 "Save them and review the updated file list before committing?" ),
882 _(
"Unsaved Changes" ), wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING | wxCENTER );
883 dlg.SetYesNoCancelLabels(
_(
"&Save and Review" ),
_(
"Commit &Anyway" ),
_(
"Cancel" ) );
885 int answer = dlg.ShowModal();
887 if( answer == wxID_CANCEL )
890 if( answer == wxID_YES )
892 for(
const GIT_EDITOR*
editor : dirty )
897 if( payload !=
"success" )
900 wxString::Format(
_(
"Could not save %s." ), wxGetTranslation(
editor->label ) ) );
909 *aSavedEditors =
true;
918 m_root.MakeDirectory( wxS(
"kicad_gitdiff_" ), 0700 );
926 return wxEmptyString;
928 const wxString sep = wxFileName::GetPathSeparator();
934 wxString dir =
Root() + sep + wxString::Format( wxS(
"s%d" ),
m_slot++ );
937 return wxEmptyString;
939 wxString
path = dir + sep + aRelPath;
941 return wxFileName::FileExists(
path ) ?
path : wxString( wxEmptyString );
944 wxString
path =
Root() + sep + wxString::Format( wxS(
"s%d_" ),
m_slot++ ) + wxFileName( aRelPath ).GetFullName();
947 return wxEmptyString;
961struct MODAL_GIT_DIFF_REQUEST
963 MODAL_GIT_DIFF_REQUEST(
EDA_BASE_FRAME* aFrame, wxWindow* aParent ) :
966 session( aFrame->
Prj().GetGitCommon() )
970 bool IsCurrent()
const
972 return frame.get() && parent.get() && !frame->IsBeingDeleted() && !parent->IsBeingDeleted()
973 && frame->Prj().GetGitCommon() == session && !session->IsShuttingDown();
976 wxWeakRef<EDA_BASE_FRAME> frame;
977 wxWeakRef<wxWindow> parent;
978 std::shared_ptr<KIGIT_COMMON> session;
983struct MODAL_GIT_DIFF_RESULT
985 std::unique_ptr<GIT_DIFF_WORKSPACE> workspace;
986 GIT_FILE_SIDES sides;
987 std::vector<KIGIT::TEXT_DIFF_LINE> textLines;
992std::string readDiffText(
const wxString& aPath )
994 if( aPath.IsEmpty() )
997 std::ifstream in( aPath.fn_str(), std::ios::binary );
998 return std::string( ( std::istreambuf_iterator<char>( in ) ), std::istreambuf_iterator<char>() );
1004void loadModalGitDiff(
const std::shared_ptr<MODAL_GIT_DIFF_REQUEST>& aRequest,
const wxString& aRelativePath,
1005 const wxString& aCommitHash )
1007 auto result = std::make_shared<MODAL_GIT_DIFF_RESULT>();
1008 result->sides.error =
_(
"Could not compare this file." );
1010 aRequest->query.Run(
1014 result->workspace = std::make_unique<GIT_DIFF_WORKSPACE>();
1016 if( !result->workspace->IsOk() )
1018 result->sides.error = _(
"Could not create a temporary directory for the diff." );
1023 aCommitHash.IsEmpty()
1033 std::string before = readDiffText( result->sides.before );
1034 std::string after = readDiffText( result->sides.after );
1036 if( KIGIT::TextLooksBinary( before ) || KIGIT::TextLooksBinary( after ) )
1038 result->sides.error = wxString::Format(
1039 _(
"'%s' is not a plain text file. KiCad compares design files and text files "
1040 "only, so there is no comparison to show." ),
1051 [aRequest,
result, aRelativePath, aCommitHash]()
1053 if( !aRequest->IsCurrent() )
1056 wxWindow* parent = aRequest->parent.get();
1060 if( !
result->sides.error.IsEmpty() )
1073 wxString beforeLabel = aCommitHash.IsEmpty()
1074 ?
_(
"BASE (HEAD)" )
1075 : wxString::
Format(
_(
"PARENT (of %s)" ), aCommitHash );
1076 wxString afterLabel = aCommitHash.IsEmpty() ?
_(
"WORKING (changes)" )
1077 : wxString::Format(
_(
"COMMIT (%s)" ), aCommitHash );
1083 result->sides.after, beforeLabel, afterLabel, parent, &
reporter );
1085 if( aRequest->IsCurrent() &&
reporter.HasMessage() )
1094 const std::vector<GIT_IGNORE_TARGET>& aTargets )
1098 if( !common->GetRepo() || aTargets.empty() )
1102 const bool byExtension =
1106 std::vector<wxString> rules;
1113 if( !rule.IsEmpty() )
1114 rules.push_back( rule );
1130 common->NotifyRefreshListeners();
1135 std::vector<wxString> stillIgnored;
1139 std::unique_lock<std::mutex> lock = common->TryLockAction();
1141 if( !lock.owns_lock() )
1147 stillIgnored.push_back( target.path );
1151 if( stillIgnored.empty() )
1155 stillIgnored.size() == 1
1156 ? wxString::Format(
_(
"'%s' is still ignored by another rule." ), stillIgnored.front() )
1157 : wxString::Format(
_(
"%zu of the selected files are still ignored by another rule." ),
1158 stillIgnored.size() );
1161 wxString::Format(
_(
"That rule covers more than this, so it was left in "
1162 "place. Edit '%s' to change it." ),
1163 ignoreFile.GetFullPath() ) );
1169 auto request = std::make_shared<MODAL_GIT_DIFF_REQUEST>( aFrame, aFrame );
1170 loadModalGitDiff( request, aRelativePath, wxEmptyString );
1193 if( inHead && aSides.
before.IsEmpty() )
1195 aSides.
error = wxString::Format(
_(
"Could not read the committed version of '%s'." ), aRelativePath );
1201 if( !wxFileName::FileExists( aSides.
after ) )
1202 aSides.
after.clear();
1209 const wxString& aRelativePath )
1211 auto request = std::make_shared<MODAL_GIT_DIFF_REQUEST>( aFrame, aParentWindow ? aParentWindow : aFrame );
1215 if( !aRelativePath.IsEmpty() )
1217 loadModalGitDiff( request, aRelativePath, aCommitHash );
1221 auto changedPaths = std::make_shared<std::vector<wxString>>();
1227 git_repository* repo = aCommon.GetRepo();
1229 git_object* commitObj = nullptr;
1232 if( git_revparse_single( &commitObj, repo, aCommitHash.utf8_string().c_str() ) == GIT_OK )
1234 if( git_object_type( commitObj ) == GIT_OBJECT_COMMIT
1235 && git_commit_parentcount( reinterpret_cast<git_commit*>( commitObj ) ) > 0 )
1237 parentRef = aCommitHash + wxT(
"^" );
1240 git_object_free( commitObj );
1248 if( !request->IsCurrent() )
1251 wxWindow* parent = request->parent.get();
1263 wxArrayString choices;
1266 choices.Add(
path );
1268 int sel = wxGetSingleChoiceIndex(
_(
"This commit changed more than one file. "
1269 "Select one to compare:" ),
1270 _(
"Select File to Compare" ), choices, parent );
1275 chosen = ( *changedPaths )[sel];
1279 if( request->IsCurrent() )
1280 loadModalGitDiff( request, chosen, aCommitHash );
1297 git_object* commitObj =
nullptr;
1298 unsigned parentCount = 0;
1300 if( git_revparse_single( &commitObj, repo, aCommitHash.utf8_string().c_str() ) == GIT_OK )
1302 if( git_object_type( commitObj ) == GIT_OBJECT_COMMIT )
1303 parentCount = git_commit_parentcount(
reinterpret_cast<git_commit*
>( commitObj ) );
1305 if( parentCount > 0 )
1306 parentRef = aCommitHash + wxT(
"^" );
1308 git_object_free( commitObj );
1313 if( file.path != aRelativePath )
1324 wxString parentPath = file.oldPath.IsEmpty() ? file.path : file.oldPath;
1331 if( ( hasParent && aSides.
before.IsEmpty() ) || ( hasCommit && aSides.
after.IsEmpty() ) )
1333 aSides.
error =
_(
"Could not read this commit's file contents." );
1342 if( parentCount > 2 )
1345 aSides.
after = aWorkspace.
Materialize( repo, aCommitHash + wxT(
"^3" ), aRelativePath, aSides.
kind );
1347 if( !aSides.
after.IsEmpty() )
1351 aSides.
error = wxString::Format(
_(
"This commit did not change '%s'." ), aRelativePath );
BITMAPS
A list of all bitmap identifiers.
Read-only line diff, for the file types that have no visual diff.
The base frame for deriving all KiCad main window classes.
SETTINGS_MANAGER * GetSettingsManager() const
virtual wxString GetCurrentFileName() const
Get the full filename + path of the currently opened file in the frame.
virtual bool IsContentModified() const
Get if the contents of the frame have been modified since the last save.
BranchResult SwitchToBranch(const wxString &aBranchName)
Switch to the specified branch.
A private scratch directory for extracting committed file versions to diff, removed when this object ...
bool IsOk() const
True when the scratch directory was created.
const wxString & Root() const
The scratch directory, for callers that lay out their own files (e.g. footprint libraries).
wxString Materialize(git_repository *aRepo, const wxString &aRef, const wxString &aRelPath, KICAD_DIFF::DOC_KIND aKind)
Extract aRelPath at aRef into a uniquely named slot and return the path to load, or an empty string w...
std::map< wxString, FileStatus > GetFileStatus(const wxString &aPathspec=wxEmptyString, bool aChangedOnly=false)
Get detailed file status for all files in the specified path.
wxString GetWorkingDirectory()
Get the repository working directory path.
virtual bool LoadFromFile(const wxString &aDirectory="")
Loads the backing file from disk and then calls Load()
wxColour ToColour() const
static bool WriteBlobToFile(git_repository *aRepo, const wxString &aRef, const wxString &aPath, const wxString &aDestPath)
Write a file as it exists at a git ref to a path on disk, so a committed version can be diffed.
static bool IsTransientGitFile(const wxFileName &aFile)
Match a project-relative path against the shared transient patterns.
static bool WriteTreeToDir(git_repository *aRepo, const wxString &aRef, const wxString &aDestDir)
Check out a whole tree into a directory, leaving the repository's working copy and index alone.
static bool IsWithinProjectPath(const wxString &aAbsPath, const wxString &aProjectPath)
Test whether an absolute file path lives inside the current project directory.
static wxString LfsRefusal(KIGIT_COMMON *aCommon)
Return a refusal message for LFS files or an unknown project folder, otherwise empty.
The project's git session.
bool HasUncommittedTrackedChanges(bool *aReadOk=nullptr) const
std::optional< wxString > GetProjectPrefix() const
Project folder relative to the repository, with a trailing slash.
git_repository * GetRepo() const
wxString GetProjectDir() const
Return the path set by SetProjectDir(), or the repository's working directory.
bool IsPathInHead(const wxString &aPath)
True when the working directory relative path exists in the HEAD commit's tree.
static wxString GetLastGitError()
libgit2's last message, without credentials from any URL it quotes, so it is safe to show or trace.
KIGIT_ERROR_MESSAGE PopError()
Take the newest error with its details. Both are empty when none is queued.
Read repository state without blocking the UI.
void Run(std::shared_ptr< KIGIT_COMMON > aSession, std::function< void(KIGIT_COMMON &)> aWork, std::function< void()> aDone)
Run aWork under the session's action lock on a worker, then aDone on the UI thread.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual SETTINGS_MANAGER & GetSettingsManager() const
bool LoadFromFile(const wxString &aDirectory="") override
Loads the backing file from disk and then calls Load()
Container for project specific data.
virtual std::shared_ptr< KIGIT_COMMON > GetGitCommon() const
This project's Git session, created empty on first use.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
virtual PROJECT_FILE & GetProjectFile() const
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
A wrapper for reporting to a wxString object.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
Base window classes and related definitions.
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
@ FRAME_SCH_SYMBOL_EDITOR
bool PrepareEditorsForGitOperation(EDA_BASE_FRAME *aFrame, GIT_EDITOR_PREP aPurpose, bool *aSavedEditors)
Offer to save unsaved schematic and board edits before a git operation.
std::vector< wxString > ChangedTrackedFilesOutsideProject(KIGIT_COMMON &aCommon, const wxString &aProjectPath)
Repository relative paths of tracked files changed outside the project directory, which the checklist...
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.
EDITOR_SNAPSHOT CaptureOpenEditorDocs(KIWAY &aKiway)
Record the on-disk identity of the open documents, before an operation that may rewrite them.
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.
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 ea...
void ChangeGitIgnore(EDA_BASE_FRAME *aFrame, wxWindow *aParent, GIT_IGNORE_CHANGE aChange, const std::vector< GIT_IGNORE_TARGET > &aTargets)
Write a change to the project's ignored files and refresh every Git surface.
void ReloadOpenEditors(KIWAY &aKiway, const EDITOR_SNAPSHOT &aBefore)
Tell the open board and schematic editors to reload from disk.
std::vector< wxString > LibraryEditorsWithUnsavedChanges(KIWAY &aKiway)
Names of the library editors holding unsaved changes.
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 c...
GIT_WORKTREE_STATUS ReadGitWorktreeStatus(KIGIT_COMMON &aCommon, const wxString &aProjectPath)
Read tracked changes and Git LFS using a captured project path.
bool DocumentEditorsDirty(KIWAY &aKiway)
Unsaved schematic or board edits can be saved for a commit, even with no changes on disk.
static bool statusToDisplay(KIGIT_COMMON::GIT_STATUS aStatus, wxString &aWord, BITMAPS &aIcon, wxColour &aColour, const KICAD_DIFF::DIFF_COLOR_THEME &aTheme)
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 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.
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 EditorsDirty(KIWAY &aKiway)
Unsaved document or library edits block operations that rewrite files. Call on the UI thread.
GIT_IGNORE_CHANGE
Which change to the project's ignored files a menu item asks for.
@ IGNORE_PATH
Ignore the paths themselves.
@ KEEP_EXTENSION
Stop ignoring every file sharing the paths' extension.
@ IGNORE_EXTENSION
Ignore every file sharing the paths' extension.
GIT_EDITOR_PREP
What the caller is about to do, which decides the wording and whether the project file is written.
@ WORKING_TREE
The working files are about to be rewritten, by a pull, branch switch or stash.
static const std::string ProjectLocalSettingsFileExtension
Some functions to handle hotkeys in KiCad.
static std::vector< std::string > changedPaths(git_repository *aRepo)
MAIL_T
The set of mail types sendable via KIWAY::ExpressMail() and supplied as the aCommand parameter to tha...
@ MAIL_SCH_PROJECT_SETTINGS_CHANGED
@ MAIL_PCB_PROJECT_SETTINGS_CHANGED
DOC_KIND DocKindFromExtension(const wxString &aPath)
Map a path's extension to a DOC_KIND (.kicad_pcb -> PCB, .kicad_sch -> SCH, .kicad_sym -> SYM_LIB,...
DOC_KIND
Document type a diff/merge entry point should route to, derived from a file path's extension.
int DispatchOpenDiffDialog(KIWAY &aKiway, DOC_KIND aKind, const wxString &aFileA, const wxString &aFileB, const wxString &aLabelA, const wxString &aLabelB, wxWindow *aParent, REPORTER *aReporter)
Open DIALOG_KICAD_DIFF on two files by calling the owning kiface's KIFACE_OPEN_DIFF_DIALOG function e...
@ ALL
All except INITIAL_ADD.
std::vector< CHANGED_FILE > CompareRefs(git_repository *aRepo, const wxString &aBaseRef, const wxString &aHeadRef)
Compare two git refs (branch / tag / commit OID) within a repository and return the per-file change l...
std::vector< wxString > SplitTextLines(const std::string &aContent)
Tolerates CRLF endings and content that is not valid UTF-8.
APIEXPORT bool AddIgnoreRules(const wxFileName &aIgnoreFile, const std::vector< wxString > &aRules, const wxString &aHeader, wxString &aError)
Append rules to an ignore file, creating it with aHeader as a comment when it is not there.
APIEXPORT wxFileName ProjectIgnoreFile(const wxString &aProjectPath)
The ignore file that covers a project.
APIEXPORT bool RemoveIgnoreRules(const wxFileName &aIgnoreFile, const std::vector< wxString > &aRules, wxString &aError)
Remove rules from an ignore file.
APIEXPORT wxString ExtensionIgnoreRule(const wxString &aProjectRelPath)
The rule that ignores every file sharing a path's extension, or nothing when it has none.
std::unique_lock< std::mutex > TryLockAction(KIGIT_COMMON &aCommon, wxWindow *aParent)
Try the action lock and show a busy message if it is unavailable.
APIEXPORT IGNORE_STATE IgnoreState(KIGIT_COMMON &aCommon, const wxString &aProjectRelPath, bool aIsDirectory)
What git's rules and its index say about a project path, so the user is offered only what would take ...
std::vector< TEXT_DIFF_LINE > BuildTextDiff(const std::vector< wxString > &aOld, const std::vector< wxString > &aNew)
Every line of both sides appears once. There are no hunks and nothing is elided.
APIEXPORT wxString PathIgnoreRule(const wxString &aProjectRelPath, bool aIsDirectory)
The rule that ignores one path and nothing else.
@ CANCELLED
Stop and say so, the user cancelled the transfer or a prompt.
PGM_BASE & Pgm()
The global program "get" accessor.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
The files making up one open document, each with its on-disk identity.
std::map< wxString, FILE_STAMP > files
What the open editors and the project settings looked like on disk before an operation that may rewri...
std::map< FRAME_T, DOCUMENT_SNAPSHOT > editors
DOCUMENT_SNAPSHOT settings
One file row in a FILE_CHECKLIST_CTRL.
wxString path
Row identity, and what the row shows.
wxColour statusColour
Text colour for the status, or the default when not set.
wxString status
Free text, e.g. "Modified".
On-disk identity of one file, used to tell whether a git operation rewrote it.
long long modified
Modification time, nanoseconds where the platform provides them.
The two sides of one file, written out for a comparison.
KICAD_DIFF::DOC_KIND kind
wxString before
Empty when the file did not exist on that side.
wxString error
Why the sides could not be written, when they could not.
One path an ignore change applies to, relative to the project folder with forward slashes.
Repository state used before an operation that requires a clean working tree.
std::vector< wxString > outsideProject
wxString RefusalMessage(const std::vector< wxString > &aUnsavedEditors, bool aAllowTrackedChanges=false) const
Empty when rewriting is allowed.
Diff colors with defaults for light backgrounds.
static DIFF_COLOR_THEME ForText(bool aDarkTheme)
Resolve change colors for UI text. Pass the desktop theme captured on the UI thread.
A summary the user can act on, with the raw text that explains it kept apart for the details.
IbisParser parser & reporter
wxString result
Test unit parsing edge cases and error handling.
Definition of file extensions used in Kicad.