KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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
28#include <trace_helpers.h>
29
30#include <git2.h>
31#include <wx/filename.h>
32#include <wx/log.h>
33
35{}
36
37
39{}
40
41
43{
44 std::unique_lock<std::mutex> lock( GetCommon()->m_gitActionMutex, std::try_to_lock );
45
46 if( !lock.owns_lock() )
47 {
48 wxLogTrace( traceGit, "GIT_CLONE_HANDLER::PerformClone() could not lock" );
49 return false;
50 }
51
52 wxFileName clonePath( m_clonePath );
53
54 if( !clonePath.DirExists() )
55 {
56 if( !clonePath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
57 {
58 AddErrorString( wxString::Format( _( "Could not create directory '%s'" ),
59 m_clonePath ) );
60 return false;
61 }
62 }
63
64 git_clone_options cloneOptions;
65 git_clone_init_options( &cloneOptions, GIT_CLONE_OPTIONS_VERSION );
66 cloneOptions.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
67 cloneOptions.checkout_opts.progress_cb = clone_progress_cb;
68 cloneOptions.checkout_opts.progress_payload = this;
69 cloneOptions.fetch_opts.callbacks.transfer_progress = transfer_progress_cb;
70 cloneOptions.fetch_opts.callbacks.credentials = credentials_cb;
71 cloneOptions.fetch_opts.callbacks.payload = this;
72
73 TestedTypes() = 0;
75 git_repository* newRepo = nullptr;
76 wxString remote = GetCommon()->m_remote;
77
78 if( git_clone( &newRepo, remote.mbc_str(), m_clonePath.mbc_str(),
79 &cloneOptions ) != 0 )
80 {
81 AddErrorString( wxString::Format( _( "Could not clone repository '%s'" ), remote ) );
82 return false;
83 }
84
85 GetCommon()->SetRepo( newRepo );
86
88 m_progressReporter->Hide();
89
91
92 return true;
93}
94
95
96void GIT_CLONE_HANDLER::UpdateProgress( int aCurrent, int aTotal, const wxString& aMessage )
97{
98 ReportProgress( aCurrent, aTotal, aMessage );
99}
GIT_CLONE_HANDLER(KIGIT_COMMON *aCommon)
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:69
std::unique_ptr< WX_PROGRESS_REPORTER > m_progressReporter
Definition: git_progress.h:71
void SetRepo(git_repository *aRepo)
void AddErrorString(const wxString aErrorString)
unsigned & TestedTypes()
Return the connection types that have been tested for authentication.
KIGIT_COMMON * GetCommon() const
Get the common object.
void ResetNextKey()
Reset the next public key to test.
#define _(s)
const wxChar *const traceGit
Flag to enable Git debugging output.
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)
void clone_progress_cb(const char *aStr, size_t aLen, size_t aTotal, void *aPayload)
wxLogTrace helper definitions.