KiCad PCB EDA Suite
Loading...
Searching...
No Matches
git_clone_handler.cpp
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#include "git_clone_handler.h"
25
27
28#include <git2.h>
29#include <wx/filename.h>
30
32{}
33
34
36{
37 if( m_repo )
38 git_repository_free( m_repo );
39}
40
41
43{
44 wxFileName clonePath( m_clonePath );
45
46 if( !clonePath.DirExists() )
47 {
48 if( !clonePath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
49 {
50 AddErrorString( wxString::Format( _( "Could not create directory '%s'" ),
51 m_clonePath ) );
52 return false;
53 }
54 }
55
56 git_clone_options cloneOptions;
57 git_clone_init_options( &cloneOptions, GIT_CLONE_OPTIONS_VERSION );
58 cloneOptions.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
59 cloneOptions.checkout_opts.progress_cb = clone_progress_cb;
60 cloneOptions.checkout_opts.progress_payload = this;
61 cloneOptions.fetch_opts.callbacks.transfer_progress = transfer_progress_cb;
62 cloneOptions.fetch_opts.callbacks.credentials = credentials_cb;
63 cloneOptions.fetch_opts.callbacks.payload = this;
64
65 m_testedTypes = 0;
67
68 if( git_clone( &m_repo, m_URL.ToStdString().c_str(), m_clonePath.ToStdString().c_str(),
69 &cloneOptions ) != 0 )
70 {
71 AddErrorString( wxString::Format( _( "Could not clone repository '%s'" ), m_URL ) );
72 return false;
73 }
74
76 m_progressReporter->Hide();
77
79
80 return true;
81}
82
83
84void GIT_CLONE_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage )
85{
86 ReportProgress( aCurrent, aTotal, aMessage );
87}
void UpdateProgress(int aCurrent, int aTotal, const wxString &aMessage) override
void ReportProgress(int aCurrent, int aTotal, const wxString &aMessage)
Definition: git_progress.h:45
int m_previousProgress
Definition: git_progress.h:67
std::unique_ptr< WX_PROGRESS_REPORTER > m_progressReporter
Definition: git_progress.h:69
git_repository * m_repo
unsigned m_testedTypes
void AddErrorString(const wxString aErrorString)
#define _(s)
void clone_progress_cb(const char *aStr, size_t aLen, size_t aTotal, void *data)
int transfer_progress_cb(const git_transfer_progress *aStats, void *aPayload)
int credentials_cb(git_cred **aOut, const char *aUrl, const char *aUsername, unsigned int aAllowedTypes, void *aPayload)