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 (C) 2023 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
35{
36 if( m_repo )
37 git_repository_free( m_repo );
38}
39
40
42{
43 wxFileName clonePath( m_clonePath );
44
45 if( !clonePath.DirExists() )
46 {
47 if( !clonePath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
48 {
49 AddErrorString( wxString::Format( _( "Could not create directory '%s'" ), m_clonePath ) );
50 return false;
51 }
52 }
53
54 git_clone_options cloneOptions;
55 git_clone_init_options( &cloneOptions, GIT_CLONE_OPTIONS_VERSION );
56 cloneOptions.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
57 cloneOptions.checkout_opts.progress_cb = clone_progress_cb;
58 cloneOptions.checkout_opts.progress_payload = this;
59 cloneOptions.fetch_opts.callbacks.transfer_progress = transfer_progress_cb;
60 cloneOptions.fetch_opts.callbacks.credentials = credentials_cb;
61 cloneOptions.fetch_opts.callbacks.payload = this;
62
63 m_testedTypes = 0;
64
65 if( git_clone( &m_repo, m_URL.ToStdString().c_str(), m_clonePath.ToStdString().c_str(), &cloneOptions ) != 0 )
66 {
67 AddErrorString( wxString::Format( _( "Could not clone repository '%s'" ), m_URL ) );
68 return false;
69 }
70
72 m_progressReporter->Hide();
73
75
76 return true;
77}
78
79
80void GIT_CLONE_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage )
81{
82 ReportProgress( aCurrent, aTotal, aMessage );
83}
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)