38#include <wx/filename.h>
41#include <wx/stdpaths.h>
47 const std::vector<wxString>& aRefList ) :
50 m_repo( aCommon ? aCommon->GetRepo() : nullptr )
52 m_listFiles->AppendColumn(
_(
"Path" ), wxLIST_FORMAT_LEFT, 400 );
53 m_listFiles->AppendColumn(
_(
"Status" ), wxLIST_FORMAT_LEFT, 100 );
54 m_listFiles->AppendColumn(
_(
"Old Path" ), wxLIST_FORMAT_LEFT, 200 );
56 for(
const wxString& ref : aRefList )
62 if( !aRefList.empty() )
64 m_comboBase->SetSelection( 0 );
65 m_comboHead->SetSelection( aRefList.size() > 1 ? 1 : 0 );
75 EndModal( wxID_CANCEL );
98 wxMessageBox(
_(
"No git repository available." ),
_(
"Compare Branches" ),
99 wxOK | wxICON_ERROR,
this );
106 if( base.IsEmpty() || head.IsEmpty() )
108 wxMessageBox(
_(
"Select base and head refs to compare." ),
109 _(
"Compare Branches" ), wxOK | wxICON_INFORMATION,
this );
116 if( !lock.owns_lock() )
122 [
this](
const wxString& aRef ) ->
bool
129 wxString::Format(
_(
"Could not resolve ref '%s' to a commit or tree." ),
131 _(
"Compare Branches" ), wxOK | wxICON_ERROR,
this );
138 if( !validateRef( base ) || !validateRef( head ) )
147 m_listFiles->InsertItem( 0,
_(
"No changes between selected refs." ) );
155 long idx =
m_listFiles->InsertItem( row++, f.path );
159 if( !f.oldPath.IsEmpty() )
171bool isPrettyFootprintChange(
const wxString& aPath )
176 wxFileName fn( aPath );
177 const wxArrayString& dirs = fn.GetDirs();
179 return !dirs.IsEmpty() && dirs.Last().EndsWith( wxS(
".pretty" ) );
188 if( aListIndex < 0 || aListIndex >=
static_cast<long>(
m_changedFiles.size() ) )
194 bool prettyFootprint = isPrettyFootprintChange( file.
path );
196 if( prettyFootprint )
201 wxMessageBox( wxString::Format(
_(
"No diff handler for '%s'." ), file.
path ),
202 _(
"Compare File" ), wxOK | wxICON_INFORMATION,
this );
213 if( !workspace.
IsOk() )
215 wxMessageBox(
_(
"Could not create a temporary directory." ),
_(
"Compare File" ),
216 wxOK | wxICON_ERROR,
this );
223 if( !lock.owns_lock() )
233 if( prettyFootprint )
237 const wxString sep = wxFileName::GetPathSeparator();
238 const wxString fpFile = wxFileName( file.
path ).GetFullName();
240 wxString dirA = workspace.
Root() + sep + wxS(
"base.pretty" );
241 wxString dirB = workspace.
Root() + sep + wxS(
"head.pretty" );
243 if( hasBase && !wxFileName::Mkdir( dirA, 0700, wxPATH_MKDIR_FULL ) )
246 if( hasHead && !wxFileName::Mkdir( dirB, 0700, wxPATH_MKDIR_FULL ) )
253 wxMessageBox( wxString::Format(
_(
"Could not extract %s from %s." ), basePath, base ),
254 _(
"Compare File" ), wxOK | wxICON_ERROR,
this );
265 wxMessageBox( wxString::Format(
_(
"Could not extract %s from %s." ), file.
path, head ),
266 _(
"Compare File" ), wxOK | wxICON_ERROR,
this );
279 if( pathA.IsEmpty() )
281 wxMessageBox( wxString::Format(
_(
"Could not extract %s from %s." ), basePath, base ),
282 _(
"Compare File" ), wxOK | wxICON_ERROR,
this );
291 if( pathB.IsEmpty() )
293 wxMessageBox( wxString::Format(
_(
"Could not extract %s from %s." ), file.
path, head ),
294 _(
"Compare File" ), wxOK | wxICON_ERROR,
this );
304 const wxString labelA = wxString::Format( wxS(
"%s:%s" ), base, basePath );
305 const wxString labelB = wxString::Format( wxS(
"%s:%s" ), head, file.
path );
312 wxMessageBox(
reporter.GetMessages(),
_(
"Compare File" ),
313 wxOK | wxICON_INFORMATION,
this );
DIALOG_GIT_MR_REVIEW_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Compare Branches"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(800, 550), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void OnFileActivated(wxListEvent &aEvent) override
void OnCompareClick(wxCommandEvent &aEvent) override
DIALOG_GIT_MR_REVIEW(wxWindow *aParent, KIGIT_COMMON *aCommon, const std::vector< wxString > &aRefList)
std::vector< KIGIT::CHANGED_FILE > m_changedFiles
void openFileDiff(long aListIndex)
void OnClose(wxCloseEvent &aEvent) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
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...
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.
The project's git session.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wrapper for reporting to a wxString object.
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...
std::unique_ptr< git_tree, decltype([](git_tree *aTree) { git_tree_free(aTree); })> GitTreePtr
A unique pointer for git_tree objects with automatic cleanup.
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...
git_tree * ResolveRefToTree(git_repository *aRepo, const wxString &aRef)
Resolve a string ref (branch name, short OID, full OID, tag) to its tree.
const char * FileChangeStatusToString(FILE_CHANGE_STATUS aStatus)
std::unique_lock< std::mutex > TryLockAction(KIGIT_COMMON &aCommon, wxWindow *aParent)
Try the action lock and show a busy message if it is unavailable.
FILE_CHANGE_STATUS status
IbisParser parser & reporter